Commit 63054ec530a3154e730972f5833df7d6494913ac
1 parent
a3d6c501
Exists in
master
1.优化生成代码
Showing
4 changed files
with
88 additions
and
65 deletions
Show diff stats
src/com/taover/base/template/ControllerTemplate.ftl
... | ... | @@ -103,7 +103,7 @@ public class ${controllerClassName} { |
103 | 103 | @RequestParam(value="sort", required=false) String sort, |
104 | 104 | @RequestParam(value="order", required=false) String order, |
105 | 105 | @RequestParam(value="page", required=false) Integer page, |
106 | - @RequestParam(value="rows", required=false) Integer pageSize, | |
106 | + @RequestParam(value="pageSize", required=false) Integer pageSize, | |
107 | 107 | HttpServletRequest request) { |
108 | 108 | //参数检验 |
109 | 109 | if(page == null){ |
... | ... | @@ -112,7 +112,7 @@ public class ${controllerClassName} { |
112 | 112 | if(pageSize == null){ |
113 | 113 | pageSize = 20; |
114 | 114 | } |
115 | - if("".equals(sort)){ | |
115 | + if(sort == null || "".equals(sort)){ | |
116 | 116 | sort = "id"; |
117 | 117 | order = "desc"; |
118 | 118 | } | ... | ... |
src/com/taover/base/template/HtmlLayuiTemplate.ftl
... | ... | @@ -49,11 +49,13 @@ |
49 | 49 | |
50 | 50 | <!-- 添加表单 --> |
51 | 51 | <form id="form-data-add" class="layui-hide layui-form" lay-filter="form-data-add"> |
52 | + <div class="layui-form-item"> | |
52 | 53 | <#list fields as tempField> |
53 | 54 | <#if (tempField["name"]!="id")> |
54 | 55 | ${tempField["layui-form-item"]} |
55 | 56 | </#if> |
56 | 57 | </#list> |
58 | + </div> | |
57 | 59 | |
58 | 60 | <div class="layui-form-item"> |
59 | 61 | <div class="layui-input-block"> |
... | ... | @@ -65,9 +67,11 @@ |
65 | 67 | |
66 | 68 | <!-- 修改表单 --> |
67 | 69 | <form id="form-data-edit" class="layui-hide layui-form" lay-filter="form-data-edit"> |
70 | + <div class="layui-form-item"> | |
68 | 71 | <#list fields as tempField> |
69 | 72 | ${tempField["layui-form-item"]} |
70 | 73 | </#list> |
74 | + </div> | |
71 | 75 | |
72 | 76 | <div class="layui-form-item"> |
73 | 77 | <div class="layui-input-block"> |
... | ... | @@ -76,10 +80,7 @@ |
76 | 80 | </div> |
77 | 81 | </div> |
78 | 82 | </form> |
79 | - | |
80 | - <!-- 隐藏信息 --> | |
81 | - <input id="data-checkList" type="hidden" name="ids" value=""/> | |
82 | - | |
83 | + | |
83 | 84 | <script src="/plugins/layuiadmin/layui/layui.js"></script> |
84 | 85 | <script> |
85 | 86 | layui.config({ |
... | ... | @@ -173,14 +174,17 @@ |
173 | 174 | }); |
174 | 175 | } |
175 | 176 | } else if(obj.event === 'edit'){ //修改按钮操作入口 |
176 | - var formHtml = '<form id="activeForm" class="layui-form" lay-filter="activeForm" style="padding:20px;">' + $('#form-data-edit').html() + '</form>'; | |
177 | + $('#form-data-edit').removeClass('layui-hide'); | |
177 | 178 | layer.open({ |
178 | 179 | title: '修改窗口', |
179 | 180 | type: 1, |
180 | - content: formHtml, | |
181 | - btn: null | |
181 | + content: $('#form-data-edit'), | |
182 | + btn: null, | |
183 | + end: function(){ | |
184 | + $('#form-data-edit').addClass('layui-hide'); | |
185 | + } | |
182 | 186 | }); |
183 | - form.val('activeForm', data); | |
187 | + form.val('form-data-edit', data); | |
184 | 188 | form.render(); |
185 | 189 | $('.me-date-form').each(function(index, element){ |
186 | 190 | laydate.render({ |
... | ... | @@ -190,45 +194,6 @@ |
190 | 194 | }); |
191 | 195 | } |
192 | 196 | }); |
193 | - | |
194 | - //表格的checkbox事件 | |
195 | - table.on('checkbox(table-data-main)', function(obj){ | |
196 | - var ids = $('#data-checkList').val(); | |
197 | - var idsArray = new Array(); | |
198 | - var resultArray = new Array(); | |
199 | - if(ids != ''){ | |
200 | - idsArray = ids.split(','); | |
201 | - resultArray = ids.split(','); | |
202 | - } | |
203 | - | |
204 | - if(obj.checked){ | |
205 | - if(obj.type === 'one'){ | |
206 | - resultArray.push(obj.data.id); | |
207 | - }else{ | |
208 | - var tempData = window.document.global_tableData.rows; | |
209 | - for(var i=0; i<tempData.length; ++i){ | |
210 | - resultArray.push(tempData[i].id); | |
211 | - } | |
212 | - } | |
213 | - }else{ | |
214 | - if(obj.type === 'one'){ | |
215 | - resultArray = new Array(); | |
216 | - $(idsArray).each(function(index, item){ | |
217 | - if(obj.data.id != item){ | |
218 | - resultArray.push(item); | |
219 | - } | |
220 | - }); | |
221 | - }else{ | |
222 | - resultArray = new Array(); | |
223 | - } | |
224 | - } | |
225 | - | |
226 | - var tempResult = ''; | |
227 | - if(resultArray.length > 0){ | |
228 | - tempResult = resultArray.join(','); | |
229 | - } | |
230 | - $('#data-checkList').val(tempResult); | |
231 | - }); | |
232 | 197 | |
233 | 198 | //搜索按钮点击事件 |
234 | 199 | form.on('submit(btn-search-bar)', function(data){ |
... | ... | @@ -248,15 +213,18 @@ |
248 | 213 | var layer = layui.layer; |
249 | 214 | var form = layui.form; |
250 | 215 | var laydate = layui.laydate; |
251 | - var formHtml = '<form id="activeForm" class="layui-form " style="padding:20px;">' + $('#form-data-add').html() + '</form>'; | |
216 | + $('#form-data-add').removeClass('layui-hide'); | |
252 | 217 | layer.open({ |
253 | 218 | title: '添加窗口', |
254 | 219 | type: 1, |
255 | - content: formHtml, | |
256 | - btn: null | |
220 | + content: $('#form-data-add'), | |
221 | + btn: null, | |
222 | + end: function(){ | |
223 | + $('#form-data-add').addClass('layui-hide'); | |
224 | + } | |
257 | 225 | }); |
258 | 226 | form.render(); |
259 | - $('#activeForm .me-date-form').each(function(index, element){ | |
227 | + $('#form-data-add .me-date-form').each(function(index, element){ | |
260 | 228 | laydate.render({ |
261 | 229 | elem: element, |
262 | 230 | type: 'datetime' |
... | ... | @@ -272,7 +240,7 @@ |
272 | 240 | var layer = layui.layer; |
273 | 241 | var form = layui.form; |
274 | 242 | var table = layui.table; |
275 | - var formArray = $('#activeForm').serializeArray(); | |
243 | + var formArray = $('#form-data-add').serializeArray(); | |
276 | 244 | var params = {}; |
277 | 245 | layui.each(formArray, function(index, item){ |
278 | 246 | params[item.name] = item.value; |
... | ... | @@ -305,13 +273,16 @@ |
305 | 273 | var layer = layui.layer; |
306 | 274 | var form = layui.form; |
307 | 275 | var table = layui.table; |
308 | - var ids = $('#data-checkList').val(); | |
309 | - if(ids == '' || ids.length == 0){ | |
276 | + var checkedData = table.checkStatus('table-data-main').data; //test即为基础参数id对应的值 | |
277 | + if(checkedData == null || checkedData.length == 0){ | |
310 | 278 | layer.alert('没有选择任何选项,请选择需要删除记录再进行该操作'); |
311 | 279 | return; |
312 | 280 | }else{ |
313 | - var idsArray = ids.split(','); | |
314 | - layer.confirm('您当前选择了'+idsArray.length+'条记录,是否确认删除?', function(){ | |
281 | + var ids = checkedData[0].id; | |
282 | + for(var i=1; i<checkedData.length; ++i){ | |
283 | + ids += ','+checkedData[i].id; | |
284 | + } | |
285 | + layer.confirm('您当前选择了'+checkedData.length+'条记录,是否确认删除?', function(){ | |
315 | 286 | $.ajax({ |
316 | 287 | url: '/${controllerPathMap}/delete.htm', |
317 | 288 | type: 'post', |
... | ... | @@ -344,7 +315,7 @@ |
344 | 315 | var layer = layui.layer; |
345 | 316 | var form = layui.form; |
346 | 317 | var table = layui.table; |
347 | - var formArray = $('#activeForm').serializeArray(); | |
318 | + var formArray = $('#form-data-edit').serializeArray(); | |
348 | 319 | var params = {}; |
349 | 320 | layui.each(formArray, function(index, item){ |
350 | 321 | params[item.name] = item.value; | ... | ... |
src/com/taover/base/template/model/bussiness/ViewModel.java
... | ... | @@ -59,22 +59,27 @@ public class ViewModel { |
59 | 59 | String easyuiSearchDom = ""; |
60 | 60 | String layuiSearchDom = ""; |
61 | 61 | String layuiFormDom = ""; |
62 | + String layuiTableHeaderDom = ""; | |
62 | 63 | if(remarkPart.length > 1){ |
63 | 64 | easyuiSearchDom = ViewModel.parseEasyuiSearchSelect(fieldName, cnName, remarkPart[1]); |
64 | 65 | layuiSearchDom = ViewModel.parseLayuiSearchSelect(fieldName, cnName, remarkPart[1]); |
65 | 66 | layuiFormDom = ViewModel.parseLayuiFormSelect(fieldName, cnName, remarkPart[1]); |
67 | + layuiTableHeaderDom = ViewModel.parseLayuiTableHeaderSelect(fieldName, cnName, remarkPart[1]); | |
66 | 68 | }else if("java.util.Date|java.sql.Time|java.sql.Timestamp".indexOf(fieldType) != -1){ |
67 | 69 | easyuiSearchDom = ViewModel.parseEasyuiSearchDatetime(fieldName, cnName); |
68 | 70 | layuiSearchDom = ViewModel.parseLayuiSearchDatetime(fieldName, cnName); |
69 | 71 | layuiFormDom = ViewModel.parseLayuiFormDatetime(fieldName, cnName); |
72 | + layuiTableHeaderDom = ViewModel.parseLayuiTableHeader(fieldName, cnName); | |
70 | 73 | }else if("Byte|Long|Integer|Short".indexOf(fieldType) != -1){ |
71 | 74 | easyuiSearchDom = ViewModel.parseEasyuiSearchNumber(fieldName, cnName); |
72 | 75 | layuiSearchDom = ViewModel.parseLayuiSearchNumber(fieldName, cnName); |
73 | 76 | layuiFormDom = ViewModel.parseLayuiFormNumber(fieldName, cnName); |
77 | + layuiTableHeaderDom = ViewModel.parseLayuiTableHeader(fieldName, cnName); | |
74 | 78 | }else{ |
75 | 79 | easyuiSearchDom = ViewModel.parseEasyuiSearchText(fieldName, cnName); |
76 | 80 | layuiSearchDom = ViewModel.parseLayuiSearchText(fieldName, cnName); |
77 | 81 | layuiFormDom = ViewModel.parseLayuiFormText(fieldName, cnName); |
82 | + layuiTableHeaderDom = ViewModel.parseLayuiTableHeader(fieldName, cnName); | |
78 | 83 | } |
79 | 84 | //构造easyui筛选栏元素 |
80 | 85 | columnMap.put("easyui-search-item", easyuiSearchDom); |
... | ... | @@ -86,7 +91,7 @@ public class ViewModel { |
86 | 91 | columnMap.put("layui-form-item", layuiFormDom); |
87 | 92 | |
88 | 93 | //构造layui表格表头 |
89 | - columnMap.put("layui-table-item", ViewModel.parseLayuiTableHeader(fieldName, cnName)); | |
94 | + columnMap.put("layui-table-item", layuiTableHeaderDom); | |
90 | 95 | |
91 | 96 | model.fields.add(columnMap); |
92 | 97 | } |
... | ... | @@ -241,7 +246,7 @@ public class ViewModel { |
241 | 246 | } |
242 | 247 | |
243 | 248 | public static String parseLayuiFormSelect(String name, String cnName, String optionStr){ |
244 | - String LayuiFormEle = "<div class=\"layui-form-item\">" | |
249 | + String LayuiFormEle = "<div class=\"layui-inline\">" | |
245 | 250 | + "<label class=\"layui-form-label\">"+cnName+"</label>" |
246 | 251 | + "<div class=\"layui-input-block\">" |
247 | 252 | + "<select name=\""+name+"\">" |
... | ... | @@ -287,7 +292,7 @@ public class ViewModel { |
287 | 292 | * @return |
288 | 293 | */ |
289 | 294 | public static String parseLayuiFormDatetime(String name, String cnName){ |
290 | - String dateBoxDom = "<div class=\"layui-form-item\">" | |
295 | + String dateBoxDom = "<div class=\"layui-inline\">" | |
291 | 296 | + "<label class=\"layui-form-label\">"+cnName+"</label>" |
292 | 297 | + "<div class=\"layui-input-block\">" |
293 | 298 | +"<input type=\"text\" name=\""+name+"\" placeholder=\"请输入\" class=\"layui-input me-date-form\" >" |
... | ... | @@ -296,7 +301,7 @@ public class ViewModel { |
296 | 301 | } |
297 | 302 | |
298 | 303 | public static String parseLayuiFormNumber(String name, String cnName){ |
299 | - String dateBoxDom = "<div class=\"layui-form-item\">" | |
304 | + String dateBoxDom = "<div class=\"layui-inline\">" | |
300 | 305 | + "<label class=\"layui-form-label\">"+cnName+"</label>" |
301 | 306 | + "<div class=\"layui-input-block\">" |
302 | 307 | +"<input type=\"number\" name=\""+name+"\" class=\"layui-input\" >" |
... | ... | @@ -305,7 +310,7 @@ public class ViewModel { |
305 | 310 | } |
306 | 311 | |
307 | 312 | public static String parseLayuiFormText(String name, String cnName){ |
308 | - String dateBoxDom = "<div class=\"layui-form-item\">" | |
313 | + String dateBoxDom = "<div class=\"layui-inline\">" | |
309 | 314 | + "<label class=\"layui-form-label\">"+cnName+"</label>" |
310 | 315 | + "<div class=\"layui-input-block\">" |
311 | 316 | +"<input type=\"text\" name=\""+name+"\" placeholder=\"请输入\" class=\"layui-input\" >" |
... | ... | @@ -317,6 +322,48 @@ public class ViewModel { |
317 | 322 | String header = "{title:'"+cnName+"', field:'"+name+"', width:100, sort: true},"; |
318 | 323 | return header; |
319 | 324 | } |
325 | + | |
326 | + public static String parseLayuiTableHeaderSelect(String name, String cnName, String optionStr){ | |
327 | + String header = "{title:'"+cnName+"', field:'"+name+"', width:100, sort: true, "; | |
328 | + String[] options = optionStr.split(","); | |
329 | + List<String> optionsList = new ArrayList<String>(); | |
330 | + for(int i=0; i<options.length; ++i){ | |
331 | + String tempOption = options[i]; | |
332 | + if(tempOption.contains(",")){ | |
333 | + String[] optionsExt = tempOption.split(","); | |
334 | + if(optionsExt.length > 0){ | |
335 | + for(int j=0; j<optionsExt.length; ++j){ | |
336 | + optionsList.add(optionsExt[j]); | |
337 | + } | |
338 | + } | |
339 | + }else{ | |
340 | + optionsList.add(options[i]); | |
341 | + } | |
342 | + } | |
343 | + | |
344 | + String remarkStr = "\t\t\t\t//"+cnName+":"; | |
345 | + String caseStr = ""; | |
346 | + for(int i=0; i<optionsList.size(); ++i){ | |
347 | + String optionsItem = optionsList.get(i); | |
348 | + String[] optionsArr = optionsItem.split("-"); | |
349 | + String optionName = "未知名称"; | |
350 | + if(optionsArr.length > 1){ | |
351 | + optionName = optionsArr[1]; | |
352 | + } | |
353 | + caseStr += "\t\t\t\t\tcase "+optionsArr[0]+": return '"+optionName+"';\n"; | |
354 | + remarkStr += optionsArr[0]+"-"+optionName+","; | |
355 | + } | |
356 | + String displayInfo = " templet: function(d){ \n" | |
357 | + + remarkStr +"\n" | |
358 | + + "\t\t\t\tswitch(d."+name+"){ \n" | |
359 | + + caseStr | |
360 | + + "\t\t\t\t\tdefault: return '未知状态';\n" | |
361 | + + "\t\t\t\t}\n" | |
362 | + + "\t\t\t}"; | |
363 | + | |
364 | + header = header + displayInfo + "},"; | |
365 | + return header; | |
366 | + } | |
320 | 367 | |
321 | 368 | public String getTableName(){ |
322 | 369 | return tableName; | ... | ... |
src/com/taover/business/GenerateView.java
... | ... | @@ -34,6 +34,11 @@ public class GenerateView { |
34 | 34 | String dbType = properties.getProperty("dbtype"); |
35 | 35 | String dbPackagePath = properties.getProperty("packageName"); |
36 | 36 | String tableName = properties.getProperty("TableName"); |
37 | + //如果文件已存在是否覆盖 | |
38 | + boolean coverWhenFileExists = false; | |
39 | + if(properties.getProperty("coverWhenFileExists") != null){ | |
40 | + coverWhenFileExists = Boolean.valueOf(properties.getProperty("coverWhenFileExists")); | |
41 | + } | |
37 | 42 | |
38 | 43 | //WebRootPath读取 |
39 | 44 | String webRootPath = properties.getProperty("WebRootPath"); |
... | ... | @@ -85,7 +90,7 @@ public class GenerateView { |
85 | 90 | String moduleName = tableNameCurr.split("_")[0]; |
86 | 91 | |
87 | 92 | //生成view |
88 | - generateView(webRootPath, tableNameCurr, columnsInTable, false, moduleName); | |
93 | + generateView(webRootPath, tableNameCurr, columnsInTable, coverWhenFileExists, moduleName); | |
89 | 94 | |
90 | 95 | System.out.println(tableNameCurr + " : 生成结束"); |
91 | 96 | } | ... | ... |