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
| package ${controller.packageName};
import com.example.demo.common.CommonPage; import com.example.demo.common.CommonResult; import ${tableClass.fullClassName}; import ${serviceInterface.packageName}.${serviceInterface.fileName}; import com.github.pagehelper.PageHelper; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import java.util.List;
@RestController @RequestMapping("/${tableClass.shortClassName?uncap_first}") @Api(tags = "${controller.fileName}", value = "${tableClass.remark!}Controller") public class ${controller.fileName} {
@Resource private ${serviceInterface.fileName} ${serviceInterface.fileName?uncap_first};
@ApiOperation("新增${tableClass.remark!?substring(0, tableClass.remark?length-1)}") @PostMapping(value = "/insert", produces = "application/json;charset=UTF-8") public CommonResult save(@RequestBody @Validated ${tableClass.shortClassName} ${tableClass.shortClassName?uncap_first}) { int count = ${serviceInterface.fileName?uncap_first}.insert${tableClass.shortClassName}(${tableClass.shortClassName?uncap_first}); if (count > 0) { return CommonResult.success(count); } return CommonResult.failed(); }
@ApiOperation("修改${tableClass.remark!?substring(0, tableClass.remark?length-1)}") @PostMapping(value = "/update", produces = "application/json;charset=UTF-8") public CommonResult update(@RequestBody @Validated ${tableClass.shortClassName} ${tableClass.shortClassName?uncap_first}) { int count = ${serviceInterface.fileName?uncap_first}.update${tableClass.shortClassName}(${tableClass.shortClassName?uncap_first}); if (count > 0) { return CommonResult.success(count); } return CommonResult.failed(); }
@ApiOperation("分页获取${tableClass.remark!?substring(0, tableClass.remark?length-1)}") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", paramType = "query", dataType = "integer"), @ApiImplicitParam(name = "pageSize", value = "每页显示数量", defaultValue = "5", allowableValues = "0,5,10,15,20", paramType = "query", dataType = "integer"), @ApiImplicitParam(name = "orderBy", value = "排序字段", paramType = "query", dataType = "string")} ) @GetMapping(value = "/list", produces = "application/json;charset=UTF-8") public CommonResult<CommonPage<${tableClass.shortClassName}>> list(${tableClass.shortClassName} ${tableClass.shortClassName?uncap_first}, @RequestParam(required = false, defaultValue = "1") Integer pageNum, @RequestParam(required = false, defaultValue = "5") Integer pageSize, @RequestParam(required = false) String orderBy) { PageHelper.startPage(pageNum, pageSize, orderBy + " desc"); List<${tableClass.shortClassName}> list = ${serviceInterface.fileName?uncap_first}.list${tableClass.shortClassName}s(${tableClass.shortClassName?uncap_first}); return CommonResult.success(CommonPage.restPage(list)); }
@ApiOperation("根据id查询${tableClass.remark!?substring(0, tableClass.remark?length-1)}") @GetMapping(value = "/{id}", produces = "application/json;charset=UTF-8") public CommonResult<${tableClass.shortClassName}> detail(@PathVariable Long id) { ${tableClass.shortClassName} ${tableClass.shortClassName} = ${serviceInterface.fileName?uncap_first}.get${tableClass.shortClassName}ById(id); return CommonResult.success(${tableClass.shortClassName}); }
@ApiOperation("批量删除${tableClass.remark!?substring(0, tableClass.remark?length-1)}") @PostMapping(value = "/remove", produces = "application/json;charset=UTF-8") public CommonResult remove(@RequestParam("ids") List<Long> ids) { int count = ${serviceInterface.fileName?uncap_first}.delete${tableClass.shortClassName}ByIds(ids); if (count > 0) { return CommonResult.success(count); } return CommonResult.failed(); } }
|