@@ -10,29 +10,45 @@ $!define
1010##包路径(宏定义)
1111#setPackageSuffix("controller")
1212
13- import org.springframework.web.bind.annotation.*;
14- import javax.annotation.Resource;
15- import com.alibaba.fastjson.JSON;
13+ ##定义服务名
14+ #set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service"))
15+
16+ ##定义实体对象名
17+ #set($entityName = $!tool.firstLowerCase($!tableInfo.name))
18+
19+ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
20+ import com.baomidou.mybatisplus.extension.api.ApiController;
21+ import com.baomidou.mybatisplus.extension.api.ApiResult;
22+ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
1623import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;
1724import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
25+ import org.springframework.web.bind.annotation.*;
26+
27+ import javax.annotation.Resource;
28+ import java.io.Serializable;
1829import java.util.List;
1930
2031##表注释(宏定义)
2132#tableComment("表控制层")
2233@RestController
23- @RequestMapping("$!tool.firstLowerCase($!{tableName})")
24- public class $!{tableName} {
34+ @RequestMapping("$!tool.firstLowerCase($!tableInfo.name)")
35+ public class $!{tableName} extends ApiController {
36+ /**
37+ * 服务对象
38+ */
2539 @Resource
26- private $!{tableInfo.name}Service $!tool.firstLowerCase($!tableInfo.name)Service ;
40+ private $!{tableInfo.name}Service $!{serviceName} ;
2741
2842 /**
2943 * 分页查询所有数据
3044 *
45+ * @param page 分页对象
46+ * @param $!entityName 查询实体
3147 * @return 所有数据
3248 */
3349 @GetMapping
34- public String selectAll() {
35- return success(this.$!tool.firstLowerCase($!tableInfo.name)Service.selectAll( ));
50+ public ApiResult selectAll(Page<UserInfo> page, $!tableInfo.name $!entityName ) {
51+ return success(this.$!{serviceName}.page(page, new QueryWrapper<>($!entityName) ));
3652 }
3753
3854 /**
@@ -42,30 +58,30 @@ public class $!{tableName} {
4258 * @return 单条数据
4359 */
4460 @GetMapping("{id}")
45- public String selectOne(@PathVariable Long id) {
46- return success(this.$!tool.firstLowerCase($!tableInfo.name)Service.queryById (id));
61+ public ApiResult selectOne(@PathVariable Serializable id) {
62+ return success(this.$!{serviceName}.getById (id));
4763 }
4864
4965 /**
5066 * 新增数据
5167 *
52- * @param entity 实体对象
68+ * @param $!entityName 实体对象
5369 * @return 新增结果
5470 */
5571 @PostMapping
56- public String insert(@RequestBody $!tableInfo.name entity ) {
57- return success(this.$!tool.firstLowerCase ($!tableInfo.name)Service.insert(entity ));
72+ public ApiResult insert(@RequestBody $!tableInfo.name $!entityName ) {
73+ return success(this.$!{serviceName}.save ($!entityName ));
5874 }
5975
6076 /**
6177 * 修改数据
6278 *
63- * @param entity 实体对象
79+ * @param $!entityName 实体对象
6480 * @return 修改结果
6581 */
6682 @PutMapping
67- public String update(@RequestBody $!tableInfo.name entity ) {
68- return success(this.$!tool.firstLowerCase ($!tableInfo.name)Service.update(entity ));
83+ public ApiResult update(@RequestBody $!tableInfo.name $!entityName ) {
84+ return success(this.$!{serviceName}.updateById ($!entityName ));
6985 }
7086
7187 /**
@@ -75,17 +91,7 @@ public class $!{tableName} {
7591 * @return 删除结果
7692 */
7793 @DeleteMapping
78- public String delete(@RequestParam("idList") List<Long> idList) {
79- return success(this.$!tool.firstLowerCase($!tableInfo.name)Service.deleteByIdList(idList));
80- }
81-
82- /**
83- * 成功返回方法
84- *
85- * @param obj 对象
86- * @return JSON字符串
87- */
88- public String success(Object obj) {
89- return JSON.toJSONString(obj);
94+ public ApiResult delete(@RequestParam("idList") List<Long> idList) {
95+ return success(this.$!{serviceName}.removeByIds(idList));
9096 }
9197}
0 commit comments