diff --git a/src/test/resources/demo-user.sql b/src/test/resources/demo-user.sql index 940113d..b29f561 100644 --- a/src/test/resources/demo-user.sql +++ b/src/test/resources/demo-user.sql @@ -33,4 +33,13 @@ CREATE TABLE `user` ( -- Records of user -- ---------------------------- INSERT INTO `user` VALUES ('1', '89921218@qq.com', '1ee04e0b1cb5af7367c80c22e42efd8b', '土豆', '1', '2017-06-23 14:24:23'); +INSERT INTO `user` VALUES ('1', '2@qq.com', '1ee04e0b1cb5af7367c80c22e42efd8b', '土豆-2', '1', '2017-06-23 14:24:23'); +INSERT INTO `user` VALUES ('1', '3@qq.com', '1ee04e0b1cb5af7367c80c22e42efd8b', '土豆-3', '1', '2017-06-23 14:24:23'); +INSERT INTO `user` VALUES ('1', '4@qq.com', '1ee04e0b1cb5af7367c80c22e42efd8b', '土豆-4', '1', '2017-06-23 14:24:23'); +INSERT INTO `user` VALUES ('1', '5@qq.com', '1ee04e0b1cb5af7367c80c22e42efd8b', '土豆-5', '1', '2017-06-23 14:24:23'); +INSERT INTO `user` VALUES ('1', '6@qq.com', '1ee04e0b1cb5af7367c80c22e42efd8b', '土豆-6', '1', '2017-06-23 14:24:23'); +INSERT INTO `user` VALUES ('1', '7@qq.com', '1ee04e0b1cb5af7367c80c22e42efd8b', '土豆-7', '1', '2017-06-23 14:24:23'); +INSERT INTO `user` VALUES ('1', '8@qq.com', '1ee04e0b1cb5af7367c80c22e42efd8b', '土豆-8', '1', '2017-06-23 14:24:23'); +INSERT INTO `user` VALUES ('1', '9@qq.com', '1ee04e0b1cb5af7367c80c22e42efd8b', '土豆-9', '1', '2017-06-23 14:24:23'); +INSERT INTO `user` VALUES ('1', '10@qq.com', '1ee04e0b1cb5af7367c80c22e42efd8b', '土豆-10', '1', '2017-06-23 14:24:23'); SET FOREIGN_KEY_CHECKS=1; diff --git a/src/test/resources/generator/template/controller-restful.ftl b/src/test/resources/generator/template/controller-restful.ftl new file mode 100644 index 0000000..7b12b7e --- /dev/null +++ b/src/test/resources/generator/template/controller-restful.ftl @@ -0,0 +1,53 @@ +package ${basePackage}.web; + +import ${basePackage}.core.Result; +import ${basePackage}.core.ResultGenerator; +import ${basePackage}.model.${modelNameUpperCamel}; +import ${basePackage}.service.${modelNameUpperCamel}Service; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** +* Created by ${author} on ${date}. +*/ +@RestController +@RequestMapping("${baseRequestMapping}") +public class ${modelNameUpperCamel}Controller { + @Resource + private ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service; + + @PostMapping + public Result add(${modelNameUpperCamel} ${modelNameLowerCamel}) { + ${modelNameLowerCamel}Service.save(${modelNameLowerCamel}); + return ResultGenerator.genSuccessResult(); + } + + @DeleteMapping("/{id}") + public Result delete(@PathVariable Integer id) { + userService.deleteById(id); + return ResultGenerator.genSuccessResult(); + } + + @PutMapping + public Result update(${modelNameUpperCamel} ${modelNameLowerCamel}) { + ${modelNameLowerCamel}Service.update(${modelNameLowerCamel}); + return ResultGenerator.genSuccessResult(); + } + @GetMapping("/{id}") + public Result detail(@PathVariable Integer id) { + ${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.findById(id); + return ResultGenerator.genSuccessResult(${modelNameLowerCamel}); + } + + @GetMapping + public Result list(Integer page, Integer size) { + PageHelper.startPage(page, size); + List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Service.findAll(); + PageInfo pageInfo = new PageInfo(list); + return ResultGenerator.genSuccessResult(pageInfo); + } +} diff --git a/src/test/resources/generator/template/controller.ftl b/src/test/resources/generator/template/controller.ftl index 55c29aa..530190d 100644 --- a/src/test/resources/generator/template/controller.ftl +++ b/src/test/resources/generator/template/controller.ftl @@ -35,9 +35,18 @@ public class ${modelNameUpperCamel}Controller { ${modelNameLowerCamel}Service.update(${modelNameLowerCamel}); return ResultGenerator.genSuccessResult(); } + @PostMapping("/detail") public Result detail(Integer id) { ${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.findById(id); return ResultGenerator.genSuccessResult(${modelNameLowerCamel}); } + + @PostMapping("/list") + public Result list(Integer page, Integer size) { + PageHelper.startPage(page, size); + List list = userService.findAll(); + PageInfo pageInfo = new PageInfo(list); + return ResultGenerator.genSuccessResult(pageInfo); + } }