傅行帆 5 gadus atpakaļ
vecāks
revīzija
e7d79c50da

+ 36
- 5
SmartCommunity/mybatisGeneratorCode/src/main/resources/templatesPlus/controller.java.ftl Parādīt failu

1
 package ${package.Controller};
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
 import com.community.huiju.common.model.ResponseBean;
6
 import com.community.huiju.common.model.ResponseBean;
4
 import org.slf4j.Logger;
7
 import org.slf4j.Logger;
5
 import org.slf4j.LoggerFactory;
8
 import org.slf4j.LoggerFactory;
8
 import org.springframework.web.bind.annotation.RequestBody;
11
 import org.springframework.web.bind.annotation.RequestBody;
9
 import org.springframework.web.bind.annotation.RequestMapping;
12
 import org.springframework.web.bind.annotation.RequestMapping;
10
 import org.springframework.web.bind.annotation.RequestMethod;
13
 import org.springframework.web.bind.annotation.RequestMethod;
14
+import org.springframework.web.bind.annotation.RequestParam;
11
 import org.springframework.web.bind.annotation.ResponseBody;
15
 import org.springframework.web.bind.annotation.ResponseBody;
12
 import ${package.Service}.${table.serviceName};
16
 import ${package.Service}.${table.serviceName};
13
 import ${package.Entity}.${table.entityName};
17
 import ${package.Entity}.${table.entityName};
49
     public ${table.serviceName} i${entity}Service;
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
      * @param ${table.entityPath} 实体对象
83
      * @param ${table.entityPath} 实体对象
55
      * @return
84
      * @return
56
      */
85
      */
57
-    @RequestMapping(value="/${table.entityPath}/add",method= RequestMethod.POST)
86
+    @RequestMapping(value="/${table.entityPath}",method= RequestMethod.POST)
58
     public ResponseBean tpShopImgAdd(@RequestBody ${entity} ${table.entityPath}){
87
     public ResponseBean tpShopImgAdd(@RequestBody ${entity} ${table.entityPath}){
59
         ResponseBean responseBean = new ResponseBean();
88
         ResponseBean responseBean = new ResponseBean();
60
         try {
89
         try {
75
      * @param id  实体ID
104
      * @param id  实体ID
76
      */
105
      */
77
     @ResponseBody
106
     @ResponseBody
78
-    @RequestMapping(value="/${table.entityPath}/delete/{id}", method= RequestMethod.DELETE)
107
+    @RequestMapping(value="/${table.entityPath}/{id}", method= RequestMethod.DELETE)
79
     public ResponseBean ${table.entityPath}Delete(@PathVariable Integer id){
108
     public ResponseBean ${table.entityPath}Delete(@PathVariable Integer id){
80
         ResponseBean responseBean = new ResponseBean();
109
         ResponseBean responseBean = new ResponseBean();
81
         try {
110
         try {
93
 
122
 
94
     /**
123
     /**
95
      * 修改对象
124
      * 修改对象
125
+     * @param id  实体ID
96
      * @param ${table.entityPath} 实体对象
126
      * @param ${table.entityPath} 实体对象
97
      * @return
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
         ResponseBean responseBean = new ResponseBean();
132
         ResponseBean responseBean = new ResponseBean();
102
         try {
133
         try {
103
             if (i${entity}Service.updateById(${table.entityPath})){
134
             if (i${entity}Service.updateById(${table.entityPath})){
116
      * 根据id查询对象
147
      * 根据id查询对象
117
      * @param id  实体ID
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
     public ResponseBean tpShopImgGet(@PathVariable Integer id){
151
     public ResponseBean tpShopImgGet(@PathVariable Integer id){
121
         ResponseBean responseBean = new ResponseBean();
152
         ResponseBean responseBean = new ResponseBean();
122
         try {
153
         try {