Commit 5407045e42f90ede130bc703d4ff74900b9d2606
1 parent
3f8cd5f4
Exists in
master
remote generate manager controller
Showing
3 changed files
with
2 additions
and
173 deletions
Show diff stats
build.gradle
src/main/java/com/taover/codegenerate/bazhuayun/GenerateCode.java
... | ... | @@ -67,7 +67,6 @@ public class GenerateCode { |
67 | 67 | ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); |
68 | 68 | //generateDto(srcPath, apiModel); |
69 | 69 | generateEntity(srcPath, apiModel, isCover); |
70 | - generateManageController(srcPath, apiModel, isCover); | |
71 | 70 | generateV1Controller(srcPath, apiModel, isCover); |
72 | 71 | generateRepository(srcPath, apiModel, isCover); |
73 | 72 | generateService(srcPath, apiModel, isCover); |
... | ... | @@ -101,7 +100,6 @@ public class GenerateCode { |
101 | 100 | boolean isCover = true; |
102 | 101 | //generateDto(srcPath, apiModel); |
103 | 102 | generateEntity(srcPath, apiModel, isCover); |
104 | - generateManageController(srcPath, apiModel, isCover); | |
105 | 103 | generateV1Controller(srcPath, apiModel, isCover); |
106 | 104 | generateRepository(srcPath, apiModel, isCover); |
107 | 105 | generateService(srcPath, apiModel, isCover); |
... | ... | @@ -163,34 +161,7 @@ public class GenerateCode { |
163 | 161 | } |
164 | 162 | System.out.println("处理完成"); |
165 | 163 | } |
166 | - | |
167 | - public static void generateControllerManage(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName, boolean isCover) throws Exception{ | |
168 | - //取数据库连接 | |
169 | - Connection conn = getConnection(host, port, user, password, dbName); | |
170 | - //初始化要生成的表列表 | |
171 | - List<String> tableNameList = getListTableName(tableNameStr, dbName, conn); | |
172 | - for (int i = 0; i < tableNameList.size(); i++) { | |
173 | - | |
174 | - String tableNameCurr = (String) tableNameList.get(i); | |
175 | - | |
176 | - //取得表中所有列 | |
177 | - Vector<MysqlTableColumn> columnsInTable = MysqlTableColumn.GetTableInfo(conn, dbName, tableNameCurr, "%", "mysql"); | |
178 | - if (columnsInTable == null || columnsInTable.size() == 0) { | |
179 | - System.out.println(tableNameCurr + " : 生成失败,得不到表中列明"); | |
180 | - continue; | |
181 | - } | |
182 | - MysqlTableColumn pkcolum = MysqlTableColumn.getPKColum(columnsInTable); | |
183 | - if (pkcolum == null) { | |
184 | - System.out.println(tableNameCurr + " : 生成失败,未设置主键"); | |
185 | - continue; | |
186 | - } | |
187 | - | |
188 | - ApiModel apiModel = new ApiModel(dbName, tableNameCurr, columnsInTable, "1.0.0", basePackage); | |
189 | - generateManageController(srcPath, apiModel, isCover); | |
190 | - } | |
191 | - System.out.println("处理完成"); | |
192 | - } | |
193 | - | |
164 | + | |
194 | 165 | public static void generateControllerV1(String basePackage, String tableNameStr, String srcPath, String host, String port, String user, String password, String dbName, boolean isCover) throws Exception{ |
195 | 166 | //取数据库连接 |
196 | 167 | Connection conn = getConnection(host, port, user, password, dbName); |
... | ... | @@ -347,12 +318,6 @@ public class GenerateCode { |
347 | 318 | Tools.createFile(filePath, apiModel.getEntityClassSimpleName()+".java", renderByTemplate("EntityTemplate.ftl", apiModel), isCover); |
348 | 319 | } |
349 | 320 | |
350 | - private static void generateManageController(String srcPath, ApiModel apiModel, boolean isCover) throws Exception{ | |
351 | - String modelPath = apiModel.getBasePackage().replace(".", File.separator); | |
352 | - String filePath = srcPath+File.separator+modelPath+File.separator+"controller"+File.separator+"manage"; | |
353 | - Tools.createFile(filePath, apiModel.getControllerClassName()+".java", renderByTemplate("ManageControllerTemplate.ftl", apiModel), isCover); | |
354 | - } | |
355 | - | |
356 | 321 | private static void generateV1Controller(String srcPath, ApiModel apiModel, boolean isCover) throws Exception{ |
357 | 322 | String modelPath = apiModel.getBasePackage().replace(".", File.separator); |
358 | 323 | String filePath = srcPath+File.separator+modelPath+File.separator+"controller"+File.separator+"v1"; | ... | ... |
src/main/resources/template/bazhuayun/ManageControllerTemplate.ftl
... | ... | @@ -1,136 +0,0 @@ |
1 | -package ${basePackage}.controller.manage; | |
2 | - | |
3 | -import java.util.List; | |
4 | - | |
5 | -import javax.annotation.Resource; | |
6 | -import javax.servlet.http.HttpServletRequest; | |
7 | - | |
8 | -import org.apache.commons.lang.StringUtils; | |
9 | -import org.springframework.web.bind.annotation.DeleteMapping; | |
10 | -import org.springframework.web.bind.annotation.GetMapping; | |
11 | -import org.springframework.web.bind.annotation.PostMapping; | |
12 | -import org.springframework.web.bind.annotation.PutMapping; | |
13 | -import org.springframework.web.bind.annotation.RequestMapping; | |
14 | -import org.springframework.web.bind.annotation.RestController; | |
15 | -import org.springframework.web.bind.annotation.PathVariable; | |
16 | - | |
17 | -import ${basePackage}.bean.entity.${entityClassSimpleName}; | |
18 | -import ${basePackage}.constants.GlobalConstants; | |
19 | -import ${basePackage}.service.${serviceClassSimpleName}; | |
20 | - | |
21 | -import com.taover.util.UtilHttpRequestMap; | |
22 | -import com.taover.util.bean.ResultInfo; | |
23 | - | |
24 | -@RestController("manage.${controllerMap}") | |
25 | -@RequestMapping("/manage/${controllerMap}") | |
26 | -public class ${controllerClassName} { | |
27 | - @Resource | |
28 | - private ${serviceClassSimpleName} ${serviceClassFieldName}; | |
29 | - | |
30 | - /** | |
31 | - * @apiDefine ResultInfo | |
32 | - * @apiSuccess {string} | |
33 | - * @apiSuccessExample {json} Success-Response: | |
34 | - * { | |
35 | - * code:ok, | |
36 | - * error:null | |
37 | - * } | |
38 | - * @apiError ThrowException 出现异常 | |
39 | - * @apiErrorExample | |
40 | - * { | |
41 | - * code:fail, | |
42 | - * error:null exception | |
43 | - * } | |
44 | - */ | |
45 | - | |
46 | - /** | |
47 | - * @api {GET} /manage/${controllerMap} 查询${controllerMap}列表 | |
48 | - * @apiDescription 查询${controllerMap}列表数据 | |
49 | - * 返回分页结果 | |
50 | - * | |
51 | - * @apiGroup ${controllerMap} | |
52 | - * @apiName ${controllerMap}列表 | |
53 | - * @apiVersion 1.0.0 | |
54 | - * @apiHeader Authorization | |
55 | - * | |
56 | - * @apiUse ResultInfo | |
57 | - */ | |
58 | - @GetMapping | |
59 | - public ResultInfo get(HttpServletRequest request){ | |
60 | - String pageStr = request.getParameter("page"); | |
61 | - if(StringUtils.isEmpty(pageStr)){ | |
62 | - pageStr = ""+GlobalConstants.DEFAULT_QUERY_PAGE; | |
63 | - } | |
64 | - String sizeStr = request.getParameter("size"); | |
65 | - if(StringUtils.isEmpty(sizeStr)){ | |
66 | - sizeStr = ""+GlobalConstants.DEFAULT_QUERY_PAGE_SIZE; | |
67 | - } | |
68 | - List<Object[]> condition = UtilHttpRequestMap.getSqlConditionListByRequestMap(request.getParameterMap(), ${entityClassSimpleName}.class, "page,size"); | |
69 | - return this.${serviceClassFieldName}.getListManage(condition, Integer.valueOf(pageStr), Integer.valueOf(sizeStr)); | |
70 | - } | |
71 | - | |
72 | - /** | |
73 | - * @api {GET} /manage/${controllerMap}/{id} 查询id对应的${controllerMap} | |
74 | - * @apiDescription 查询ssid对应${controllerMap}数据 | |
75 | - * | |
76 | - * @apiGroup ${controllerMap} | |
77 | - * @apiName get实体数据 | |
78 | - * @apiVersion 1.0.0 | |
79 | - * @apiHeader Authorization | |
80 | - * | |
81 | - * @apiUse ResultInfo | |
82 | - */ | |
83 | - @GetMapping("/{id}") | |
84 | - public ResultInfo get(@PathVariable Integer id){ | |
85 | - return this.${serviceClassFieldName}.getOneManage(id); | |
86 | - } | |
87 | - | |
88 | - /** | |
89 | - * @api {POST} /manage/${controllerMap} 创建${controllerMap} | |
90 | - * @apiDescription 创建${controllerMap} | |
91 | - * | |
92 | - * @apiGroup ${controllerMap} | |
93 | - * @apiName get实体数据 | |
94 | - * @apiVersion 1.0.0 | |
95 | - * @apiHeader Authorization | |
96 | - * | |
97 | - * @apiUse ResultInfo | |
98 | - */ | |
99 | - @PostMapping | |
100 | - public ResultInfo post(HttpServletRequest request){ | |
101 | - return this.${serviceClassFieldName}.postManage(UtilHttpRequestMap.getMapValueStringByRequestMap(request.getParameterMap())); | |
102 | - } | |
103 | - | |
104 | - /** | |
105 | - * @api {DELETE} /manage/${controllerMap}/{id} 删除id对应的${controllerMap} | |
106 | - * @apiDescription 删除id对应的${controllerMap}数据 | |
107 | - * | |
108 | - * @apiGroup ${controllerMap} | |
109 | - * @apiName 删除实体数据 | |
110 | - * @apiVersion 1.0.0 | |
111 | - * @apiHeader Authorization | |
112 | - * | |
113 | - * @apiUse ResultInfo | |
114 | - */ | |
115 | - @DeleteMapping("/{id}") | |
116 | - public ResultInfo delete(@PathVariable Integer id){ | |
117 | - return this.${serviceClassFieldName}.deleteManage(id); | |
118 | - } | |
119 | - | |
120 | - /** | |
121 | - * @api {PUT} /manage/${controllerMap}/{id} 修改${controllerMap}数据 | |
122 | - * @apiDescription 修改${controllerMap}数据 | |
123 | - * | |
124 | - * @apiGroup ${controllerMap} | |
125 | - * @apiName 修改实体数据 | |
126 | - * @apiVersion 1.0.0 | |
127 | - * @apiHeader Authorization | |
128 | - * | |
129 | - * @apiUse ResultInfo | |
130 | - */ | |
131 | - @PutMapping("/{id}") | |
132 | - public ResultInfo put(@PathVariable Integer id, HttpServletRequest request){ | |
133 | - return this.${serviceClassFieldName}.putManage(id, UtilHttpRequestMap.getUpdateListByRequestMap(request.getParameterMap(), ${entityClassSimpleName}.class, null)); | |
134 | - } | |
135 | - | |
136 | -} |