Commit 63054ec530a3154e730972f5833df7d6494913ac

Authored by 王彬
1 parent a3d6c501
Exists in master

1.优化生成代码

src/com/taover/base/template/ControllerTemplate.ftl
@@ -103,7 +103,7 @@ public class ${controllerClassName} { @@ -103,7 +103,7 @@ public class ${controllerClassName} {
103 @RequestParam(value="sort", required=false) String sort, 103 @RequestParam(value="sort", required=false) String sort,
104 @RequestParam(value="order", required=false) String order, 104 @RequestParam(value="order", required=false) String order,
105 @RequestParam(value="page", required=false) Integer page, 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 HttpServletRequest request) { 107 HttpServletRequest request) {
108 //参数检验 108 //参数检验
109 if(page == null){ 109 if(page == null){
@@ -112,7 +112,7 @@ public class ${controllerClassName} { @@ -112,7 +112,7 @@ public class ${controllerClassName} {
112 if(pageSize == null){ 112 if(pageSize == null){
113 pageSize = 20; 113 pageSize = 20;
114 } 114 }
115 - if("".equals(sort)){ 115 + if(sort == null || "".equals(sort)){
116 sort = "id"; 116 sort = "id";
117 order = "desc"; 117 order = "desc";
118 } 118 }
src/com/taover/base/template/HtmlLayuiTemplate.ftl
@@ -49,11 +49,13 @@ @@ -49,11 +49,13 @@
49 49
50 <!-- 添加表单 --> 50 <!-- 添加表单 -->
51 <form id="form-data-add" class="layui-hide layui-form" lay-filter="form-data-add"> 51 <form id="form-data-add" class="layui-hide layui-form" lay-filter="form-data-add">
  52 + <div class="layui-form-item">
52 <#list fields as tempField> 53 <#list fields as tempField>
53 <#if (tempField["name"]!="id")> 54 <#if (tempField["name"]!="id")>
54 ${tempField["layui-form-item"]} 55 ${tempField["layui-form-item"]}
55 </#if> 56 </#if>
56 </#list> 57 </#list>
  58 + </div>
57 59
58 <div class="layui-form-item"> 60 <div class="layui-form-item">
59 <div class="layui-input-block"> 61 <div class="layui-input-block">
@@ -65,9 +67,11 @@ @@ -65,9 +67,11 @@
65 67
66 <!-- 修改表单 --> 68 <!-- 修改表单 -->
67 <form id="form-data-edit" class="layui-hide layui-form" lay-filter="form-data-edit"> 69 <form id="form-data-edit" class="layui-hide layui-form" lay-filter="form-data-edit">
  70 + <div class="layui-form-item">
68 <#list fields as tempField> 71 <#list fields as tempField>
69 ${tempField["layui-form-item"]} 72 ${tempField["layui-form-item"]}
70 </#list> 73 </#list>
  74 + </div>
71 75
72 <div class="layui-form-item"> 76 <div class="layui-form-item">
73 <div class="layui-input-block"> 77 <div class="layui-input-block">
@@ -76,10 +80,7 @@ @@ -76,10 +80,7 @@
76 </div> 80 </div>
77 </div> 81 </div>
78 </form> 82 </form>
79 -  
80 - <!-- 隐藏信息 -->  
81 - <input id="data-checkList" type="hidden" name="ids" value=""/>  
82 - 83 +
83 <script src="/plugins/layuiadmin/layui/layui.js"></script> 84 <script src="/plugins/layuiadmin/layui/layui.js"></script>
84 <script> 85 <script>
85 layui.config({ 86 layui.config({
@@ -173,14 +174,17 @@ @@ -173,14 +174,17 @@
173 }); 174 });
174 } 175 }
175 } else if(obj.event === 'edit'){ //修改按钮操作入口 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 layer.open({ 178 layer.open({
178 title: '修改窗口', 179 title: '修改窗口',
179 type: 1, 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 form.render(); 188 form.render();
185 $('.me-date-form').each(function(index, element){ 189 $('.me-date-form').each(function(index, element){
186 laydate.render({ 190 laydate.render({
@@ -190,45 +194,6 @@ @@ -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 form.on('submit(btn-search-bar)', function(data){ 199 form.on('submit(btn-search-bar)', function(data){
@@ -248,15 +213,18 @@ @@ -248,15 +213,18 @@
248 var layer = layui.layer; 213 var layer = layui.layer;
249 var form = layui.form; 214 var form = layui.form;
250 var laydate = layui.laydate; 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 layer.open({ 217 layer.open({
253 title: '添加窗口', 218 title: '添加窗口',
254 type: 1, 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 form.render(); 226 form.render();
259 - $('#activeForm .me-date-form').each(function(index, element){ 227 + $('#form-data-add .me-date-form').each(function(index, element){
260 laydate.render({ 228 laydate.render({
261 elem: element, 229 elem: element,
262 type: 'datetime' 230 type: 'datetime'
@@ -272,7 +240,7 @@ @@ -272,7 +240,7 @@
272 var layer = layui.layer; 240 var layer = layui.layer;
273 var form = layui.form; 241 var form = layui.form;
274 var table = layui.table; 242 var table = layui.table;
275 - var formArray = $('#activeForm').serializeArray(); 243 + var formArray = $('#form-data-add').serializeArray();
276 var params = {}; 244 var params = {};
277 layui.each(formArray, function(index, item){ 245 layui.each(formArray, function(index, item){
278 params[item.name] = item.value; 246 params[item.name] = item.value;
@@ -305,13 +273,16 @@ @@ -305,13 +273,16 @@
305 var layer = layui.layer; 273 var layer = layui.layer;
306 var form = layui.form; 274 var form = layui.form;
307 var table = layui.table; 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 layer.alert('没有选择任何选项,请选择需要删除记录再进行该操作'); 278 layer.alert('没有选择任何选项,请选择需要删除记录再进行该操作');
311 return; 279 return;
312 }else{ 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 $.ajax({ 286 $.ajax({
316 url: '/${controllerPathMap}/delete.htm', 287 url: '/${controllerPathMap}/delete.htm',
317 type: 'post', 288 type: 'post',
@@ -344,7 +315,7 @@ @@ -344,7 +315,7 @@
344 var layer = layui.layer; 315 var layer = layui.layer;
345 var form = layui.form; 316 var form = layui.form;
346 var table = layui.table; 317 var table = layui.table;
347 - var formArray = $('#activeForm').serializeArray(); 318 + var formArray = $('#form-data-edit').serializeArray();
348 var params = {}; 319 var params = {};
349 layui.each(formArray, function(index, item){ 320 layui.each(formArray, function(index, item){
350 params[item.name] = item.value; 321 params[item.name] = item.value;
src/com/taover/base/template/model/bussiness/ViewModel.java
@@ -59,22 +59,27 @@ public class ViewModel { @@ -59,22 +59,27 @@ public class ViewModel {
59 String easyuiSearchDom = ""; 59 String easyuiSearchDom = "";
60 String layuiSearchDom = ""; 60 String layuiSearchDom = "";
61 String layuiFormDom = ""; 61 String layuiFormDom = "";
  62 + String layuiTableHeaderDom = "";
62 if(remarkPart.length > 1){ 63 if(remarkPart.length > 1){
63 easyuiSearchDom = ViewModel.parseEasyuiSearchSelect(fieldName, cnName, remarkPart[1]); 64 easyuiSearchDom = ViewModel.parseEasyuiSearchSelect(fieldName, cnName, remarkPart[1]);
64 layuiSearchDom = ViewModel.parseLayuiSearchSelect(fieldName, cnName, remarkPart[1]); 65 layuiSearchDom = ViewModel.parseLayuiSearchSelect(fieldName, cnName, remarkPart[1]);
65 layuiFormDom = ViewModel.parseLayuiFormSelect(fieldName, cnName, remarkPart[1]); 66 layuiFormDom = ViewModel.parseLayuiFormSelect(fieldName, cnName, remarkPart[1]);
  67 + layuiTableHeaderDom = ViewModel.parseLayuiTableHeaderSelect(fieldName, cnName, remarkPart[1]);
66 }else if("java.util.Date|java.sql.Time|java.sql.Timestamp".indexOf(fieldType) != -1){ 68 }else if("java.util.Date|java.sql.Time|java.sql.Timestamp".indexOf(fieldType) != -1){
67 easyuiSearchDom = ViewModel.parseEasyuiSearchDatetime(fieldName, cnName); 69 easyuiSearchDom = ViewModel.parseEasyuiSearchDatetime(fieldName, cnName);
68 layuiSearchDom = ViewModel.parseLayuiSearchDatetime(fieldName, cnName); 70 layuiSearchDom = ViewModel.parseLayuiSearchDatetime(fieldName, cnName);
69 layuiFormDom = ViewModel.parseLayuiFormDatetime(fieldName, cnName); 71 layuiFormDom = ViewModel.parseLayuiFormDatetime(fieldName, cnName);
  72 + layuiTableHeaderDom = ViewModel.parseLayuiTableHeader(fieldName, cnName);
70 }else if("Byte|Long|Integer|Short".indexOf(fieldType) != -1){ 73 }else if("Byte|Long|Integer|Short".indexOf(fieldType) != -1){
71 easyuiSearchDom = ViewModel.parseEasyuiSearchNumber(fieldName, cnName); 74 easyuiSearchDom = ViewModel.parseEasyuiSearchNumber(fieldName, cnName);
72 layuiSearchDom = ViewModel.parseLayuiSearchNumber(fieldName, cnName); 75 layuiSearchDom = ViewModel.parseLayuiSearchNumber(fieldName, cnName);
73 layuiFormDom = ViewModel.parseLayuiFormNumber(fieldName, cnName); 76 layuiFormDom = ViewModel.parseLayuiFormNumber(fieldName, cnName);
  77 + layuiTableHeaderDom = ViewModel.parseLayuiTableHeader(fieldName, cnName);
74 }else{ 78 }else{
75 easyuiSearchDom = ViewModel.parseEasyuiSearchText(fieldName, cnName); 79 easyuiSearchDom = ViewModel.parseEasyuiSearchText(fieldName, cnName);
76 layuiSearchDom = ViewModel.parseLayuiSearchText(fieldName, cnName); 80 layuiSearchDom = ViewModel.parseLayuiSearchText(fieldName, cnName);
77 layuiFormDom = ViewModel.parseLayuiFormText(fieldName, cnName); 81 layuiFormDom = ViewModel.parseLayuiFormText(fieldName, cnName);
  82 + layuiTableHeaderDom = ViewModel.parseLayuiTableHeader(fieldName, cnName);
78 } 83 }
79 //构造easyui筛选栏元素 84 //构造easyui筛选栏元素
80 columnMap.put("easyui-search-item", easyuiSearchDom); 85 columnMap.put("easyui-search-item", easyuiSearchDom);
@@ -86,7 +91,7 @@ public class ViewModel { @@ -86,7 +91,7 @@ public class ViewModel {
86 columnMap.put("layui-form-item", layuiFormDom); 91 columnMap.put("layui-form-item", layuiFormDom);
87 92
88 //构造layui表格表头 93 //构造layui表格表头
89 - columnMap.put("layui-table-item", ViewModel.parseLayuiTableHeader(fieldName, cnName)); 94 + columnMap.put("layui-table-item", layuiTableHeaderDom);
90 95
91 model.fields.add(columnMap); 96 model.fields.add(columnMap);
92 } 97 }
@@ -241,7 +246,7 @@ public class ViewModel { @@ -241,7 +246,7 @@ public class ViewModel {
241 } 246 }
242 247
243 public static String parseLayuiFormSelect(String name, String cnName, String optionStr){ 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 + "<label class=\"layui-form-label\">"+cnName+"</label>" 250 + "<label class=\"layui-form-label\">"+cnName+"</label>"
246 + "<div class=\"layui-input-block\">" 251 + "<div class=\"layui-input-block\">"
247 + "<select name=\""+name+"\">" 252 + "<select name=\""+name+"\">"
@@ -287,7 +292,7 @@ public class ViewModel { @@ -287,7 +292,7 @@ public class ViewModel {
287 * @return 292 * @return
288 */ 293 */
289 public static String parseLayuiFormDatetime(String name, String cnName){ 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 + "<label class=\"layui-form-label\">"+cnName+"</label>" 296 + "<label class=\"layui-form-label\">"+cnName+"</label>"
292 + "<div class=\"layui-input-block\">" 297 + "<div class=\"layui-input-block\">"
293 +"<input type=\"text\" name=\""+name+"\" placeholder=\"请输入\" class=\"layui-input me-date-form\" >" 298 +"<input type=\"text\" name=\""+name+"\" placeholder=\"请输入\" class=\"layui-input me-date-form\" >"
@@ -296,7 +301,7 @@ public class ViewModel { @@ -296,7 +301,7 @@ public class ViewModel {
296 } 301 }
297 302
298 public static String parseLayuiFormNumber(String name, String cnName){ 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 + "<label class=\"layui-form-label\">"+cnName+"</label>" 305 + "<label class=\"layui-form-label\">"+cnName+"</label>"
301 + "<div class=\"layui-input-block\">" 306 + "<div class=\"layui-input-block\">"
302 +"<input type=\"number\" name=\""+name+"\" class=\"layui-input\" >" 307 +"<input type=\"number\" name=\""+name+"\" class=\"layui-input\" >"
@@ -305,7 +310,7 @@ public class ViewModel { @@ -305,7 +310,7 @@ public class ViewModel {
305 } 310 }
306 311
307 public static String parseLayuiFormText(String name, String cnName){ 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 + "<label class=\"layui-form-label\">"+cnName+"</label>" 314 + "<label class=\"layui-form-label\">"+cnName+"</label>"
310 + "<div class=\"layui-input-block\">" 315 + "<div class=\"layui-input-block\">"
311 +"<input type=\"text\" name=\""+name+"\" placeholder=\"请输入\" class=\"layui-input\" >" 316 +"<input type=\"text\" name=\""+name+"\" placeholder=\"请输入\" class=\"layui-input\" >"
@@ -317,6 +322,48 @@ public class ViewModel { @@ -317,6 +322,48 @@ public class ViewModel {
317 String header = "{title:'"+cnName+"', field:'"+name+"', width:100, sort: true},"; 322 String header = "{title:'"+cnName+"', field:'"+name+"', width:100, sort: true},";
318 return header; 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 public String getTableName(){ 368 public String getTableName(){
322 return tableName; 369 return tableName;
src/com/taover/business/GenerateView.java
@@ -34,6 +34,11 @@ public class GenerateView { @@ -34,6 +34,11 @@ public class GenerateView {
34 String dbType = properties.getProperty("dbtype"); 34 String dbType = properties.getProperty("dbtype");
35 String dbPackagePath = properties.getProperty("packageName"); 35 String dbPackagePath = properties.getProperty("packageName");
36 String tableName = properties.getProperty("TableName"); 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 //WebRootPath读取 43 //WebRootPath读取
39 String webRootPath = properties.getProperty("WebRootPath"); 44 String webRootPath = properties.getProperty("WebRootPath");
@@ -85,7 +90,7 @@ public class GenerateView { @@ -85,7 +90,7 @@ public class GenerateView {
85 String moduleName = tableNameCurr.split("_")[0]; 90 String moduleName = tableNameCurr.split("_")[0];
86 91
87 //生成view 92 //生成view
88 - generateView(webRootPath, tableNameCurr, columnsInTable, false, moduleName); 93 + generateView(webRootPath, tableNameCurr, columnsInTable, coverWhenFileExists, moduleName);
89 94
90 System.out.println(tableNameCurr + " : 生成结束"); 95 System.out.println(tableNameCurr + " : 生成结束");
91 } 96 }