文件信息类:
package com.example.file_monitor; import lombok.Data; import lombok.NoArgsConstructor; /* 文件信息实体对象 */ @Data @NoArgsConstructor public class FileInfo { private int id; private String action; private String name; private String time; public FileInfo(int id,String action,String name,String time){ this.id=id; this.action=action; this.name=name; this.time=time; } }数据库操作接口:
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.List; /* 数据库操作接口 */ @Mapper public interface FileMapper { //获取文件监控信息列表 @Select("SELECT * FROM file_info") List<FileInfo> findAllFile(); //分页获取 @Select("SELECT * FROM file_info LIMIT #{start},#{end}") List<FileInfo> findFile(@Param("start") int start,@Param("end") int end); //删除 @Delete("DELETE FROM file_info WHERE id= #{id}") int deleteFile(@Param("id") int id); //统计各种操作 @Select("SELECT COUNT(*) FROM file_info WHERE action= #{a}") int getCount(@Param("a") String action); }控制类
package com.example.file_monitor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; @RestController @RequestMapping(value = "api") public class FileController { @Autowired private FileMapper fileMapper; @Autowired private ApiJson apiJson; //分页 @GetMapping("/data") public ApiJson getFileList(@RequestParam("curr") int page,@RequestParam("nums") int limit){ int start=(page-1)*limit; int end= limit; List<FileInfo> data=fileMapper.findFile(start,end); apiJson.setCode(0); apiJson.setCount(100); apiJson.setMsg("test"); apiJson.setData(data); return apiJson; } //统计 @GetMapping("/count") public List<Integer> getCount(){ int mod=fileMapper.getCount("File Modified"); int add=fileMapper.getCount("File Added"); int dele=fileMapper.getCount("File Deleted"); int reName=fileMapper.getCount("File Renamed"); List<Integer> res=new ArrayList<Integer>(); res.add(mod); res.add(add); res.add(dele); res.add(reName); return res; } //删除 @CrossOrigin @GetMapping("/delete") public int delFile(@RequestParam("id") int id){ return fileMapper.deleteFile(id); } //获取所有信息 @CrossOrigin @GetMapping("/all") public List<FileInfo> getAllFileInfo(){ return fileMapper.findAllFile(); } }