From f1fed76273361a6d6ed7ed276a9cafd32677be79 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Mon, 4 Oct 2021 10:28:13 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E5=8D=87=E7=BA=A7element-ui=E5=88=B0?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=89=88=E6=9C=AC2.15.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 ++-- ruoyi-ui/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 2e1d5e075..c1d9a291c 100644 --- a/pom.xml +++ b/pom.xml @@ -21,8 +21,8 @@ 1.2.6 1.21 3.0.0 - 2.3.2 - 2.1.4 + 2.3.2 + 2.1.4 1.3.1 1.2.78 5.8.0 diff --git a/ruoyi-ui/package.json b/ruoyi-ui/package.json index c7db2d8ed..034e0642d 100644 --- a/ruoyi-ui/package.json +++ b/ruoyi-ui/package.json @@ -41,7 +41,7 @@ "clipboard": "2.0.6", "core-js": "3.8.1", "echarts": "4.9.0", - "element-ui": "2.15.5", + "element-ui": "2.15.6", "file-saver": "2.0.5", "fuse.js": "6.4.3", "highlight.js": "9.18.5", From 0b14155a75f955e553f8730447f2cf17a584fe81 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sat, 9 Oct 2021 11:42:29 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20sendGet=20=E6=97=A0?= =?UTF-8?q?=E5=8F=82=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/ruoyi/common/utils/http/HttpUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java index 200374328..c920f5b12 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java @@ -19,6 +19,7 @@ import javax.net.ssl.X509TrustManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ruoyi.common.constant.Constants; +import com.ruoyi.common.utils.StringUtils; /** * 通用http发送方法 @@ -55,7 +56,7 @@ public class HttpUtils BufferedReader in = null; try { - String urlNameString = url + "?" + param; + String urlNameString = StringUtils.isNotBlank(param) ? url + "?" + param : url; log.info("sendGet - {}", urlNameString); URL realUrl = new URL(urlNameString); URLConnection connection = realUrl.openConnection(); From 7ae47b50b850d6fd2eac4b76cfcd9c63100f5e92 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sat, 9 Oct 2021 11:43:26 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=BB=98=E8=AE=A4=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java index b9f9ac289..fa9529119 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java @@ -493,7 +493,7 @@ public class ExcelUtil */ public void importTemplateExcel(HttpServletResponse response, String sheetName) throws IOException { - importTemplateExcel(response, sheetName); + importTemplateExcel(response, sheetName, StringUtils.EMPTY); } /** From f6e477b4f539715bbbc08bf7c0c9bbb8d4208fe7 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sat, 9 Oct 2021 11:43:34 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E5=8D=87=E7=BA=A7druid=E5=88=B0=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E7=89=881.2.8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c1d9a291c..69cd0efab 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ UTF-8 1.8 3.1.1 - 1.2.6 + 1.2.8 1.21 3.0.0 2.3.2 From c4207f640b798009d81fa0d9270e88341a4d5d24 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sun, 10 Oct 2021 11:21:46 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E4=BD=BF=E7=94=A8JSONField=E5=BF=BD?= =?UTF-8?q?=E7=95=A5=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/core/domain/model/LoginUser.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java index 7b1d8966a..993ca2268 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java @@ -4,7 +4,7 @@ import java.util.Collection; import java.util.Set; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; -import com.fasterxml.jackson.annotation.JsonIgnore; +import com.alibaba.fastjson.annotation.JSONField; import com.ruoyi.common.core.domain.entity.SysUser; /** @@ -119,7 +119,7 @@ public class LoginUser implements UserDetails this.permissions = permissions; } - @JsonIgnore + @JSONField(serialize = false) @Override public String getPassword() { @@ -135,7 +135,7 @@ public class LoginUser implements UserDetails /** * 账户是否未过期,过期无法验证 */ - @JsonIgnore + @JSONField(serialize = false) @Override public boolean isAccountNonExpired() { @@ -147,7 +147,7 @@ public class LoginUser implements UserDetails * * @return */ - @JsonIgnore + @JSONField(serialize = false) @Override public boolean isAccountNonLocked() { @@ -159,7 +159,7 @@ public class LoginUser implements UserDetails * * @return */ - @JsonIgnore + @JSONField(serialize = false) @Override public boolean isCredentialsNonExpired() { @@ -171,7 +171,7 @@ public class LoginUser implements UserDetails * * @return */ - @JsonIgnore + @JSONField(serialize = false) @Override public boolean isEnabled() { From 4fdb0f48ec1f7833d37db1b995ff1b05d0310e6e Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sun, 10 Oct 2021 11:23:04 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E5=90=8C=E6=AD=A5element2.15.6=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/views/monitor/cache/index.vue | 48 ++++---- ruoyi-ui/src/views/monitor/server/index.vue | 118 ++++++++++---------- 2 files changed, 83 insertions(+), 83 deletions(-) diff --git a/ruoyi-ui/src/views/monitor/cache/index.vue b/ruoyi-ui/src/views/monitor/cache/index.vue index 36957edd2..22501dc34 100644 --- a/ruoyi-ui/src/views/monitor/cache/index.vue +++ b/ruoyi-ui/src/views/monitor/cache/index.vue @@ -8,34 +8,34 @@ - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + +
Redis版本
{{ cache.info.redis_version }}
运行模式
{{ cache.info.redis_mode == "standalone" ? "单机" : "集群" }}
端口
{{ cache.info.tcp_port }}
客户端数
{{ cache.info.connected_clients }}
Redis版本
{{ cache.info.redis_version }}
运行模式
{{ cache.info.redis_mode == "standalone" ? "单机" : "集群" }}
端口
{{ cache.info.tcp_port }}
客户端数
{{ cache.info.connected_clients }}
运行时间(天)
{{ cache.info.uptime_in_days }}
使用内存
{{ cache.info.used_memory_human }}
使用CPU
{{ parseFloat(cache.info.used_cpu_user_children).toFixed(2) }}
内存配置
{{ cache.info.maxmemory_human }}
运行时间(天)
{{ cache.info.uptime_in_days }}
使用内存
{{ cache.info.used_memory_human }}
使用CPU
{{ parseFloat(cache.info.used_cpu_user_children).toFixed(2) }}
内存配置
{{ cache.info.maxmemory_human }}
AOF是否开启
{{ cache.info.aof_enabled == "0" ? "否" : "是" }}
RDB是否成功
{{ cache.info.rdb_last_bgsave_status }}
Key数量
{{ cache.dbSize }}
网络入口/出口
{{ cache.info.instantaneous_input_kbps }}kps/{{cache.info.instantaneous_output_kbps}}kps
AOF是否开启
{{ cache.info.aof_enabled == "0" ? "否" : "是" }}
RDB是否成功
{{ cache.info.rdb_last_bgsave_status }}
Key数量
{{ cache.dbSize }}
网络入口/出口
{{ cache.info.instantaneous_input_kbps }}kps/{{cache.info.instantaneous_output_kbps}}kps
diff --git a/ruoyi-ui/src/views/monitor/server/index.vue b/ruoyi-ui/src/views/monitor/server/index.vue index 367001f4d..503bf9b61 100644 --- a/ruoyi-ui/src/views/monitor/server/index.vue +++ b/ruoyi-ui/src/views/monitor/server/index.vue @@ -8,26 +8,26 @@ - - + + - - + + - - + + - - + + - - + +
属性
属性
核心数
{{ server.cpu.cpuNum }}
核心数
{{ server.cpu.cpuNum }}
用户使用率
{{ server.cpu.used }}%
用户使用率
{{ server.cpu.used }}%
系统使用率
{{ server.cpu.sys }}%
系统使用率
{{ server.cpu.sys }}%
当前空闲率
{{ server.cpu.free }}%
当前空闲率
{{ server.cpu.free }}%
@@ -42,31 +42,31 @@ - - - + + + - - - + + + - - - + + + - - - + + + - - - + + +
属性
内存
JVM
属性
内存
JVM
总内存
{{ server.mem.total }}G
{{ server.jvm.total }}M
总内存
{{ server.mem.total }}G
{{ server.jvm.total }}M
已用内存
{{ server.mem.used}}G
{{ server.jvm.used}}M
已用内存
{{ server.mem.used}}G
{{ server.jvm.used}}M
剩余内存
{{ server.mem.free }}G
{{ server.jvm.free }}M
剩余内存
{{ server.mem.free }}G
{{ server.jvm.free }}M
使用率
{{ server.mem.usage }}%
{{ server.jvm.usage }}%
使用率
{{ server.mem.usage }}%
{{ server.jvm.usage }}%
@@ -83,16 +83,16 @@ - - - - + + + + - - - - + + + +
服务器名称
{{ server.sys.computerName }}
操作系统
{{ server.sys.osName }}
服务器名称
{{ server.sys.computerName }}
操作系统
{{ server.sys.osName }}
服务器IP
{{ server.sys.computerIp }}
系统架构
{{ server.sys.osArch }}
服务器IP
{{ server.sys.computerIp }}
系统架构
{{ server.sys.osArch }}
@@ -109,24 +109,24 @@ - - - - + + + + - - - - + + + + - - + + - - + +
Java名称
{{ server.jvm.name }}
Java版本
{{ server.jvm.version }}
Java名称
{{ server.jvm.name }}
Java版本
{{ server.jvm.version }}
启动时间
{{ server.jvm.startTime }}
运行时长
{{ server.jvm.runTime }}
启动时间
{{ server.jvm.startTime }}
运行时长
{{ server.jvm.runTime }}
安装路径
{{ server.jvm.home }}
安装路径
{{ server.jvm.home }}
项目路径
{{ server.sys.userDir }}
项目路径
{{ server.sys.userDir }}
@@ -143,24 +143,24 @@ - - - - - - - + + + + + + + - - - - - - - + + + + + + +
盘符路径
文件系统
盘符类型
总大小
可用大小
已用大小
已用百分比
盘符路径
文件系统
盘符类型
总大小
可用大小
已用大小
已用百分比
{{ sysFile.dirName }}
{{ sysFile.sysTypeName }}
{{ sysFile.typeName }}
{{ sysFile.total }}
{{ sysFile.free }}
{{ sysFile.used }}
{{ sysFile.usage }}%
{{ sysFile.dirName }}
{{ sysFile.sysTypeName }}
{{ sysFile.typeName }}
{{ sysFile.total }}
{{ sysFile.free }}
{{ sysFile.used }}
{{ sysFile.usage }}%
From ae5c68368be574a12952b64b1b91808307eed310 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sun, 10 Oct 2021 11:24:16 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E5=8D=87=E7=BA=A7SpringBoot=E5=88=B0?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=89=88=E6=9C=AC2.5.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../controller/system/SysRegisterController.java | 2 +- .../ruoyi/framework/config/ResourcesConfig.java | 15 ++++++++++----- .../interceptor/RepeatSubmitInterceptor.java | 6 +++--- .../framework/web/service/SysRegisterService.java | 2 +- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 69cd0efab..5e4ec7b13 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ org.springframework.boot spring-boot-dependencies - 2.2.13.RELEASE + 2.5.5 pom import diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java index e88a2ad6e..f1552e033 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java @@ -1,13 +1,13 @@ package com.ruoyi.web.controller.system; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.model.RegisterBody; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.web.service.SysRegisterService; import com.ruoyi.system.service.ISysConfigService; diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java index 9cd523e76..24ef0dec9 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java @@ -28,10 +28,12 @@ public class ResourcesConfig implements WebMvcConfigurer public void addResourceHandlers(ResourceHandlerRegistry registry) { /** 本地文件上传路径 */ - registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**").addResourceLocations("file:" + RuoYiConfig.getProfile() + "/"); + registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**") + .addResourceLocations("file:" + RuoYiConfig.getProfile() + "/"); /** swagger配置 */ - registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/"); + registry.addResourceHandler("/swagger-ui/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/"); } /** @@ -49,17 +51,20 @@ public class ResourcesConfig implements WebMvcConfigurer @Bean public CorsFilter corsFilter() { - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = new CorsConfiguration(); config.setAllowCredentials(true); // 设置访问源地址 - config.addAllowedOrigin("*"); + config.addAllowedOriginPattern("*"); // 设置访问源请求头 config.addAllowedHeader("*"); // 设置访问源请求方法 config.addAllowedMethod("*"); - // 对接口配置跨域设置 + // 有效期 1800秒 + config.setMaxAge(1800L); + // 添加映射路径,拦截一切请求 + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", config); + // 返回新的CorsFilter return new CorsFilter(source); } } \ No newline at end of file diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java index 7b7f5a407..509e28731 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java @@ -5,7 +5,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Component; import org.springframework.web.method.HandlerMethod; -import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; +import org.springframework.web.servlet.HandlerInterceptor; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.annotation.RepeatSubmit; import com.ruoyi.common.core.domain.AjaxResult; @@ -17,7 +17,7 @@ import com.ruoyi.common.utils.ServletUtils; * @author ruoyi */ @Component -public abstract class RepeatSubmitInterceptor extends HandlerInterceptorAdapter +public abstract class RepeatSubmitInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception @@ -40,7 +40,7 @@ public abstract class RepeatSubmitInterceptor extends HandlerInterceptorAdapter } else { - return super.preHandle(request, response, handler); + return true; } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java index c7fbdc942..35a425c7d 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java @@ -2,7 +2,6 @@ package com.ruoyi.framework.web.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.entity.SysUser; @@ -12,6 +11,7 @@ import com.ruoyi.common.exception.user.CaptchaException; import com.ruoyi.common.exception.user.CaptchaExpireException; import com.ruoyi.common.utils.MessageUtils; import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.manager.AsyncManager; import com.ruoyi.framework.manager.factory.AsyncFactory; import com.ruoyi.system.service.ISysConfigService; From 8bd6296721185bf5350ac975eb6caca7c9e7b75c Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sun, 10 Oct 2021 11:25:37 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E5=8D=87=E7=BA=A7pagehelper=E5=88=B0?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=89=881.4.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5e4ec7b13..91da95425 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ 3.0.0 2.3.2 2.1.4 - 1.3.1 + 1.4.0 1.2.78 5.8.0 5.8.0 From b1e5ebab8f2d522b876a46f6a60f37227a6de1e5 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sun, 10 Oct 2021 11:26:50 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E5=8D=87=E7=BA=A7spring-boot-mybatis?= =?UTF-8?q?=E5=88=B0=E6=9C=80=E6=96=B0=E7=89=882.2.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 91da95425..91ac13cee 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ 1.21 3.0.0 2.3.2 - 2.1.4 + 2.2.0 1.4.0 1.2.78 5.8.0 From eb4376b649a0f8783e8f70406a438ad3c61b8f12 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sun, 10 Oct 2021 14:30:08 +0800 Subject: [PATCH 10/10] =?UTF-8?q?Excel=E5=AF=BC=E5=85=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?@Excels=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/utils/poi/ExcelUtil.java | 70 +++++++++---------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java index fa9529119..4169360a1 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java @@ -268,22 +268,15 @@ public class ExcelUtil } } // 有数据时才处理 得到类的所有field. - Field[] allFields = clazz.getDeclaredFields(); - // 定义一个map用于存放列的序号和field. - Map fieldsMap = new HashMap(); - for (int col = 0; col < allFields.length; col++) + List fields = this.getFields(); + Map fieldsMap = new HashMap(); + for (Object[] objects : fields) { - Field field = allFields[col]; - Excel attr = field.getAnnotation(Excel.class); - if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) + Excel attr = (Excel) objects[1]; + Integer column = cellMap.get(attr.name()); + if (column != null) { - // 设置类的私有字段属性可访问. - field.setAccessible(true); - Integer column = cellMap.get(attr.name()); - if (column != null) - { - fieldsMap.put(column, field); - } + fieldsMap.put(column, objects); } } for (int i = titleNum + 1; i <= rows; i++) @@ -296,14 +289,15 @@ public class ExcelUtil continue; } T entity = null; - for (Map.Entry entry : fieldsMap.entrySet()) + for (Map.Entry entry : fieldsMap.entrySet()) { Object val = this.getCellValue(row, entry.getKey()); // 如果不存在实例则新建. entity = (entity == null ? clazz.newInstance() : entity); // 从map中得到对应列的field. - Field field = fieldsMap.get(entry.getKey()); + Field field = (Field) entry.getValue()[0]; + Excel attr = (Excel) entry.getValue()[1]; // 取得类型,并根据对象类型设置值. Class fieldType = field.getType(); if (String.class == fieldType) @@ -363,7 +357,6 @@ public class ExcelUtil } if (StringUtils.isNotNull(fieldType)) { - Excel attr = field.getAnnotation(Excel.class); String propertyName = field.getName(); if (StringUtils.isNotEmpty(attr.targetAttr())) { @@ -610,8 +603,6 @@ public class ExcelUtil { Field field = (Field) os[0]; Excel excel = (Excel) os[1]; - // 设置实体类私有属性可访问 - field.setAccessible(true); this.addCell(excel, row, vo, field, column++); } } @@ -1164,7 +1155,17 @@ public class ExcelUtil */ private void createExcelField() { - this.fields = new ArrayList(); + this.fields = getFields(); + this.fields = this.fields.stream().sorted(Comparator.comparing(objects -> ((Excel) objects[1]).sort())).collect(Collectors.toList()); + this.maxHeight = getRowHeight(); + } + + /** + * 获取字段注解信息 + */ + public List getFields() + { + List fields = new ArrayList(); List tempFields = new ArrayList<>(); tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields())); tempFields.addAll(Arrays.asList(clazz.getDeclaredFields())); @@ -1173,7 +1174,12 @@ public class ExcelUtil // 单注解 if (field.isAnnotationPresent(Excel.class)) { - putToField(field, field.getAnnotation(Excel.class)); + Excel attr = field.getAnnotation(Excel.class); + if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) + { + field.setAccessible(true); + fields.add(new Object[] { field, attr }); + } } // 多注解 @@ -1181,14 +1187,17 @@ public class ExcelUtil { Excels attrs = field.getAnnotation(Excels.class); Excel[] excels = attrs.value(); - for (Excel excel : excels) + for (Excel attr : excels) { - putToField(field, excel); + if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) + { + field.setAccessible(true); + fields.add(new Object[] { field, attr }); + } } } } - this.fields = this.fields.stream().sorted(Comparator.comparing(objects -> ((Excel) objects[1]).sort())).collect(Collectors.toList()); - this.maxHeight = getRowHeight(); + return fields; } /** @@ -1205,17 +1214,6 @@ public class ExcelUtil return (short) (maxHeight * 20); } - /** - * 放到字段集合中 - */ - private void putToField(Field field, Excel attr) - { - if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) - { - this.fields.add(new Object[] { field, attr }); - } - } - /** * 创建一个工作簿 */