本文最后更新于 2026年5月11日 晚上
获取文件列表接口的实现
获取文件列表接口的需求
根据关键字模糊查询文件
按创建时间升序排序
支持分页查询
代码实现
新建 FileListDto
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
@Data @AllArgsConstructor @NoArgsConstructor @ApiModel(description = "文件查询请求对象") public class FileListDto {
@ApiModelProperty(value = "类型", example = "图片") private String type;
@ApiModelProperty(value = "关键字(用于模糊搜索文件名称)", example = "Fluid") private String keywords; }
|
再创建 FileListVo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| @Data @AllArgsConstructor @NoArgsConstructor @ApiModel(description = "文件列表响应对象") public class FileListVo { @ApiModelProperty(value = "文件ID", example = "1") private Long id;
@ApiModelProperty(value = "文件名称", example = "bb278d771b9c47b9ab48843f554447ff_loading_1.gif") private String name;
@ApiModelProperty(value = "文件来源", example = "用户“里斯啊”的头像图片") private String fileSource;
@ApiModelProperty(value = "文件类型(图片,视频,文档等....)", example = "图片") private String type;
@ApiModelProperty(value = "文件存储路径", example = "文件oss中的存储路径") private String filePath;
@ApiModelProperty(value = "文件URL,图片预览URL", example = "域名 + 文件oss中的存储路径") private String url;
@ApiModelProperty(value = "文件大小(字节)", example = "363856") private Long size;
@ApiModelProperty(value = "MIME类型", example = "image/gif") private String mimeType;
@ApiModelProperty(value = "创建者ID", example = "1") private Long createBy;
@ApiModelProperty(value = "创建时间", example = "2026-05-08 14:40:22") private Date createTime;
@ApiModelProperty(value = "更新时间", example = "2026-05-08 14:40:50") private Date updateTime; }
|
在 SysFileServiceImpl 中实现方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| @Override public ResponseResult<PageVo> getFileList(Integer pageNum, Integer pageSize, FileListDto fileListDto) { LambdaQueryWrapper<SysFile> queryWrapper = new LambdaQueryWrapper<>();
if (StringUtils.hasText(fileListDto.getKeywords())){ queryWrapper.like(SysFile::getName, fileListDto.getKeywords()) .or() .like(SysFile::getFileSource, fileListDto.getKeywords()); }
queryWrapper.orderByDesc(SysFile::getCreateTime);
Page<SysFile> page = new Page<>(pageNum, pageSize); sysFileService.page(page, queryWrapper);
List<FileListVo> fileListVos = BeanCopyUtils.copyBeanList(page.getRecords(), FileListVo.class); PageVo pageVo = new PageVo(fileListVos, page.getTotal());
return ResponseResult.okResult(pageVo); }
|
PS:该系列只做为作者学习开发项目做的笔记用
不一定符合读者来学习,仅供参考
预告
后续会记录博客的开发过程
每次学习会做一份笔记来进行发表
“一花一世界,一叶一菩提”
版权所有 © 2026 云梦泽
欢迎访问我的个人网站:https://hgt12.github.io/