diff --git a/API.md b/API.md new file mode 100644 index 0000000..a86047d --- /dev/null +++ b/API.md @@ -0,0 +1,38 @@ +# API + +###查询文件 + +``` +GET /home/file/findbyname +``` + +参数 + +``` +fileName: 文件 +``` + +返回 + +``` +{ + "code": 0, + "msg": "成功", + "data": [ + { + "createTime": "2018-06-23 11:46:18", + "fileName": "测试Service虚拟文件3", + "fileSize": "31kb", + "filePath": "/www/Service", + "deleteFlag": 0 + }, + { + "createTime": "2018-06-23 11:43:59", + "fileName": "测试Service虚拟文件", + "fileSize": "31kb", + "filePath": "/www/Service", + "deleteFlag": 0 + } + ] +} +``` \ No newline at end of file diff --git a/src/main/java/top/fjy8018/fileupload/VO/FileInfoVO.java b/src/main/java/top/fjy8018/fileupload/VO/FileInfoVO.java new file mode 100644 index 0000000..7534499 --- /dev/null +++ b/src/main/java/top/fjy8018/fileupload/VO/FileInfoVO.java @@ -0,0 +1,23 @@ +package top.fjy8018.fileupload.VO; + +import lombok.Data; + +/** + * 返回的文件查询对象 + * @author F嘉阳 + * @date 2018-06-23 20:59 + */ +@Data +public class FileInfoVO { + + private String createTime; + + private String fileName; + + private String fileSize; + + private String filePath; + + private Integer deleteFlag; + +} diff --git a/src/main/java/top/fjy8018/fileupload/controller/FileSearchController.java b/src/main/java/top/fjy8018/fileupload/controller/FileSearchController.java new file mode 100644 index 0000000..75f6dca --- /dev/null +++ b/src/main/java/top/fjy8018/fileupload/controller/FileSearchController.java @@ -0,0 +1,48 @@ +package top.fjy8018.fileupload.controller; + +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import top.fjy8018.fileupload.VO.FileInfoVO; +import top.fjy8018.fileupload.dataobject.es.EsFileInfo; +import top.fjy8018.fileupload.service.FileService; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author F嘉阳 + * @date 2018-06-23 20:50 + */ +@RequestMapping("/home/file") +@RestController +public class FileSearchController { + + @Autowired + private FileService fileService; + + @GetMapping("/findbyname") + public List searchByFileName(@RequestParam String fileName, + @RequestParam(name = "pageNum", required = false, defaultValue = "1") Integer page, + @RequestParam(name = "size", required = false, defaultValue = "5") Integer size){ + + PageRequest pageRequest = PageRequest.of(page - 1, size); + Page productInfoPage = fileService.findByFileName(pageRequest,fileName); + List fileInfoList = productInfoPage.getContent(); + + List fileInfoVOList = new ArrayList<>(); + for (EsFileInfo fileInfo: fileInfoList){ + FileInfoVO fileInfoVO = new FileInfoVO(); + BeanUtils.copyProperties(fileInfo,fileInfoVO); + + fileInfoVOList.add(fileInfoVO); + } + + return fileInfoVOList; + } +} diff --git a/src/main/java/top/fjy8018/fileupload/interceptor/WebAppConfig.java b/src/main/java/top/fjy8018/fileupload/interceptor/WebAppConfig.java index d8fc3ee..e6d10c5 100644 --- a/src/main/java/top/fjy8018/fileupload/interceptor/WebAppConfig.java +++ b/src/main/java/top/fjy8018/fileupload/interceptor/WebAppConfig.java @@ -5,7 +5,7 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -@Configuration +/*@Configuration*/ public class WebAppConfig implements WebMvcConfigurer { /**