在learning-online-media-api
工程的com.swx.media.api
包下创建控制类
api.MediaFilesController
@Api(value = "媒资文件管理接口", tags = "媒资文件管理接口") @RestController @ResponseResult @RequestMapping("/files") public class MediaFilesController {
}
|
查询所有媒资
接口信息如下
查询DTO
QueryCourseParamsDTO@Data public class QueryMediaParamsDTO implements Serializable {
private static final long serialVersionUID = 1L;
private String filename; private String fileType; private String auditStatus;
}
|
定义Service
找到MediaFilesService
接口,定义课程查询接口
MediaFilesService
public interface MediaFilesService extends IService<MediaFiles> {
PageResult<MediaFiles> queryMediaFiles(Long companyId, PageParam pageParam, QueryMediaParamsDTO dto); }
|
实现该方法,找到其实现类MediaFilesServiceImpl
MediaFilesServiceImpl
@Slf4j @Service public class MediaFilesServiceImpl extends ServiceImpl<MediaFilesMapper, MediaFiles> implements MediaFilesService {
@Override public PageResult<MediaFiles> queryMediaFiles(Long companyId, PageParam pageParam, QueryMediaParamsDTO dto) { IPage<MediaFiles> page = new Page<>(pageParam.getPageNo(), pageParam.getPageSize()); LambdaQueryWrapper<MediaFiles> wrapper = Wrappers.<MediaFiles>lambdaQuery() .like(StringUtils.hasText(dto.getFilename()), MediaFiles::getFilename, dto.getFilename()) .eq(StringUtils.hasText(dto.getFileType()), MediaFiles::getFileType, dto.getFileType()); IPage<MediaFiles> pageResult = page(page, wrapper); return new PageResult<>(pageResult.getRecords(), pageResult.getTotal(), pageParam); } }
|
配置分页插件
在learning-online-media-service
工程下的com.swx.media.config
包下创建分页配置类,其内容如下:
MybatisPlusConfig@Configuration @MapperScan("com.swx.media.mapper") public class MybatisPlusConfig {
@Bean public MybatisPlusInterceptor mybatisPlusInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); return interceptor; } }
|
定义Controller
MediaFilesController
@Api(value = "媒资文件管理接口", tags = "媒资文件管理接口") @RestController @ResponseResult @RequestMapping("/files") public class MediaFilesController {
private final MediaFilesService mediaFilesService;
public MediaFilesController(MediaFilesService mediaFilesService) { this.mediaFilesService = mediaFilesService; }
@ApiOperation("媒资列表查询接口") @PostMapping public PageResult<MediaFiles> list(PageParam pageParam, @RequestBody QueryMediaParamsDTO dto) { Long companyId = 1232141425L; return mediaFilesService.queryMediaFiles(companyId, pageParam, dto); } }
|
媒资查询信息服务以提供,打开前端项目查看是否成功
Push到Git