diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f4501fe7..3b25631c 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,9 +1,9 @@ # 开发环境 -server.port=80 +server.port=8080 server.servlet.context-path= spring.mvc.static-path-pattern=/static/** spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:/file-upload -spring.application.name=EXAMPLE-WEB +spring.application.name=DBTOOL spring.main.banner-mode=CONSOLE spring.devtools.restart.enabled=true # 编码配置 diff --git a/src/main/resources/modules/SpringBoot/java/action/GlobalController.java b/src/main/resources/modules/SpringBoot/java/action/GlobalController.java index aa2c9bd7..f9644ed0 100644 --- a/src/main/resources/modules/SpringBoot/java/action/GlobalController.java +++ b/src/main/resources/modules/SpringBoot/java/action/GlobalController.java @@ -251,36 +251,31 @@ public class GlobalController implements ErrorController { @RequestMapping("/ajax/{module}/{target}/{method}") @ResponseBody - public BaseResponse ajax(@PathVariable String module, @PathVariable String target, @PathVariable String method, @RequestBody String param) { - BaseResponse baseResponse = null; - + public Object ajax(@PathVariable String module, @PathVariable String target, @PathVariable String method, @RequestBody String param) { try { String beanClassName = (ActionConfig.AJAX_PREFIX + module + "/" + target).toLowerCase(); Object ajax = LocalData.getApplicationContext().getBean(beanClassName); Class ajaxClass = ajax.getClass(); Method methodC = ajaxClass.getMethod(method, String.class); - Object invoke = methodC.invoke(ajax, param); - if (invoke instanceof BaseResponse) { - baseResponse = (BaseResponse) invoke; - } else { - baseResponse = new BaseResponse(); - baseResponse.addError(ErrorType.BUSINESS_ERROR, "方法返回值错误!"); - } + return methodC.invoke(ajax, ""); } catch (BeansException e) { - baseResponse = new BaseResponse(); + BaseResponse baseResponse = new BaseResponse(); baseResponse.addError(ErrorType.BUSINESS_ERROR, "未找到对应的目标!"); + return baseResponse; } catch (NoSuchMethodException e) { - baseResponse = new BaseResponse(); + BaseResponse baseResponse = new BaseResponse(); baseResponse.addError(ErrorType.BUSINESS_ERROR, "未找到对应的方法!"); + return baseResponse; } catch (IllegalAccessException e) { - baseResponse = new BaseResponse(); + BaseResponse baseResponse = new BaseResponse(); baseResponse.addError(ErrorType.BUSINESS_ERROR, "方法执必须公开!"); + return baseResponse; } catch (InvocationTargetException e) { - baseResponse = new BaseResponse(); + BaseResponse baseResponse = new BaseResponse(); baseResponse.addError(ErrorType.BUSINESS_ERROR, "方法执行错误!"); + return baseResponse; } - return baseResponse; } @RequestMapping("/download") diff --git a/src/main/resources/modules/SpringBoot/java/action/ajax/system/DictAjax.java b/src/main/resources/modules/SpringBoot/java/action/ajax/system/DictAjax.java index 393bc0b3..524d0182 100644 --- a/src/main/resources/modules/SpringBoot/java/action/ajax/system/DictAjax.java +++ b/src/main/resources/modules/SpringBoot/java/action/ajax/system/DictAjax.java @@ -1,11 +1,16 @@ package ${basePackage}.action.ajax.system; import ${basePackage}.frame.auth.LocalData; +import ${basePackage}.frame.excel.WSheet; import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.module.system.mgr.DictManager; import ${basePackage}.module.system.req.*; import ${basePackage}.module.system.rsp.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; public class DictAjax { @@ -41,4 +46,13 @@ public class DictAjax { DictLoadRequest request = MapperUtil.toJava(jsonParam, DictLoadRequest.class); return dictManager.load(request, LocalData.getToken()); } + + public ResponseEntity template(String jsonParam) throws IOException { + WSheet sheet = new WSheet<>(DictCreateRequest.class); + byte[] bytes = sheet.getBytes(); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); + headers.setContentDispositionFormData("attachment", new String((sheet.getName() + ".xlsx").getBytes("UTF-8"), "iso-8859-1")); + return new ResponseEntity(bytes, headers, HttpStatus.OK); + } } diff --git a/src/main/resources/modules/SpringBoot/java/frame/excel/WColumn.java b/src/main/resources/modules/SpringBoot/java/frame/excel/WColumn.java index 3d3d5223..7c6f5356 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/excel/WColumn.java +++ b/src/main/resources/modules/SpringBoot/java/frame/excel/WColumn.java @@ -1,8 +1,8 @@ package ${basePackage}.frame.excel; -import xyz.wbsite.frame.excel.converter.Converter; -import xyz.wbsite.frame.utils.StringUtil; +import ${basePackage}.frame.excel.converter.Converter; +import ${basePackage}.frame.utils.StringUtil; import java.io.Serializable; import java.lang.reflect.Field; diff --git a/src/main/resources/modules/SpringBoot/java/frame/excel/WSheet.java b/src/main/resources/modules/SpringBoot/java/frame/excel/WSheet.java index c97ec712..2b4b45db 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/excel/WSheet.java +++ b/src/main/resources/modules/SpringBoot/java/frame/excel/WSheet.java @@ -1,14 +1,14 @@ package ${basePackage}.frame.excel; -import xyz.wbsite.frame.excel.style.DataCellStyle; -import xyz.wbsite.frame.excel.style.ErrorCellStyle; -import xyz.wbsite.frame.excel.style.HeadCellStyle; -import xyz.wbsite.frame.excel.style.RedFont; -import xyz.wbsite.frame.utils.ClassUtil; -import xyz.wbsite.frame.utils.StringUtil; -import xyz.wbsite.frame.utils.ValidationUtil; -import xyz.wbsite.frame.excel.annotation.*; -import xyz.wbsite.frame.excel.converter.*; +import ${basePackage}.frame.excel.style.DataCellStyle; +import ${basePackage}.frame.excel.style.ErrorCellStyle; +import ${basePackage}.frame.excel.style.HeadCellStyle; +import ${basePackage}.frame.excel.style.RedFont; +import ${basePackage}.frame.utils.ClassUtil; +import ${basePackage}.frame.utils.StringUtil; +import ${basePackage}.frame.utils.ValidationUtil; +import ${basePackage}.frame.excel.annotation.*; +import ${basePackage}.frame.excel.converter.*; import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.*; @@ -70,7 +70,7 @@ public class WSheet implements Serializable, Cloneable { this.setName(sheetName.value()); this.setFreezeFirst(sheetName.freezeFirst()); } else { - this.setName(clazz.getName()); + this.setName(clazz.getSimpleName()); } //是否关注父类属性 @@ -102,11 +102,11 @@ public class WSheet implements Serializable, Cloneable { } //获取列类型 - if (field.isAnnotationPresent(xyz.wbsite.frame.excel.annotation.Converter.class)) { - xyz.wbsite.frame.excel.annotation.Converter converter = field.getAnnotation(xyz.wbsite.frame.excel.annotation.Converter.class); + if (field.isAnnotationPresent(${basePackage}.frame.excel.annotation.Converter.class)) { + ${basePackage}.frame.excel.annotation.Converter converter = field.getAnnotation(${basePackage}.frame.excel.annotation.Converter.class); Class target = converter.target(); try { - WColumn.setConverter((xyz.wbsite.frame.excel.converter.Converter) target.newInstance()); + WColumn.setConverter((${basePackage}.frame.excel.converter.Converter) target.newInstance()); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { @@ -349,7 +349,7 @@ public class WSheet implements Serializable, Cloneable { String value = WCell.getValue(); Method method = clazz.getMethod("set" + att, field.getType()); //获取转换器 - xyz.wbsite.frame.excel.converter.Converter converter = column.getConverter(); + ${basePackage}.frame.excel.converter.Converter converter = column.getConverter(); method.invoke(object, converter.convert(value)); } break; diff --git a/src/main/resources/modules/SpringBoot/java/frame/utils/ClassUtil.java b/src/main/resources/modules/SpringBoot/java/frame/utils/ClassUtil.java index 2b64d39f..4c2b8a04 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/utils/ClassUtil.java +++ b/src/main/resources/modules/SpringBoot/java/frame/utils/ClassUtil.java @@ -1,5 +1,4 @@ -package xyz.wbsite.frame.utils; - +package ${basePackage}.frame.utils; import java.lang.reflect.Field; import java.lang.reflect.Method; diff --git a/src/main/resources/modules/SpringBoot/java/frame/utils/StringUtil.java b/src/main/resources/modules/SpringBoot/java/frame/utils/StringUtil.java index 767dbe88..1e5f646d 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/utils/StringUtil.java +++ b/src/main/resources/modules/SpringBoot/java/frame/utils/StringUtil.java @@ -1,4 +1,4 @@ -package xyz.wbsite.frame.utils; +package ${basePackage}.frame.utils; public class StringUtil { diff --git a/src/main/resources/modules/SpringBoot/resources/static/js/ajax.js b/src/main/resources/modules/SpringBoot/resources/static/js/ajax.js index fa17d2bd..02ab8ddf 100644 --- a/src/main/resources/modules/SpringBoot/resources/static/js/ajax.js +++ b/src/main/resources/modules/SpringBoot/resources/static/js/ajax.js @@ -1,28 +1,47 @@ -//创建axios实例 -instance = axios.create({ +jsonService = axios.create({ method: 'post', timeout: 30000, baseURL: '/ajax', headers: {'Content-Type': 'application/json;charset=UTF-8'}, }); +downloadService = axios.create({ + method: 'post', + timeout: 30000, + baseURL: '/ajax', + responseType: 'blob', + headers: {'Content-Type': 'application/json;charset=UTF-8'}, +}); +uploadService = axios.create({ + method: 'post', + timeout: 30000, + baseURL: '/ajax', + headers: {'Content-Type': 'multipart/form-data'}, + onUploadProgress: function (progressEvent) { + var complete = (progressEvent.loaded / progressEvent.total * 100 | 0) + '%' + nav.tip.show("上传中(" + complete + ")") + }, +}); -// 添加请求拦截器 -instance.interceptors.request.use(function (config) { +// 添加JSON请求拦截器 +jsonService.interceptors.request.use(function (config) { // 在发送请求之前做些什么 nav.bar.show(); - if (config.url == '/upload') { - nav.tip.show("上传中 ..."); - } else { - nav.tip.show(); - } + nav.tip.show(); + return config; +}, function (error) { + return Promise.reject(error); +}); +uploadService.interceptors.request.use(function (config) { + // 在发送请求之前做些什么 + nav.bar.show(); + nav.tip.show("上传中 ..."); return config; }, function (error) { - // 对请求错误做些什么 return Promise.reject(error); }); -// 添加响应拦截器 -instance.interceptors.response.use(function (response) { +// 添加JSON响应拦截器 +jsonService.interceptors.response.use(function (response) { // 对响应数据做点什么 nav.tip.close(); try {//确保服务器正确返回Json @@ -32,65 +51,107 @@ instance.interceptors.response.use(function (response) { nav.bar.finish(); }catch (e){ nav.bar.error(); - response.data = {errors: [{message: '服务器错误'}]}; + response.data = {errors: [{message: '服务器响应错误'}]}; } return response; }, function (error) { - // 对响应错误做点什么,保准化返回结果 + // 对响应错误做点什么,并返回错误结果 nav.tip.close(); nav.bar.error(); const rsp = {errors: []}; if (!error.response) { rsp.errors.push({message: error.message}); } else { - switch (error.response.status) { - case 401: - rsp.errors.push({message: "未授权,请登录(401)"}); - break - case 403: - rsp.errors.push({message: "拒绝访问(403)"}); - break - case 404: - rsp.errors.push({message: "请求地址错误(404)"}); - break - case 408: - rsp.errors.push({message: "请求超时(408)"}); - break - case 500: - rsp.errors.push({message: "服务器内部错误(500)"}); - break - case 501: - rsp.errors.push({message: "服务未实现(501)"}); - break - default: - rsp.errors.push({message: "请求错误(" + error.response.status + ")"}); - break + rsp.errors.push(handleError(error.response.status)); + } + return Promise.reject(rsp); +}); +// 添加Upload响应拦截器 +uploadService.interceptors.response.use(function (response) { + // 对响应数据做点什么 + nav.tip.close(); + try {//确保服务器正确返回Json + if(response.data.errors.length > 0){ + console.error(response.data.errors) } + nav.bar.finish(); + }catch (e){ + nav.bar.error(); + response.data = {errors: [{message: '服务器响应错误'}]}; + } + return response; +}, function (error) { + // 对响应错误做点什么,并返回错误结果 + nav.tip.close(); + nav.bar.error(); + const rsp = {errors: []}; + if (!error.response) { + rsp.errors.push({message: error.message}); + } else { + rsp.errors.push(handleError(error.response.status)); } return Promise.reject(rsp); }); +function handerResponse(){ + +} +function handleError(status){ + switch (status) { + case 401: + return {message: "未授权,请登录(401)"}; + case 403: + return {message: "拒绝访问(403)"}; + case 404: + return {message: "请求地址错误(404)"}; + case 408: + return {message: "请求超时(408)"}; + case 500: + return {message: "服务器内部错误(500)"}; + case 501: + return {message: "服务未实现(501)"}; + default: + return {message: "请求错误(" + error.response.status + ")"}; + } +} jsonRequest = function (data) { - return instance.request(data) + return jsonService.request(data) .then(function (response) { return Promise.resolve(response.data); }, function (response) { return Promise.resolve(response); }) }; -fileRequest = function (config) { - return instance.request({ - url: '/upload', - data: config.data, - headers: {'Content-Type': 'multipart/form-data'}, - onUploadProgress: function (progressEvent) { - var complete = (progressEvent.loaded / progressEvent.total * 100 | 0) + '%' - nav.tip.show("上传中(" + complete + ")") - } - }).then(function (response) { - return Promise.resolve(response.data); - }, function (response) { - return Promise.resolve(response); - }) +upRequest = function (data) { + data.url='/upload'; + return uploadService.request(data) + .then(function (response) { + return Promise.resolve(response.data); + }, function (response) { + return Promise.resolve(response); + }) +}; +downRequest = function (data) { + return downloadService.request(data) + .then(function (response) { + if (!response.data) { + return Promise.resolve({errors: [{message: '下载错误'}]}); + } + // 获取响应header中文件信息 + var dis = response.headers['content-disposition']; + // 正则匹配文件名 + var fileName = dis.match(/filename="(.*\..*)"/)[1]; + // 模拟下载 + var url = window.URL.createObjectURL(new Blob([response.data])); + var link = document.createElement('a') + link.style.display = 'none'; + link.href = url; + link.setAttribute('download', fileName) + document.body.appendChild(link) + link.click(); + return Promise.resolve({errors: []}); + }, function (response) { + return Promise.resolve(response); + }) }; window.ajax = { authLogin: function (data) { @@ -102,7 +163,7 @@ window.ajax = { fileUpload: function (file) { var fd = new FormData(); fd.append("file", file); - return fileRequest({ + return upRequest({ data: fd }) }, @@ -142,6 +203,12 @@ window.ajax = { data: JSON.stringify(data), }) }, + dictTemplate: function (data) { + return downRequest({ + url: "/system/Dict/template", + data: JSON.stringify(data), + }) + }, dictItemCreate: function (data) { return jsonRequest({ url: "/system/DictItem/create", diff --git a/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/dict.ftl b/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/dict.ftl index d1c431ae..d0fa52f4 100644 --- a/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/dict.ftl +++ b/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/dict.ftl @@ -59,7 +59,7 @@ - + @@ -340,6 +340,13 @@ }.bind(this)); }.bind(this)); break; + case "template": + ajax.dictTemplate({}).then(function (response) { + if (response.errors.length > 0) { + nav.e(response.errors[0].message); + } + }.bind(this)); + break } } }, diff --git a/src/main/resources/templates/screen/system/dict.ftl b/src/main/resources/templates/screen/system/dict.ftl index fac77938..d1c431ae 100644 --- a/src/main/resources/templates/screen/system/dict.ftl +++ b/src/main/resources/templates/screen/system/dict.ftl @@ -24,8 +24,8 @@ - 新增 - + 新增 + 导出 @@ -58,8 +58,18 @@ - - + + + + + + + + + + + + @@ -131,12 +141,13 @@ diff --git a/src/main/resources/templates/screen/system/dictItem.ftl b/src/main/resources/templates/screen/system/dictItem.ftl index 17e2d490..75297dc7 100644 --- a/src/main/resources/templates/screen/system/dictItem.ftl +++ b/src/main/resources/templates/screen/system/dictItem.ftl @@ -28,6 +28,7 @@ 新增 + 导出 @@ -55,8 +56,18 @@ - - + + + + + + + + + + + + @@ -126,11 +137,13 @@ diff --git a/src/main/resources/templates/screen/user/user1.ftl b/src/main/resources/templates/screen/user/user1.ftl deleted file mode 100644 index 4ad961d8..00000000 --- a/src/main/resources/templates/screen/user/user1.ftl +++ /dev/null @@ -1,381 +0,0 @@ -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - 搜索 - 重置 - - - - - - - - 新增 - - 导出 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 取 消 - 保存 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -