张延森 4 years ago
parent
commit
ae060f6ba6

+ 8
- 5
generator_service/src/main/java/com/example/demo/controller/DbController.java View File

@@ -20,9 +20,7 @@ import javax.servlet.http.HttpServletResponse;
20 20
 import java.io.*;
21 21
 import java.net.URLEncoder;
22 22
 import java.sql.*;
23
-import java.util.ArrayList;
24
-import java.util.List;
25
-import java.util.UUID;
23
+import java.util.*;
26 24
 
27 25
 @RestController
28 26
 @RequestMapping("/mydb")
@@ -129,7 +127,11 @@ public class DbController {
129 127
         InjectionConfig cfg = new InjectionConfig() {
130 128
             @Override
131 129
             public void initMap() {
132
-                // to do nothing
130
+                Map<String, Object> map = new HashMap<>();
131
+                map.put("BasePackage", dbConfig.getPackPath());
132
+                map.put("ResponseClassPackage", dbConfig.getPackPath() + ".common.ResponseBean");
133
+                map.put("ResponseClass", "ResponseBean");
134
+                this.setMap(map);
133 135
             }
134 136
         };
135 137
 
@@ -160,6 +162,7 @@ public class DbController {
160 162
         // templateConfig.setEntity();
161 163
         // templateConfig.setService();
162 164
         templateConfig.setController("templatesPlus/controller.java");
165
+        templateConfig.setMapper("templatesPlus/mapper.java");
163 166
 
164 167
         templateConfig.setXml(null);
165 168
         mpg.setTemplate(templateConfig);
@@ -171,7 +174,7 @@ public class DbController {
171 174
         //strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
172 175
         strategy.setEntityLombokModel(true);
173 176
         strategy.setRestControllerStyle(true);
174
-//        strategy.setSuperControllerClass(dbConfig.getPackPath() + ".common.BaseController");
177
+        strategy.setSuperControllerClass(dbConfig.getPackPath() + ".common.BaseController");
175 178
         //表名
176 179
         strategy.setInclude(tableName);
177 180
         strategy.setSuperEntityColumns("id");

+ 1
- 1
generator_service/src/main/resources/application.yml View File

@@ -1,2 +1,2 @@
1 1
 server:
2
-  port: 8087
2
+  port: 8080

+ 22
- 23
generator_service/src/main/resources/templatesPlus/controller.java.ftl View File

@@ -3,8 +3,11 @@ package ${package.Controller};
3 3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
-import ${package.Parent}.common.ResponseBean;
7
-import ${package.Parent}.common.BaseController;
6
+import ${superControllerClassPackage};
7
+import ${cfg.ResponseClassPackage};
8
+import io.swagger.annotations.Api;
9
+import io.swagger.annotations.ApiOperation;
10
+import io.swagger.annotations.ApiParam;
8 11
 import org.slf4j.Logger;
9 12
 import org.slf4j.LoggerFactory;
10 13
 import org.springframework.beans.factory.annotation.Autowired;
@@ -13,7 +16,6 @@ import org.springframework.web.bind.annotation.RequestBody;
13 16
 import org.springframework.web.bind.annotation.RequestMapping;
14 17
 import org.springframework.web.bind.annotation.RequestMethod;
15 18
 import org.springframework.web.bind.annotation.RequestParam;
16
-import org.springframework.web.bind.annotation.ResponseBody;
17 19
 import ${package.Service}.${table.serviceName};
18 20
 import ${package.Entity}.${table.entityName};
19 21
 <#if restControllerStyle>
@@ -21,9 +23,6 @@ import org.springframework.web.bind.annotation.RestController;
21 23
 <#else>
22 24
 import org.springframework.stereotype.Controller;
23 25
 </#if>
24
-<#if superControllerClassPackage??>
25
-import ${superControllerClassPackage};
26
-</#if>
27 26
 
28 27
 /**
29 28
  * <p>
@@ -63,8 +62,8 @@ public class ${table.controllerName} {
63 62
      * @return
64 63
      */
65 64
     @RequestMapping(value="/${table.entityPath}",method= RequestMethod.GET)
66
-    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
67
-    public ResponseBean ${table.entityPath}List(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
65
+    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ${cfg.ResponseClass}.class)
66
+    public ${cfg.ResponseClass} ${table.entityPath}List(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
68 67
 									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
69 68
 
70 69
 		    IPage<${entity}> pg = new Page<>(pageNum, pageSize);
@@ -81,13 +80,13 @@ public class ${table.controllerName} {
81 80
      * @return
82 81
      */
83 82
     @RequestMapping(value="/${table.entityPath}",method= RequestMethod.POST)
84
-    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
85
-    public ResponseBean ${table.entityPath}Add(@ApiParam("保存内容") @RequestBody ${entity} ${table.entityPath}) throws Exception{
83
+    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ${cfg.ResponseClass}.class)
84
+    public ${cfg.ResponseClass} ${table.entityPath}Add(@ApiParam("保存内容") @RequestBody ${entity} ${table.entityPath}) throws Exception{
86 85
 
87 86
         if (i${entity}Service.save(${table.entityPath})){
88
-            return ResponseBean.success(${table.entityPath});
87
+            return ${cfg.ResponseClass}.success(${table.entityPath});
89 88
         }else {
90
-            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
89
+            return ${cfg.ResponseClass}.error("保存失败, 请重试", ${cfg.ResponseClass}.ERROR_UNAVAILABLE);
91 90
         }
92 91
     }
93 92
 
@@ -96,12 +95,12 @@ public class ${table.controllerName} {
96 95
      * @param id  实体ID
97 96
      */
98 97
     @RequestMapping(value="/${table.entityPath}/{id}", method= RequestMethod.DELETE)
99
-    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
100
-    public ResponseBean ${table.entityPath}Delete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
98
+    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ${cfg.ResponseClass}.class)
99
+    public ${cfg.ResponseClass} ${table.entityPath}Delete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
101 100
         if(i${entity}Service.removeById(id)){
102
-            return ResponseBean.success("success");
101
+            return ${cfg.ResponseClass}.success("success");
103 102
         }else {
104
-            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
103
+            return ${cfg.ResponseClass}.error("删除失败, 请重试", ${cfg.ResponseClass}.ERROR_UNAVAILABLE);
105 104
         }
106 105
     }
107 106
 
@@ -112,14 +111,14 @@ public class ${table.controllerName} {
112 111
      * @return
113 112
      */
114 113
     @RequestMapping(value="/${table.entityPath}/{id}",method= RequestMethod.PUT)
115
-    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
116
-    public ResponseBean ${table.entityPath}Update(@ApiParam("对象ID") @PathVariable Integer id,
114
+    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ${cfg.ResponseClass}.class)
115
+    public ${cfg.ResponseClass} ${table.entityPath}Update(@ApiParam("对象ID") @PathVariable Integer id,
117 116
                                         @ApiParam("更新内容") @RequestBody ${entity} ${table.entityPath}) throws Exception{
118 117
 
119 118
         if (i${entity}Service.updateById(${table.entityPath})){
120
-            return ResponseBean.success(i${entity}Service.getById(id));
119
+            return ${cfg.ResponseClass}.success(i${entity}Service.getById(id));
121 120
         }else {
122
-            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
121
+            return ${cfg.ResponseClass}.error("修改失败, 请重试", ${cfg.ResponseClass}.ERROR_UNAVAILABLE);
123 122
         }
124 123
     }
125 124
 
@@ -128,9 +127,9 @@ public class ${table.controllerName} {
128 127
      * @param id  实体ID
129 128
      */
130 129
     @RequestMapping(value="/${table.entityPath}/{id}",method= RequestMethod.GET)
131
-    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
132
-    public ResponseBean ${table.entityPath}Get(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
133
-        return ResponseBean.success(i${entity}Service.getById(id));
130
+    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ${cfg.ResponseClass}.class)
131
+    public ${cfg.ResponseClass} ${table.entityPath}Get(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
132
+        return ${cfg.ResponseClass}.success(i${entity}Service.getById(id));
134 133
     }
135 134
 }
136 135
 </#if>

+ 22
- 0
generator_service/src/main/resources/templatesPlus/mapper.java.ftl View File

@@ -0,0 +1,22 @@
1
+package ${package.Mapper};
2
+
3
+import ${package.Entity}.${entity};
4
+import ${superMapperClassPackage};
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ * ${table.comment!} Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author ${author}
13
+ * @since ${date}
14
+ */
15
+<#if kotlin>
16
+interface ${table.mapperName} : ${superMapperClass}<${entity}>
17
+<#else>
18
+@Mapper
19
+public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
20
+
21
+}
22
+</#if>