From e0f06eb14f68486c4ee74fa99eff2cfada36b274 Mon Sep 17 00:00:00 2001 From: wangbing <1919101440@qq.com> Date: Tue, 19 Nov 2019 00:13:11 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manger/callable/SpringBootCallable.java | 1 + .../SpringBoot/java/action/ajax/Ajax.java | 59 +++++++-------- .../java/action/ajax/system/DictAjax.java | 52 +++++-------- .../SpringBoot/java/frame/excel/WColumn.java | 10 --- .../SpringBoot/java/frame/excel/WSheet.java | 66 ++++++++++------- .../java/frame/utils/ClassUtil.java | 73 +++++-------------- .../SpringBoot/java/frame/utils/Message.java | 1 - .../java/frame/utils/ResponseUtil.java | 42 +++++++++++ .../resources/templates/control/nav.ftl | 21 +++--- .../resources/templates/screen/module/mgr.ftl | 12 +-- .../templates/screen/module/system/dict.ftl | 11 ++- .../screen/module/system/dictItem.ftl | 11 ++- 12 files changed, 176 insertions(+), 183 deletions(-) create mode 100644 src/main/resources/modules/SpringBoot/java/frame/utils/ResponseUtil.java diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java index 86d54ee7..39dd321c 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java @@ -643,6 +643,7 @@ public class SpringBootCallable implements Callable { freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "MapperUtil.java"), option + "/java/frame/utils/MapperUtil.java", ctx); freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "MD5Util.java"), option + "/java/frame/utils/MD5Util.java", ctx); freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "ProcessUtil.java"), option + "/java/frame/utils/ProcessUtil.java", ctx); + freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "ResponseUtil.java"), option + "/java/frame/utils/ResponseUtil.java", ctx); freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "RSAUtil.java"), option + "/java/frame/utils/RSAUtil.java", ctx); freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "StringUtil.java"), option + "/java/frame/utils/StringUtil.java", ctx); freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "ValidationUtil.java"), option + "/java/frame/utils/ValidationUtil.java", ctx); diff --git a/src/main/resources/modules/SpringBoot/java/action/ajax/Ajax.java b/src/main/resources/modules/SpringBoot/java/action/ajax/Ajax.java index 7dffc577..b95b1fbe 100644 --- a/src/main/resources/modules/SpringBoot/java/action/ajax/Ajax.java +++ b/src/main/resources/modules/SpringBoot/java/action/ajax/Ajax.java @@ -2,10 +2,21 @@ package ${basePackage}.action.ajax.${module}; import ${basePackage}.frame.auth.LocalData; import ${basePackage}.frame.utils.MapperUtil; +import ${basePackage}.frame.utils.ResponseUtil; import ${basePackage}.module.${module}.mgr.${table.getCName()}Manager; +import ${basePackage}.module.${module}.ent.${table.getCName()}; import ${basePackage}.module.${module}.req.*; import ${basePackage}.module.${module}.rsp.*; +import ${basePackage}.frame.base.BaseResponse; +import ${basePackage}.frame.base.ErrorType; +import ${basePackage}.frame.excel.WSheet; +import ${basePackage}.frame.excel.exception.ReadErrorException; +import ${basePackage}.frame.excel.exception.TemplateNotMatchException; +import com.fasterxml.jackson.core.TreeNode; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; public class ${table.getCName()}Ajax{ @@ -13,93 +24,83 @@ public class ${table.getCName()}Ajax{ private ${table.getCName()}Manager ${table.getFName()}Manager; <#if table.getCreate()> - public ${table.getCName()}CreateResponse create(String jsonParam) { + public ${table.getCName()}CreateResponse create(TreeNode jsonParam) { ${table.getCName()}CreateRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}CreateRequest.class); return ${table.getFName()}Manager.create(request, LocalData.getToken()); } <#if table.getDelete()> - public ${table.getCName()}DeleteResponse delete(String jsonParam) { + public ${table.getCName()}DeleteResponse delete(TreeNode jsonParam) { ${table.getCName()}DeleteRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}DeleteRequest.class); return ${table.getFName()}Manager.delete(request, LocalData.getToken()); } <#if table.getUpdate()> - public ${table.getCName()}UpdateResponse update(String jsonParam) { + public ${table.getCName()}UpdateResponse update(TreeNode jsonParam) { ${table.getCName()}UpdateRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}UpdateRequest.class); return ${table.getFName()}Manager.update(request, LocalData.getToken()); } <#if table.getFind()> - public ${table.getCName()}FindResponse find(String jsonParam) { + public ${table.getCName()}FindResponse find(TreeNode jsonParam) { ${table.getCName()}FindRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}FindRequest.class); return ${table.getFName()}Manager.find(request, LocalData.getToken()); } <#if table.getGet()> - public ${table.getCName()}GetResponse get(String jsonParam) { + public ${table.getCName()}GetResponse get(TreeNode jsonParam) { ${table.getCName()}GetRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}GetRequest.class); return ${table.getFName()}Manager.get(request, LocalData.getToken()); } <#if table.getSearch()> - public ${table.getCName()}SearchResponse search(String jsonParam) { + public ${table.getCName()}SearchResponse search(TreeNode jsonParam) { ${table.getCName()}SearchRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}SearchRequest.class); return ${table.getFName()}Manager.search(request, LocalData.getToken()); } <#if table.getGetAll()> - public ${table.getCName()}GetAllResponse getAll(String jsonParam) { + public ${table.getCName()}GetAllResponse getAll(TreeNode jsonParam) { ${table.getCName()}GetAllRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}GetAllRequest.class); return ${table.getFName()}Manager.getAll(request, LocalData.getToken()); } <#if table.getHtml()> - public Object template(){ - try { - WSheet sheet = new WSheet<>(DictItemCreateRequest.class); - byte[] bytes = sheet.getBytes(); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); - headers.setContentDispositionFormData("attachment", URLEncoder.encode(sheet.getName() + ".xlsx","utf-8")); - return new ResponseEntity<>(bytes, headers, HttpStatus.OK); - } catch (IOException e) { - BaseResponse baseResponse = new BaseResponse(); - baseResponse.addError(ErrorType.BUSINESS_ERROR, ""); - return baseResponse; + return ResponseUtil.apply(new WSheet<>(${table.getCName()}.class)); + } + + public Object exports(TreeNode jsonParam) { + ${table.getCName()}FindRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}FindRequest.class); + ${table.getCName()}FindResponse response = ${table.getFName()}Manager.find(request, LocalData.getToken()); + if (response.hasError()) { + return response; } + return ResponseUtil.apply(new WSheet<>(response.getResult())); } public Object imports(MultipartFile file) { BaseResponse baseResponse = new BaseResponse(); try { - byte[] bytes = file.getBytes(); - - WSheet sheet = new WSheet<>(bytes, DictCreateRequest.class); + WSheet<${table.getCName()}> sheet = new WSheet<>(file.getBytes(), ${table.getCName()}.class); if (sheet.hasError()) { - byte[] sheetBytes = sheet.getBytes(true); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); - headers.setContentDispositionFormData("attachment", URLEncoder.encode(sheet.getName() + "-err.xlsx","utf-8")); - return new ResponseEntity<>(sheetBytes, headers, HttpStatus.OK); + return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-err.xlsx"); } else { return baseResponse; } } catch (IOException e) { baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); - } catch (TemplateNotMatchException | ReadErrorException e) { + } catch (TemplateNotMatchException | ReadErrorException e) { baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); } - return baseResponse; } 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 7978c97b..060afd93 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,25 +1,22 @@ package ${basePackage}.action.ajax.system; +import com.fasterxml.jackson.core.TreeNode; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.multipart.MultipartFile; import ${basePackage}.frame.auth.LocalData; +import ${basePackage}.frame.base.BaseResponse; +import ${basePackage}.frame.base.ErrorType; import ${basePackage}.frame.excel.WSheet; +import ${basePackage}.frame.excel.exception.ReadErrorException; +import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.utils.MapperUtil; +import ${basePackage}.frame.utils.ResponseUtil; +import ${basePackage}.module.system.ent.Dict; import ${basePackage}.module.system.mgr.DictManager; import ${basePackage}.module.system.req.*; import ${basePackage}.module.system.rsp.*; -import ${basePackage}.frame.base.BaseResponse; -import ${basePackage}.frame.base.ErrorType; -import ${basePackage}.frame.excel.exception.ReadErrorException; -import ${basePackage}.frame.excel.exception.TemplateNotMatchException; -import org.springframework.web.multipart.MultipartFile; -import com.fasterxml.jackson.core.TreeNode; -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; import java.io.IOException; -import java.net.URLEncoder; public class DictAjax { @@ -57,33 +54,25 @@ public class DictAjax { } public Object template(){ - try { - WSheet sheet = new WSheet<>(DictCreateRequest.class); - byte[] bytes = sheet.getBytes(); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); - headers.setContentDispositionFormData("attachment", URLEncoder.encode(sheet.getName() + ".xlsx","utf-8")); - return new ResponseEntity<>(bytes, headers, HttpStatus.OK); - } catch (IOException e) { - BaseResponse baseResponse = new BaseResponse(); - baseResponse.addError(ErrorType.BUSINESS_ERROR, ""); - return baseResponse; + return ResponseUtil.apply(new WSheet<>(Dict.class)); + } + + public Object exports(TreeNode jsonParam) { + DictFindRequest request = MapperUtil.toJava(jsonParam, DictFindRequest.class); + DictFindResponse response = dictManager.find(request, LocalData.getToken()); + if (response.hasError()) { + return response; } + return ResponseUtil.apply(new WSheet<>(response.getResult())); } public Object imports(MultipartFile file) { BaseResponse baseResponse = new BaseResponse(); try { - byte[] bytes = file.getBytes(); - - WSheet sheet = new WSheet<>(bytes, DictCreateRequest.class); + WSheet sheet = new WSheet<>(file.getBytes(), Dict.class); if (sheet.hasError()) { - byte[] sheetBytes = sheet.getBytes(true); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); - headers.setContentDispositionFormData("attachment", URLEncoder.encode(sheet.getName() + "-err.xlsx","utf-8")); - return new ResponseEntity<>(sheetBytes, headers, HttpStatus.OK); + return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-err.xlsx"); } else { return baseResponse; } @@ -92,7 +81,6 @@ public class DictAjax { } catch (TemplateNotMatchException | ReadErrorException e) { baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); } - return baseResponse; } } 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 27536f4f..0e70b3d2 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/excel/WColumn.java +++ b/src/main/resources/modules/SpringBoot/java/frame/excel/WColumn.java @@ -43,7 +43,6 @@ public class WColumn implements Serializable { public WColumn() { this.name = ""; this.cellWidth = 1; - this.isHidden = false; this.isRequired = false; this.description = ""; } @@ -51,7 +50,6 @@ public class WColumn implements Serializable { public WColumn(String name) { this.name = name; this.cellWidth = 1; - this.isHidden = false; this.isRequired = false; this.description = ""; } @@ -83,14 +81,6 @@ public class WColumn implements Serializable { this.cellWidth = cellWidth; } - public boolean isHidden() { - return isHidden; - } - - public void setHidden(boolean isHidden) { - this.isHidden = isHidden; - } - public boolean isRequired() { return isRequired; } 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 7bd77420..eb6f2c38 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/excel/WSheet.java +++ b/src/main/resources/modules/SpringBoot/java/frame/excel/WSheet.java @@ -5,6 +5,7 @@ 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.LogUtil; import ${basePackage}.frame.utils.StringUtil; import ${basePackage}.frame.utils.ValidationUtil; import ${basePackage}.frame.excel.annotation.*; @@ -79,12 +80,13 @@ public class WSheet implements Serializable, Cloneable { boolean parentFirst = clazz.isAnnotationPresent(ParentFirst.class) && clazz.getAnnotation(ParentFirst.class).value(); Field[] fields = ClassUtil.getFields(clazz, parentFirst); for (Field field : fields) { - WColumn WColumn = new WColumn(); - WColumn.setField(field); if (field.isAnnotationPresent(Ignore.class) && field.getAnnotation(Ignore.class).value()) { - WColumn.setHidden(true); + continue; } + WColumn WColumn = new WColumn(); + WColumn.setField(field); + //获取列名称 if (!field.isAnnotationPresent(ColumnName.class)) { WColumn.setName(field.getName()); @@ -164,7 +166,7 @@ public class WSheet implements Serializable, Cloneable { * @throws InvocationTargetException * @throws IllegalAccessException */ - public WSheet(List list) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { + public WSheet(List list) { if (list == null || list.size() == 0) { throw new RuntimeException("不允许传入空的列表"); } @@ -185,14 +187,24 @@ public class WSheet implements Serializable, Cloneable { method = t.getClass().getMethod("get" + att); } catch (NoSuchMethodException e) { // 尝试获取is方法,工具生成布尔值可能是is而不是get - method = t.getClass().getMethod("is" + att); + try { + method = t.getClass().getMethod("is" + att); + } catch (NoSuchMethodException e1) { + LogUtil.w(field.getName()+"can not find get method"); + } } - Object value = method.invoke(t); - if (null == value) { - row.put(column.getName(), new WCell()); - } else { - String string = column.getConverter().string(value); - row.put(column.getName(), new WCell(string)); + try { + Object value = method.invoke(t); + if (null == value) { + row.put(column.getName(), new WCell()); + } else { + String string = column.getConverter().string(value); + row.put(column.getName(), new WCell(string)); + } + } catch (IllegalAccessException e) { + LogUtil.w( "can not invoke get method!"); + } catch (InvocationTargetException e) { + LogUtil.w(method.getName() + " unexpected exception!"); } } this.rowList.add(row); @@ -210,6 +222,10 @@ public class WSheet implements Serializable, Cloneable { * 2:输入流关闭出错;
*/ public WSheet(byte[] bytes, Class clazz) throws TemplateNotMatchException, ReadErrorException { + this(bytes, clazz, null); + } + + public WSheet(byte[] bytes, Class clazz, Validator validator) throws TemplateNotMatchException, ReadErrorException { Workbook workbook = null; InputStream is = null; boolean flag; @@ -301,6 +317,7 @@ public class WSheet implements Serializable, Cloneable { try { T t = transferOneObject(clazz, i); List validate = ValidationUtil.validate(t); + validate.addAll(validator != null ? validator.validate(t) : null); if (validate.size() > 0) { for (String s : validate) { row.addError(s); @@ -335,11 +352,6 @@ public class WSheet implements Serializable, Cloneable { } for (int j = 0; j < this.columnList.size(); j++) { - WColumn wColumn = this.columnList.get(0); - if (wColumn.isHidden()) { - continue; - } - String key = this.columnList.get(j).getName(); for (WColumn column : columnList) { @@ -458,21 +470,19 @@ public class WSheet implements Serializable, Cloneable { * @return 字节流信息 * @throws IOException */ - public byte[] getBytes() throws IOException { - XSSFWorkbook workbook = getExcel(false); - if (workbook != null) { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - workbook.write(outputStream); - return outputStream.toByteArray(); - } - return null; + public byte[] getBytes() { + return getBytes(false); } - public byte[] getBytes(boolean checkResult) throws IOException { + public byte[] getBytes(boolean checkResult) { XSSFWorkbook workbook = getExcel(checkResult); if (workbook != null) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - workbook.write(outputStream); + try { + workbook.write(outputStream); + } catch (IOException e) { + return null; + } return outputStream.toByteArray(); } return null; @@ -601,4 +611,8 @@ public class WSheet implements Serializable, Cloneable { return cell.getStringCellValue(); } } + + public interface Validator { + List validate(T t); + } } 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 4c2b8a04..5f3cdd6d 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/utils/ClassUtil.java +++ b/src/main/resources/modules/SpringBoot/java/frame/utils/ClassUtil.java @@ -5,10 +5,11 @@ import java.lang.reflect.Method; import java.util.*; /** - * Created on 2015/5/28. + * ClassUtil * - * @author 金洋 - * @version 2.1.0 + * @author wangbing + * @version 0.0.1 + * @since 2017-01-01 */ public class ClassUtil { @@ -20,31 +21,13 @@ public class ClassUtil { * @return */ public static Field[] getFields(Class clazz, boolean parentFirst) { - List returnList = new ArrayList<>(); - Set nameSet = new HashSet<>(); - Field[] fields = clazz.getDeclaredFields(); - for (Field field : fields) { - returnList.add(field); - nameSet.add(field.getName()); - } - List parentList = getParentFields(clazz.getSuperclass(), nameSet, parentFirst); if (parentFirst) { - parentList.addAll(returnList); - returnList = parentList; - } else { - returnList.addAll(parentList); - } - - fields = new Field[returnList.size()]; - - int index = 0; - for (Field field : returnList) { - fields[index++] = field; + Field[] parentFields = getParentFields(clazz.getSuperclass()); + return concat(fields, parentFields); } return fields; - } /** @@ -115,12 +98,6 @@ public class ClassUtil { return pojoClass.getMethod(getMethodName.toString(), type); } - /** - * 是不是java基础类 - * - * @param field - * @return - */ public static boolean isJavaClass(Field field) { Class fieldType = field.getType(); boolean isBaseClass = false; @@ -136,37 +113,23 @@ public class ClassUtil { return isBaseClass; } - /** - * 通过指定的类型获取所有的成员变量 - * - * @param clazz - * @return - */ public static Field[] getFields(Class clazz) { return getFields(clazz, false); } - private static List getParentFields(Class parentClazz, Set nameSet, boolean parentFirst) { - List fieldList = new ArrayList<>(); - + private static Field[] getParentFields(Class parentClazz) { if (parentClazz != null) { - Field[] parentList = parentClazz.getDeclaredFields(); - int index = 0; - for (Field field : parentList) { - int beginSize = nameSet.size(); - nameSet.add(field.getName()); - int endSize = nameSet.size(); - - if (endSize > beginSize) { - if (parentFirst) { - fieldList.add(index++, field); - } else { - fieldList.add(field); - } - } - } - fieldList.addAll(getParentFields(parentClazz.getSuperclass(), nameSet, parentFirst)); + Field[] fields = parentClazz.getDeclaredFields(); + Field[] parentFields = getParentFields(parentClazz.getSuperclass()); + return concat(fields, parentFields); } - return fieldList; + return new Field[0]; + } + + private static Field[] concat(Field[] f1, Field[] f2) { + Field[] fields = new Field[f1.length + f2.length]; + System.arraycopy(f1, 0, fields, 0, f1.length); + System.arraycopy(f2, 0, fields, f1.length, f2.length); + return fields; } } diff --git a/src/main/resources/modules/SpringBoot/java/frame/utils/Message.java b/src/main/resources/modules/SpringBoot/java/frame/utils/Message.java index f4ec02b0..da8ae842 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/utils/Message.java +++ b/src/main/resources/modules/SpringBoot/java/frame/utils/Message.java @@ -1,6 +1,5 @@ package ${basePackage}.frame.utils; - /** * Message - 基本消息类 * diff --git a/src/main/resources/modules/SpringBoot/java/frame/utils/ResponseUtil.java b/src/main/resources/modules/SpringBoot/java/frame/utils/ResponseUtil.java new file mode 100644 index 00000000..af2ee3c5 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/frame/utils/ResponseUtil.java @@ -0,0 +1,42 @@ +package ${basePackage}.frame.utils; + +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import ${basePackage}.frame.excel.WSheet; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +/** + * Base64Util + * + * @author wangbing + * @version 0.0.1 + * @since 2017-01-01 + */ +public class ResponseUtil { + + /** + * 包装ResponseEntity + * + * @param bytes 字节数组 + * @param fileName 文件名 + * @return + */ + public static ResponseEntity apply(byte[] bytes, String fileName) { + try { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); + headers.setContentDispositionFormData("attachment", URLEncoder.encode(fileName, "utf-8")); + return new ResponseEntity<>(bytes, headers, HttpStatus.OK); + } catch (UnsupportedEncodingException e) { + return null; + } + } + + public static ResponseEntity apply(WSheet sheet) { + return apply(sheet.getBytes(), sheet.getName() + ".xlsx"); + } +} diff --git a/src/main/resources/modules/SpringBoot/resources/templates/control/nav.ftl b/src/main/resources/modules/SpringBoot/resources/templates/control/nav.ftl index 8913f10f..046ac37a 100644 --- a/src/main/resources/modules/SpringBoot/resources/templates/control/nav.ftl +++ b/src/main/resources/modules/SpringBoot/resources/templates/control/nav.ftl @@ -404,21 +404,18 @@ onSelectionChange: function (select) { this.select = select; }, - excelTemplate: function () { - this.$ajax.template(this.module, this.target, {}); - }, - excelSelect: function () { + selectExcel: function () { this.$refs['excel'].dispatchEvent(new MouseEvent('click')) }, - excelImport: function (item) { + onTemplate: function () { + this.$ajax.template(this.module, this.target, {}); + }, + onImport: function (item) { const file = item.target.files[0]; - this.$ajax.imports(this.module, this.target, file).then(function (response) { - if (response.errors.length > 0) { - this.e(response.errors[0].message); - } else { - this.i("文件上传成功!"); - } - }.bind(this)) + this.$ajax.imports(this.module, this.target, file); + }, + onExport: function () { + this.$ajax.exports(this.module, this.target, this.vm); }, onSave: function () { this.$refs['form'].validate(function (valid) { diff --git a/src/main/resources/modules/SpringBoot/resources/templates/screen/module/mgr.ftl b/src/main/resources/modules/SpringBoot/resources/templates/screen/module/mgr.ftl index 7d9932ed..8fb53ee5 100644 --- a/src/main/resources/modules/SpringBoot/resources/templates/screen/module/mgr.ftl +++ b/src/main/resources/modules/SpringBoot/resources/templates/screen/module/mgr.ftl @@ -18,9 +18,9 @@ - 新增 - - 导出 + 新增 + + 导出 @@ -42,13 +42,13 @@ - + - + - + 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 40b0a2ef..15c29b1d 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 @@ -24,10 +24,9 @@ - 新增 - + 新增 - 导出 + 导出 @@ -60,13 +59,13 @@ - + - + - + diff --git a/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/dictItem.ftl b/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/dictItem.ftl index 997954db..4a61296b 100644 --- a/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/dictItem.ftl +++ b/src/main/resources/modules/SpringBoot/resources/templates/screen/module/system/dictItem.ftl @@ -27,10 +27,9 @@ - 新增 - + 新增 - 导出 + 导出 @@ -58,13 +57,13 @@ - + - + - +