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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| ##定义初始变量 #set($tableName = $tool.append($tableInfo.name, "Controller")) ##设置回调 $!callback.setFileName($tool.append($tableName, ".java")) $!callback.setSavePath($tool.append($tableInfo.savePath, "/controller")) ##拿到主键 #if(!$tableInfo.pkColumn.isEmpty()) #set($pk = $tableInfo.pkColumn.get(0)) #end
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name}; import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service; import org.springframework.web.bind.annotation.*; import io.swagger.annotations.*; import com.baomidou.mybatisplus.plugins.Page; import com.rambler.core.door.Response; import java.util.List;
import javax.annotation.Resource;
@Api(tags = "$!{tableInfo.comment}($!{tableInfo.name})控制层") @RestController @RequestMapping("/$!tool.firstLowerCase($tableInfo.name)") public class $!{tableName} {
@Resource private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
@ApiOperation(value = "通过主键查询单条数据") @ApiImplicitParam(name = "id", value = "实体id", required = true, paramType = "query") @RequestMapping(value = "selectOne", method = RequestMethod.GET) public Response<$tableInfo.name> selectOne($!pk.shortType $!pk.name) { if (id == null) { return Response.createErrorResponse("参数错误"); } $tableInfo.name result = $!{tool.firstLowerCase($tableInfo.name)}Service.selectById($!pk.name); if(result != null){ return Response.createSuccessResponse("查询成功", result); } return Response.createErrorResponse("查询失败"); } @ApiOperation(value = "发布新增实体类") @RequestMapping(value = "insert", method = RequestMethod.POST) public Response<$tableInfo.name> insert(@RequestBody @ApiParam(name = "文章对象", value = "json格式", required = true) $tableInfo.name $!tool.firstLowerCase($tableInfo.name)) { int result = $!{tool.firstLowerCase($tableInfo.name)}Service.insert($!tool.firstLowerCase($tableInfo.name)); if (result > 0) { return Response.createSuccessResponse("新增成功", $!tool.firstLowerCase($tableInfo.name)); } return Response.createErrorResponse("新增失败"); }
@ApiOperation(value = "更新实体") @RequestMapping(value = "update", method = RequestMethod.PUT) public Response<$tableInfo.name> update(@RequestBody @ApiParam(name = "文章对象", value = "json格式", required = true) $tableInfo.name $!tool.firstLowerCase($tableInfo.name)) { int result = $!{tool.firstLowerCase($tableInfo.name)}Service.update($!tool.firstLowerCase($tableInfo.name)); if (result != -1) { return Response.createSuccessResponse("修改成功", null); } return Response.createErrorResponse("修改失败"); }
@ApiOperation(value = "通过id删除") @ApiImplicitParam(name = "id", value = "实体id", required = true, paramType = "query") @RequestMapping(value = "delete", method = RequestMethod.DELETE) public Response<$tableInfo.name> delete($!pk.shortType $!pk.name) { if (id == null) { return Response.createErrorResponse("参数错误"); } int result = $!{tool.firstLowerCase($tableInfo.name)}Service.deleteById($!pk.name); if (result > 0) { return Response.createSuccessResponse("删除成功", null); } return Response.createErrorResponse("删除失败"); }
@ApiOperation(value = "查询所有", notes = "不需要参数") @RequestMapping(value = "selectAll", method = RequestMethod.GET) public Response<List<$tableInfo.name>> selectAll() { List<$tableInfo.name> $!tool.firstLowerCase($tableInfo.name)List = $!{tool.firstLowerCase($tableInfo.name)}Service.selectAll(); if ($!tool.firstLowerCase($tableInfo.name)List != null) { return Response.createSuccessResponse("查询成功", $!tool.firstLowerCase($tableInfo.name)List); } return Response.createErrorResponse("查询失败"); }
@ApiOperation(value = "分页查询") @ApiImplicitParams({ @ApiImplicitParam(name = "start", value = "开始位置,正整数", required = true, paramType = "query"), @ApiImplicitParam(name = "limit", value = "页面大小,正整数", required = true, paramType = "query") }) @RequestMapping(value = "selectPage", method = RequestMethod.GET) public Response<Page<$tableInfo.name>> selectPage(Integer start, Integer limit) { if(start < 0 || limit <= 0){ return Response.createErrorResponse("分页参数错误"); } List<$tableInfo.name> $!tool.firstLowerCase($tableInfo.name)List = $!{tool.firstLowerCase($tableInfo.name)}Service.selectPage(start, limit); Page<$tableInfo.name> page = new Page<>((start/limit)+1,limit); page.setRecords($!tool.firstLowerCase($tableInfo.name)List); page.setTotal($!{tool.firstLowerCase($tableInfo.name)}Service.count()); if ($!tool.firstLowerCase($tableInfo.name)List != null) { return Response.createSuccessResponse("查询成功", page); } return Response.createErrorResponse("查询失败"); } }
|