傅行帆 5 年前
父节点
当前提交
e7d79c50da

+ 36
- 5
SmartCommunity/mybatisGeneratorCode/src/main/resources/templatesPlus/controller.java.ftl 查看文件

@@ -1,5 +1,8 @@
1 1
 package ${package.Controller};
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
3 6
 import com.community.huiju.common.model.ResponseBean;
4 7
 import org.slf4j.Logger;
5 8
 import org.slf4j.LoggerFactory;
@@ -8,6 +11,7 @@ import org.springframework.web.bind.annotation.PathVariable;
8 11
 import org.springframework.web.bind.annotation.RequestBody;
9 12
 import org.springframework.web.bind.annotation.RequestMapping;
10 13
 import org.springframework.web.bind.annotation.RequestMethod;
14
+import org.springframework.web.bind.annotation.RequestParam;
11 15
 import org.springframework.web.bind.annotation.ResponseBody;
12 16
 import ${package.Service}.${table.serviceName};
13 17
 import ${package.Entity}.${table.entityName};
@@ -49,12 +53,37 @@ public class ${table.controllerName} {
49 53
     public ${table.serviceName} i${entity}Service;
50 54
 
51 55
 
56
+    /**
57
+     * 分页查询列表
58
+     * @param pageNum
59
+     * @param pageSize
60
+     * @return
61
+     */
62
+    @RequestMapping(value="/${table.entityPath}",method= RequestMethod.GET)
63
+    public ResponseBean tpShopImgAdd(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
64
+									 @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){
65
+        ResponseBean responseBean = new ResponseBean();
66
+        try {
67
+            //使用分页插件
68
+		    IPage<${entity}> pg = new Page<>(pageNum, pageSize);
69
+            QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
70
+            queryWrapper.orderByDesc("create_date");
71
+
72
+            IPage<${entity}> result = i${entity}Service.page(pg, queryWrapper);
73
+            responseBean.addSuccess(result);
74
+        }catch (Exception e){
75
+            logger.error("${table.entityPath}List -=- {}",e.toString());
76
+            responseBean.addError(e.getMessage());
77
+        }
78
+        return responseBean;
79
+    }
80
+
52 81
     /**
53 82
      * 保存对象
54 83
      * @param ${table.entityPath} 实体对象
55 84
      * @return
56 85
      */
57
-    @RequestMapping(value="/${table.entityPath}/add",method= RequestMethod.POST)
86
+    @RequestMapping(value="/${table.entityPath}",method= RequestMethod.POST)
58 87
     public ResponseBean tpShopImgAdd(@RequestBody ${entity} ${table.entityPath}){
59 88
         ResponseBean responseBean = new ResponseBean();
60 89
         try {
@@ -75,7 +104,7 @@ public class ${table.controllerName} {
75 104
      * @param id  实体ID
76 105
      */
77 106
     @ResponseBody
78
-    @RequestMapping(value="/${table.entityPath}/delete/{id}", method= RequestMethod.DELETE)
107
+    @RequestMapping(value="/${table.entityPath}/{id}", method= RequestMethod.DELETE)
79 108
     public ResponseBean ${table.entityPath}Delete(@PathVariable Integer id){
80 109
         ResponseBean responseBean = new ResponseBean();
81 110
         try {
@@ -93,11 +122,13 @@ public class ${table.controllerName} {
93 122
 
94 123
     /**
95 124
      * 修改对象
125
+     * @param id  实体ID
96 126
      * @param ${table.entityPath} 实体对象
97 127
      * @return
98 128
      */
99
-    @RequestMapping(value="/${table.entityPath}/update",method= RequestMethod.PUT)
100
-    public ResponseBean tpShopImgUpdate(@RequestBody ${entity} ${table.entityPath}){
129
+    @RequestMapping(value="/${table.entityPath}/{id}",method= RequestMethod.PUT)
130
+    public ResponseBean tpShopImgUpdate(@PathVariable Integer id,
131
+                                        @RequestBody ${entity} ${table.entityPath}){
101 132
         ResponseBean responseBean = new ResponseBean();
102 133
         try {
103 134
             if (i${entity}Service.updateById(${table.entityPath})){
@@ -116,7 +147,7 @@ public class ${table.controllerName} {
116 147
      * 根据id查询对象
117 148
      * @param id  实体ID
118 149
      */
119
-    @RequestMapping(value="/${table.entityPath}/get/{id}",method= RequestMethod.GET)
150
+    @RequestMapping(value="/${table.entityPath}/{id}",method= RequestMethod.GET)
120 151
     public ResponseBean tpShopImgGet(@PathVariable Integer id){
121 152
         ResponseBean responseBean = new ResponseBean();
122 153
         try {