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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| package com.example.demo.controller;
import java.util.Date;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController;
import com.example.demo.entity.DataFile; import com.example.demo.vo.ResultObject;
import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import io.swagger.v3.oas.annotations.parameters.RequestBody;
@RestController @RequestMapping("dataFile") @Api(tags = "文件管理") public class DataFileController {
@GetMapping("sayHello") @ApiOperation(value = "测试接口", notes = "测试连通性") public ResultObject sayHello() { ResultObject resultObject = new ResultObject("0", "hello, swagger!"); return resultObject; } @RequestMapping("testRequestType") public String testRequestType(String requestType) { return requestType + ", success!"; } @ApiOperation(value = "添加文件", notes = "新增文件") @PostMapping("addFile") public ResultObject addFile(DataFile dataFile) { System.out.println("添加文件:" + dataFile); ResultObject resultObject = new ResultObject("200", "添加文件成功!"); return resultObject; } @ApiOperation(value = "编辑文件", notes = "修改文件") @RequestMapping(value = "updateFile", method = RequestMethod.POST) public ResultObject updateFile(@RequestBody DataFile dataFile) { System.out.println("编辑文件:" + dataFile); ResultObject resultObject = new ResultObject("200", "编辑文件成功!"); return resultObject; } @ApiOperation(value = "删除文件", notes = "清除文件") @ApiImplicitParams(value = {@ApiImplicitParam(name = "fileId", value = "文件Id", required = true, paramType = "query", dataType = "String")}) @RequestMapping(value = "deleteFile", method = RequestMethod.DELETE) public ResultObject deleteFile(@RequestParam("fileId") String id) { System.out.println("删除文件,fileId = " + id); ResultObject resultObject = new ResultObject("200", "删除文件成功!"); return resultObject; } @ApiOperation(value = "查询文件", notes = "搜索文件") @ApiImplicitParams(value = {@ApiImplicitParam(name = "fileName", value = "文件名", required = true, paramType = "query", dataType = "String")}) @RequestMapping(value = "queryFile", method = RequestMethod.POST) public ResultObject queryFile(@RequestParam("fileName") String fileName) { System.out.println("查询文件,fileName = :" + fileName); DataFile dataFile = new DataFile(1, fileName, "txt", 100, "file/", "/home/admin/file/", new Date()); ResultObject resultObject = new ResultObject("200", "查询文件成功!", dataFile); return resultObject; } }
|