From 39b69dea202da7bf7d77b0265e50b583810946f9 Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Tue, 8 Oct 2019 23:30:01 +0800 Subject: [PATCH 01/21] =?UTF-8?q?:cn:=20=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=99=A8=E5=8F=AF=E8=87=AA=E5=AE=9A=E4=B9=89=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=94=9F=E6=88=90=E5=93=AA=E4=BA=9B=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springbootplus/test/CodeGenerator.java | 89 ++++++++++++++----- 1 file changed, 65 insertions(+), 24 deletions(-) diff --git a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java index 3e7e15e3..89e53c56 100644 --- a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java +++ b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java @@ -60,13 +60,22 @@ public class CodeGenerator { // 作者 private static final String AUTHOR = "geekidea"; // 生成的表名称 - private static final String TABLE_NAME = "sys_user"; + private static final String TABLE_NAME = "sys_log"; // 主键数据库列名称 - private static final String PK_ID_COLUMN_NAME = "id"; + private static final String PK_ID_COLUMN_NAME = "log_id"; // 代码生成策略 true:All/false:SIMPLE private static final boolean GENERATOR_STRATEGY = true; // 分页列表查询是否排序 true:有排序参数/false:无 private static final boolean PAGE_LIST_ORDER = false; + // 生成文件配置,是否生成entity/controller/service/serviceImpl/mapper/xml + private static final boolean GENERATOR_ENTITY = true; + private static final boolean GENERATOR_CONTROLLER = true; + private static final boolean GENERATOR_SERVICE = true; + private static final boolean GENERATOR_SERVICE_IMPL = true; + private static final boolean GENERATOR_MAPPER = true; + private static final boolean GENERATOR_MAPPER_XML = true; + private static final boolean GENERATOR_QUERY_PARAM = true; + private static final boolean GENERATOR_QUERY_VO = true; // ############################ 配置部分 end ############################ @@ -155,35 +164,67 @@ public void initMap() { } }; List focList = new ArrayList<>(); - focList.add(new FileOutConfig("/templates/mapper.xml.vm") { - @Override - public String outputFile(TableInfo tableInfo) { - // 自定义输入文件名称 - return projectPath + "/src/main/resources/mapper/" + pc.getModuleName() - + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML; - } - }); + + // 生成mapper xml + if (GENERATOR_MAPPER_XML) { + focList.add(new FileOutConfig("/templates/mapper.xml.vm") { + @Override + public String outputFile(TableInfo tableInfo) { + // 自定义输入文件名称 + return projectPath + "/src/main/resources/mapper/" + pc.getModuleName() + + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML; + } + }); + } // 自定义queryParam模板 - focList.add(new FileOutConfig("/templates/queryParam.java.vm") { - @Override - public String outputFile(TableInfo tableInfo) { - return projectPath + "/src/main/java/" + PROJECT_PACKAGE_PATH + "/" + pc.getModuleName() + "/web/param/" + tableInfo.getEntityName() + "QueryParam" + StringPool.DOT_JAVA; - } - }); + if (GENERATOR_QUERY_PARAM) { + focList.add(new FileOutConfig("/templates/queryParam.java.vm") { + @Override + public String outputFile(TableInfo tableInfo) { + return projectPath + "/src/main/java/" + PROJECT_PACKAGE_PATH + "/" + pc.getModuleName() + "/web/param/" + tableInfo.getEntityName() + "QueryParam" + StringPool.DOT_JAVA; + } + }); + } // 自定义queryVo模板 - focList.add(new FileOutConfig("/templates/queryVo.java.vm") { - @Override - public String outputFile(TableInfo tableInfo) { - return projectPath + "/src/main/java/" + PROJECT_PACKAGE_PATH + "/" + pc.getModuleName() + "/web/vo/" + tableInfo.getEntityName() + "QueryVo" + StringPool.DOT_JAVA; - } - }); - + if (GENERATOR_QUERY_VO) { + focList.add(new FileOutConfig("/templates/queryVo.java.vm") { + @Override + public String outputFile(TableInfo tableInfo) { + return projectPath + "/src/main/java/" + PROJECT_PACKAGE_PATH + "/" + pc.getModuleName() + "/web/vo/" + tableInfo.getEntityName() + "QueryVo" + StringPool.DOT_JAVA; + } + }); + } cfg.setFileOutConfigList(focList); mpg.setCfg(cfg); - mpg.setTemplate(new TemplateConfig().setXml(null)); + + // 模版生成配置,设置为空,表示不生成 + TemplateConfig templateConfig = new TemplateConfig(); + // xml使用自定义输出 + templateConfig.setXml(null); + // 是否生成entity + if (!GENERATOR_ENTITY) { + templateConfig.setEntity(null); + } + // 是否生成controller + if (!GENERATOR_CONTROLLER) { + templateConfig.setController(null); + } + // 是否生成service + if (!GENERATOR_SERVICE) { + templateConfig.setService(null); + } + // 是否生成serviceImpl + if (!GENERATOR_SERVICE_IMPL) { + templateConfig.setServiceImpl(null); + } + // 是否生成mapper + if (!GENERATOR_MAPPER) { + templateConfig.setMapper(null); + } + mpg.setTemplate(templateConfig); // 策略配置 StrategyConfig strategy = new StrategyConfig(); From 6b561070316ba1f305dd98d38d62126d835b898e Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Wed, 9 Oct 2019 00:57:44 +0800 Subject: [PATCH 02/21] =?UTF-8?q?:cn:=20=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=99=A8=E5=8F=AF=E8=87=AA=E5=AE=9A=E4=B9=89=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=94=9F=E6=88=90=E5=93=AA=E4=BA=9B=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/web/filter/CrossDomainFilter.java | 4 + .../core/SpringBootPlusConfig.java | 77 +++++++++++-------- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/main/java/io/geekidea/springbootplus/common/web/filter/CrossDomainFilter.java b/src/main/java/io/geekidea/springbootplus/common/web/filter/CrossDomainFilter.java index 431a6772..1cc5c4b1 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/filter/CrossDomainFilter.java +++ b/src/main/java/io/geekidea/springbootplus/common/web/filter/CrossDomainFilter.java @@ -50,6 +50,10 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo httpServletResponse.setHeader("Access-Control-Expose-Headers", "*"); HttpServletRequest request = (HttpServletRequest) servletRequest; + System.out.println("CrossDomainFilter..."); + System.out.println(request.getRequestURL()); + System.out.println(); + String method = request.getMethod(); if ("OPTIONS".equals(method)){ HttpServletResponse response = (HttpServletResponse) servletResponse; diff --git a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusConfig.java b/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusConfig.java index 10bf6b82..97659d4b 100644 --- a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusConfig.java @@ -16,8 +16,6 @@ package io.geekidea.springbootplus.core; import io.geekidea.springbootplus.common.aop.LogAop; -import io.geekidea.springbootplus.common.web.filter.CrossDomainFilter; -import io.geekidea.springbootplus.common.web.filter.RequestPathFilter; import io.geekidea.springbootplus.common.web.interceptor.PermissionInterceptor; import io.geekidea.springbootplus.resource.web.interceptor.DownloadInterceptor; import io.geekidea.springbootplus.resource.web.interceptor.ResourceInterceptor; @@ -27,9 +25,12 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.Order; +import org.springframework.core.Ordered; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; -import javax.servlet.Filter; +import java.util.Collections; /** * spring-boot-plus配置 @@ -42,36 +43,52 @@ @EnableConfigurationProperties({SpringBootPlusProperties.class}) public class SpringBootPlusConfig { - @Bean - public Filter crossDomainFilter(){ - return new CrossDomainFilter(); - } +// @Bean +// public Filter crossDomainFilter(){ +// return new CrossDomainFilter(); +// } +// +// @Bean +// public Filter requestPathFilter(){ +// return new RequestPathFilter(); +// } - @Bean - public Filter requestPathFilter(){ - return new RequestPathFilter(); - } +// @Bean +// @Order(1) +// public FilterRegistrationBean requestPathFilterBean(SpringBootPlusProperties springBootPlusProperties) { +// SpringBootPlusFilterConfig.FilterConfig filterConfig = springBootPlusProperties.getFilterConfig().getRequestPathConfig(); +// FilterRegistrationBean registration = new FilterRegistrationBean(); +// registration.setFilter(requestPathFilter()); +// registration.addUrlPatterns(filterConfig.getIncludePaths()); +// registration.setEnabled(filterConfig.isEnabled()); +// return registration; +// } +// +// @Bean +// public FilterRegistrationBean crossDomainFilterBean(SpringBootPlusProperties springBootPlusProperties) { +// SpringBootPlusFilterConfig.FilterConfig filterConfig = springBootPlusProperties.getFilterConfig().getCrossDomainConfig(); +// FilterRegistrationBean registration = new FilterRegistrationBean(); +// registration.setFilter(crossDomainFilter()); +// registration.addUrlPatterns(filterConfig.getIncludePaths()); +// registration.setEnabled(filterConfig.isEnabled()); +// registration.setOrder(Ordered.HIGHEST_PRECEDENCE); +// return registration; +// } - @Bean - @Order(1) - public FilterRegistrationBean requestPathFilterBean(SpringBootPlusProperties springBootPlusProperties) { - SpringBootPlusFilterConfig.FilterConfig filterConfig = springBootPlusProperties.getFilterConfig().getRequestPathConfig(); - FilterRegistrationBean registration = new FilterRegistrationBean(); - registration.setFilter(requestPathFilter()); - registration.addUrlPatterns(filterConfig.getIncludePaths()); - registration.setEnabled(filterConfig.isEnabled()); - return registration; - } @Bean - @Order(2) - public FilterRegistrationBean crossDomainFilterBean(SpringBootPlusProperties springBootPlusProperties) { - SpringBootPlusFilterConfig.FilterConfig filterConfig = springBootPlusProperties.getFilterConfig().getCrossDomainConfig(); - FilterRegistrationBean registration = new FilterRegistrationBean(); - registration.setFilter(crossDomainFilter()); - registration.addUrlPatterns(filterConfig.getIncludePaths()); - registration.setEnabled(filterConfig.isEnabled()); - return registration; + public FilterRegistrationBean corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration corsConfiguration = new CorsConfiguration(); + corsConfiguration.setAllowCredentials(true); + corsConfiguration.setAllowedOrigins(Collections.singletonList(CorsConfiguration.ALL)); + corsConfiguration.setAllowedHeaders(Collections.singletonList(CorsConfiguration.ALL)); + corsConfiguration.setAllowedMethods(Collections.singletonList(CorsConfiguration.ALL)); + corsConfiguration.addExposedHeader("Authorization"); + source.registerCorsConfiguration("/**", corsConfiguration); + FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source)); + bean.setOrder(Ordered.HIGHEST_PRECEDENCE); + return bean; } /** From 0c9d98626a789b8ab1809e3d1b9757e3331620c2 Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Thu, 10 Oct 2019 15:30:38 +0800 Subject: [PATCH 03/21] =?UTF-8?q?:cn:=20=E8=B7=A8=E5=9F=9F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8Cdruid=E8=AE=BF=E9=97=AE=EF=BC=8C=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E8=B7=AF=E5=BE=84filter=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=90=8D=E7=A7=B0=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/web/filter/CrossDomainFilter.java | 77 ------------ .../common/web/filter/RequestPathFilter.java | 46 +++++--- .../interceptor/PermissionInterceptor.java | 21 ++-- .../{ => config}/SpringBootPlusConfig.java | 110 +++++++----------- .../SpringBootPlusWebMvcConfig.java | 24 ++-- .../SpringBootPlusCorsProperties.java | 72 ++++++++++++ .../SpringBootPlusFilterProperties.java} | 16 +-- .../SpringBootPlusInterceptorProperties.java} | 19 ++- .../SpringBootPlusProperties.java | 17 ++- .../web/controller/DownloadController.java | 5 +- .../web/controller/ResourceController.java | 2 +- .../web/controller/UploadController.java | 2 +- .../web/interceptor/DownloadInterceptor.java | 4 +- .../web/interceptor/ResourceInterceptor.java | 4 +- .../web/interceptor/UploadInterceptor.java | 4 +- .../shiro/cache/LoginRedisService.java | 2 +- .../shiro/config/ShiroConfig.java | 108 +++++++++++------ ...ig.java => ShiroPermissionProperties.java} | 2 +- .../shiro/config/ShiroProperties.java | 4 +- .../web/controller/HelloWorldController.java | 47 ++++++++ src/main/resources/config/application.yml | 63 +++++++--- .../springbootplus/test/PathMatcherTest.java | 36 ++++++ 22 files changed, 401 insertions(+), 284 deletions(-) delete mode 100644 src/main/java/io/geekidea/springbootplus/common/web/filter/CrossDomainFilter.java rename src/main/java/io/geekidea/springbootplus/core/{ => config}/SpringBootPlusConfig.java (53%) rename src/main/java/io/geekidea/springbootplus/core/{ => config}/SpringBootPlusWebMvcConfig.java (85%) create mode 100644 src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusCorsProperties.java rename src/main/java/io/geekidea/springbootplus/core/{SpringBootPlusFilterConfig.java => properties/SpringBootPlusFilterProperties.java} (77%) rename src/main/java/io/geekidea/springbootplus/core/{SpringBootPlusInterceptorConfig.java => properties/SpringBootPlusInterceptorProperties.java} (71%) rename src/main/java/io/geekidea/springbootplus/core/{ => properties}/SpringBootPlusProperties.java (87%) rename src/main/java/io/geekidea/springbootplus/shiro/config/{ShiroPermissionConfig.java => ShiroPermissionProperties.java} (96%) create mode 100644 src/main/java/io/geekidea/springbootplus/system/web/controller/HelloWorldController.java create mode 100644 src/test/java/io/geekidea/springbootplus/test/PathMatcherTest.java diff --git a/src/main/java/io/geekidea/springbootplus/common/web/filter/CrossDomainFilter.java b/src/main/java/io/geekidea/springbootplus/common/web/filter/CrossDomainFilter.java deleted file mode 100644 index 1cc5c4b1..00000000 --- a/src/main/java/io/geekidea/springbootplus/common/web/filter/CrossDomainFilter.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.geekidea.springbootplus.common.web.filter; - -import com.alibaba.fastjson.JSON; -import io.geekidea.springbootplus.common.api.ApiResult; -import lombok.extern.slf4j.Slf4j; - -import javax.servlet.*; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; - -/** - * 设置允许跨域 - * @author geekidea - * @date 2018-11-08 - */ -@Slf4j -public class CrossDomainFilter implements Filter { - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - } - - @Override - public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { - HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse; - httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); - httpServletResponse.setHeader("Access-Control-Allow-Methods", "*"); - httpServletResponse.setHeader("Access-Control-Allow-Headers", "*"); - httpServletResponse.setHeader("Access-Control-Request-Headers","*"); - httpServletResponse.setHeader("Access-Control-Allow-Headers", "content-type,token"); - httpServletResponse.setHeader("Access-Control-Expose-Headers", "*"); - - HttpServletRequest request = (HttpServletRequest) servletRequest; - System.out.println("CrossDomainFilter..."); - System.out.println(request.getRequestURL()); - System.out.println(); - - String method = request.getMethod(); - if ("OPTIONS".equals(method)){ - HttpServletResponse response = (HttpServletResponse) servletResponse; - response.setCharacterEncoding("UTF-8"); - PrintWriter w = response.getWriter(); - ApiResult apiResult = new ApiResult(); - apiResult.setCode(200); - apiResult.setMsg("ok..."); - w.append(JSON.toJSONString(apiResult)); - return; - } - - filterChain.doFilter(servletRequest, httpServletResponse); - - } - - @Override - public void destroy() { - - } -} diff --git a/src/main/java/io/geekidea/springbootplus/common/web/filter/RequestPathFilter.java b/src/main/java/io/geekidea/springbootplus/common/web/filter/RequestPathFilter.java index ce8dca80..7a17016e 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/filter/RequestPathFilter.java +++ b/src/main/java/io/geekidea/springbootplus/common/web/filter/RequestPathFilter.java @@ -16,31 +16,35 @@ package io.geekidea.springbootplus.common.web.filter; +import io.geekidea.springbootplus.core.properties.SpringBootPlusFilterProperties; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ArrayUtils; +import org.springframework.util.AntPathMatcher; +import org.springframework.util.PathMatcher; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +import java.util.Arrays; /** * 请求路径过滤器 + * * @author geekidea * @date 2018-11-08 */ @Slf4j public class RequestPathFilter implements Filter { - private static List excludes = new ArrayList<>(); + private static String[] excludePaths; + + private boolean isEnabled; - static { - // 控制台日志忽略spring boot admin访问路径 - excludes.add("/actuator"); - excludes.add("/instances"); - excludes.add("/logfile"); - excludes.add("/sba-settings.js"); - excludes.add("/assets/img/favicon.png"); + public RequestPathFilter(SpringBootPlusFilterProperties.FilterConfig filterConfig) { + isEnabled = filterConfig.isEnabled(); + excludePaths = filterConfig.getExcludePaths(); + log.debug("isEnabled:" + isEnabled); + log.debug("excludePaths:" + Arrays.toString(excludePaths)); } @Override @@ -50,21 +54,27 @@ public void init(FilterConfig filterConfig) throws ServletException { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + if (!isEnabled) { + chain.doFilter(request, response); + return; + } HttpServletRequest req = (HttpServletRequest) request; String path = req.getServletPath(); String url = req.getRequestURL().toString(); - + PathMatcher pathMatcher = new AntPathMatcher(); boolean isOut = true; - for (String p : excludes){ - if (path.startsWith(p)){ - isOut = false; - break; + if (ArrayUtils.isNotEmpty(excludePaths)) { + for (String pattern : excludePaths) { + if (pathMatcher.match(pattern, path)) { + isOut = false; + break; + } } } - if (isOut){ - log.debug("requestURL:"+url); + if (isOut) { + log.debug(url); } - chain.doFilter(req,response); + chain.doFilter(req, response); } @Override diff --git a/src/main/java/io/geekidea/springbootplus/common/web/interceptor/PermissionInterceptor.java b/src/main/java/io/geekidea/springbootplus/common/web/interceptor/PermissionInterceptor.java index 52d434f1..8564113e 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/interceptor/PermissionInterceptor.java +++ b/src/main/java/io/geekidea/springbootplus/common/web/interceptor/PermissionInterceptor.java @@ -25,23 +25,22 @@ /** * 权限拦截器 - * + * * @author geekidea * @since 2018-11-08 */ @Slf4j public class PermissionInterceptor extends HandlerInterceptorAdapter { - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) - throws Exception { - log.info(request.getRequestURI()); - log.info("\n\nPermissionInterceptor...\n\n"); - return true; - } + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) + throws Exception { + log.debug(request.getRequestURI()); + return true; + } - @Override - public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { - } + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { + } } \ No newline at end of file diff --git a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusConfig.java b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java similarity index 53% rename from src/main/java/io/geekidea/springbootplus/core/SpringBootPlusConfig.java rename to src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java index 97659d4b..b125a9de 100644 --- a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2019-2029 geekidea(https://github.com/geekidea) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,10 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.geekidea.springbootplus.core; +package io.geekidea.springbootplus.core.config; import io.geekidea.springbootplus.common.aop.LogAop; import io.geekidea.springbootplus.common.web.interceptor.PermissionInterceptor; +import io.geekidea.springbootplus.core.properties.SpringBootPlusCorsProperties; +import io.geekidea.springbootplus.core.properties.SpringBootPlusFilterProperties; +import io.geekidea.springbootplus.core.properties.SpringBootPlusInterceptorProperties; +import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; import io.geekidea.springbootplus.resource.web.interceptor.DownloadInterceptor; import io.geekidea.springbootplus.resource.web.interceptor.ResourceInterceptor; import io.geekidea.springbootplus.resource.web.interceptor.UploadInterceptor; @@ -30,137 +34,101 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; -import java.util.Collections; - /** * spring-boot-plus配置 + * * @author geekidea * @date 2019/8/4 * @since 1.2.0-RELEASE */ @Slf4j @Configuration -@EnableConfigurationProperties({SpringBootPlusProperties.class}) +@EnableConfigurationProperties({ + SpringBootPlusProperties.class, + SpringBootPlusCorsProperties.class, + SpringBootPlusFilterProperties.class, + SpringBootPlusInterceptorProperties.class +}) public class SpringBootPlusConfig { -// @Bean -// public Filter crossDomainFilter(){ -// return new CrossDomainFilter(); -// } -// -// @Bean -// public Filter requestPathFilter(){ -// return new RequestPathFilter(); -// } - -// @Bean -// @Order(1) -// public FilterRegistrationBean requestPathFilterBean(SpringBootPlusProperties springBootPlusProperties) { -// SpringBootPlusFilterConfig.FilterConfig filterConfig = springBootPlusProperties.getFilterConfig().getRequestPathConfig(); -// FilterRegistrationBean registration = new FilterRegistrationBean(); -// registration.setFilter(requestPathFilter()); -// registration.addUrlPatterns(filterConfig.getIncludePaths()); -// registration.setEnabled(filterConfig.isEnabled()); -// return registration; -// } -// -// @Bean -// public FilterRegistrationBean crossDomainFilterBean(SpringBootPlusProperties springBootPlusProperties) { -// SpringBootPlusFilterConfig.FilterConfig filterConfig = springBootPlusProperties.getFilterConfig().getCrossDomainConfig(); -// FilterRegistrationBean registration = new FilterRegistrationBean(); -// registration.setFilter(crossDomainFilter()); -// registration.addUrlPatterns(filterConfig.getIncludePaths()); -// registration.setEnabled(filterConfig.isEnabled()); -// registration.setOrder(Ordered.HIGHEST_PRECEDENCE); -// return registration; -// } - - + /** + * CORS跨域设置 + * + * @return + */ @Bean - public FilterRegistrationBean corsFilter() { + public FilterRegistrationBean corsFilter(SpringBootPlusCorsProperties corsProperties) { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration corsConfiguration = new CorsConfiguration(); - corsConfiguration.setAllowCredentials(true); - corsConfiguration.setAllowedOrigins(Collections.singletonList(CorsConfiguration.ALL)); - corsConfiguration.setAllowedHeaders(Collections.singletonList(CorsConfiguration.ALL)); - corsConfiguration.setAllowedMethods(Collections.singletonList(CorsConfiguration.ALL)); - corsConfiguration.addExposedHeader("Authorization"); - source.registerCorsConfiguration("/**", corsConfiguration); + // 跨域配置 + corsConfiguration.setAllowedOrigins(corsProperties.getAllowedOrigins()); + corsConfiguration.setAllowedHeaders(corsProperties.getAllowedHeaders()); + corsConfiguration.setAllowedMethods(corsProperties.getAllowedMethods()); + corsConfiguration.setAllowCredentials(corsProperties.isAllowCredentials()); + corsConfiguration.setExposedHeaders(corsProperties.getExposedHeaders()); + source.registerCorsConfiguration(corsProperties.getPath(), corsConfiguration); + FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source)); bean.setOrder(Ordered.HIGHEST_PRECEDENCE); + bean.setEnabled(corsProperties.isEnable()); return bean; } /** * 配置日志AOP + * * @param springBootPlusProperties * @return */ @Bean - public LogAop logAop(SpringBootPlusProperties springBootPlusProperties){ + public LogAop logAop(SpringBootPlusProperties springBootPlusProperties) { LogAop logAop = new LogAop(); logAop.setRequestLogFormat(springBootPlusProperties.isRequestLogFormat()); logAop.setResponseLogFormat(springBootPlusProperties.isResponseLogFormat()); - log.info("init LogAop success"); + log.debug("init LogAop success"); return logAop; } - /** - * JWT TOKEN验证拦截器 - * @return - */ -// @Bean -// public JwtInterceptor jwtInterceptor(){ -// JwtInterceptor jwtInterceptor = new JwtInterceptor(); -// return jwtInterceptor; -// } - /** * 权限拦截器 + * * @return */ @Bean - public PermissionInterceptor permissionInterceptor(){ + public PermissionInterceptor permissionInterceptor() { PermissionInterceptor permissionInterceptor = new PermissionInterceptor(); return permissionInterceptor; } - /** - * TOKEN超时拦截器 - * @return - */ -// @Bean -// public TokenTimeoutInterceptor tokenTimeoutInterceptor(){ -// TokenTimeoutInterceptor tokenTimeoutInterceptor = new TokenTimeoutInterceptor(); -// return tokenTimeoutInterceptor; -// } - /** * 上传拦截器 + * * @return */ @Bean - public UploadInterceptor uploadInterceptor(){ + public UploadInterceptor uploadInterceptor() { UploadInterceptor uploadInterceptor = new UploadInterceptor(); return uploadInterceptor; } /** * 资源拦截器 + * * @return */ @Bean - public ResourceInterceptor resourceInterceptor(){ + public ResourceInterceptor resourceInterceptor() { ResourceInterceptor resourceInterceptor = new ResourceInterceptor(); return resourceInterceptor; } /** * 下载拦截器 + * * @return */ @Bean - public DownloadInterceptor downloadInterceptor(){ + public DownloadInterceptor downloadInterceptor() { DownloadInterceptor downloadInterceptor = new DownloadInterceptor(); return downloadInterceptor; } diff --git a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusWebMvcConfig.java b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java similarity index 85% rename from src/main/java/io/geekidea/springbootplus/core/SpringBootPlusWebMvcConfig.java rename to src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java index 62d4a9a4..1933d675 100644 --- a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusWebMvcConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java @@ -14,10 +14,12 @@ * limitations under the License. */ -package io.geekidea.springbootplus.core; +package io.geekidea.springbootplus.core.config; import com.alibaba.fastjson.JSON; import io.geekidea.springbootplus.common.web.interceptor.PermissionInterceptor; +import io.geekidea.springbootplus.core.properties.SpringBootPlusInterceptorProperties; +import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; import io.geekidea.springbootplus.resource.web.interceptor.DownloadInterceptor; import io.geekidea.springbootplus.resource.web.interceptor.ResourceInterceptor; import io.geekidea.springbootplus.resource.web.interceptor.UploadInterceptor; @@ -65,31 +67,31 @@ public void init(){ @Override public void addInterceptors(InterceptorRegistry registry) { - SpringBootPlusInterceptorConfig interceptorConfig = springBootPlusProperties.getInterceptorConfig(); + SpringBootPlusInterceptorProperties interceptorConfig = springBootPlusProperties.getInterceptor(); // 上传拦截器 - if (interceptorConfig.getUploadConfig().isEnabled()){ + if (interceptorConfig.getUpload().isEnabled()){ registry.addInterceptor(uploadInterceptor) - .addPathPatterns(interceptorConfig.getUploadConfig().getIncludePaths()); + .addPathPatterns(interceptorConfig.getUpload().getIncludePaths()); } // 资源拦截器注册 - if (interceptorConfig.getResourceConfig().isEnabled()){ + if (interceptorConfig.getResource().isEnabled()){ registry.addInterceptor(resourceInterceptor) - .addPathPatterns(interceptorConfig.getResourceConfig().getIncludePaths()); + .addPathPatterns(interceptorConfig.getResource().getIncludePaths()); } // 下载拦截器注册 - if (interceptorConfig.getDownloadConfig().isEnabled()){ + if (interceptorConfig.getDownload().isEnabled()){ registry.addInterceptor(downloadInterceptor) - .addPathPatterns(interceptorConfig.getDownloadConfig().getIncludePaths()); + .addPathPatterns(interceptorConfig.getDownload().getIncludePaths()); } - if (interceptorConfig.getPermissionConfig().isEnabled()){ + if (interceptorConfig.getPermission().isEnabled()){ // 权限拦截器注册 registry.addInterceptor(permissionInterceptor) - .addPathPatterns(interceptorConfig.getPermissionConfig().getIncludePaths()) - .excludePathPatterns(interceptorConfig.getPermissionConfig().getExcludePaths()); + .addPathPatterns(interceptorConfig.getPermission().getIncludePaths()) + .excludePathPatterns(interceptorConfig.getPermission().getExcludePaths()); } } diff --git a/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusCorsProperties.java b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusCorsProperties.java new file mode 100644 index 00000000..1df26d54 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusCorsProperties.java @@ -0,0 +1,72 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.core.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.web.cors.CorsConfiguration; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * 跨域属性配置 + * + * @author geekidea + * @date 2019-10-09 + **/ +@Data +@ConfigurationProperties(prefix = "spring-boot-plus.cors") +public class SpringBootPlusCorsProperties { + + /** + * 是否启用跨域,默认启用 + */ + private boolean enable = true; + + /** + * CORS过滤的路径,默认:/** + */ + private String path = "/**"; + + /** + * 允许访问的源 + */ + private List allowedOrigins = Collections.singletonList(CorsConfiguration.ALL); + + /** + * 允许访问的请求头 + */ + private List allowedHeaders = Collections.singletonList(CorsConfiguration.ALL); + + /** + * 是否允许发送cookie + */ + private boolean allowCredentials = true; + + /** + * 允许访问的请求方式 + */ + private List allowedMethods = Collections.singletonList(CorsConfiguration.ALL); + + /** + * 允许响应的头 + */ + private List exposedHeaders = Arrays.asList("content-type", "token"); + +} diff --git a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusFilterConfig.java b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusFilterProperties.java similarity index 77% rename from src/main/java/io/geekidea/springbootplus/core/SpringBootPlusFilterConfig.java rename to src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusFilterProperties.java index 5faf5128..1fa0310a 100644 --- a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusFilterConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusFilterProperties.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package io.geekidea.springbootplus.core; +package io.geekidea.springbootplus.core.properties; import lombok.Data; -import lombok.experimental.Accessors; +import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; /** @@ -26,20 +26,14 @@ * @since 1.3.0.RELEASE **/ @Data -@Accessors(chain = true) -public class SpringBootPlusFilterConfig { +@ConfigurationProperties(prefix = "spring-boot-plus.filter") +public class SpringBootPlusFilterProperties { /** * 请求路径Filter配置 */ @NestedConfigurationProperty - private FilterConfig requestPathConfig = new FilterConfig(); - - /** - * 跨域Filter配置 - */ - @NestedConfigurationProperty - private FilterConfig crossDomainConfig = new FilterConfig(); + private FilterConfig requestPath = new FilterConfig(); @Data public static class FilterConfig { diff --git a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusInterceptorConfig.java b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusInterceptorProperties.java similarity index 71% rename from src/main/java/io/geekidea/springbootplus/core/SpringBootPlusInterceptorConfig.java rename to src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusInterceptorProperties.java index 10607188..70fda780 100644 --- a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusInterceptorConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusInterceptorProperties.java @@ -14,46 +14,43 @@ * limitations under the License. */ -package io.geekidea.springbootplus.core; +package io.geekidea.springbootplus.core.properties; import lombok.Data; -import lombok.experimental.Accessors; +import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; -import java.io.Serializable; - /** * @author geekidea * @date 2019/8/5 */ @Data -@Accessors(chain = true) -public class SpringBootPlusInterceptorConfig implements Serializable { - private static final long serialVersionUID = -2738042100246082469L; +@ConfigurationProperties(prefix = "spring-boot-plus.interceptor") +public class SpringBootPlusInterceptorProperties { /** * 权限拦截器排除路径 */ @NestedConfigurationProperty - private InterceptorConfig permissionConfig = new InterceptorConfig(); + private InterceptorConfig permission = new InterceptorConfig(); /** * 资源拦截器 */ @NestedConfigurationProperty - private InterceptorConfig resourceConfig = new InterceptorConfig(); + private InterceptorConfig resource = new InterceptorConfig(); /** * 上传拦截器 */ @NestedConfigurationProperty - private InterceptorConfig uploadConfig = new InterceptorConfig(); + private InterceptorConfig upload = new InterceptorConfig(); /** * 下载拦截器 */ @NestedConfigurationProperty - private InterceptorConfig downloadConfig = new InterceptorConfig(); + private InterceptorConfig download = new InterceptorConfig(); @Data public static class InterceptorConfig { diff --git a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusProperties.java b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusProperties.java similarity index 87% rename from src/main/java/io/geekidea/springbootplus/core/SpringBootPlusProperties.java rename to src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusProperties.java index 90143c59..7707b7d6 100644 --- a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusProperties.java +++ b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusProperties.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package io.geekidea.springbootplus.core; +package io.geekidea.springbootplus.core.properties; -import io.geekidea.springbootplus.shiro.jwt.JwtProperties; +import io.geekidea.springbootplus.core.config.SpringBootPlusWebMvcConfig; import io.geekidea.springbootplus.shiro.config.ShiroProperties; +import io.geekidea.springbootplus.shiro.jwt.JwtProperties; import lombok.Data; -import lombok.experimental.Accessors; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; @@ -32,7 +32,6 @@ * @since 1.2.0-RELEASE */ @Data -@Accessors(chain = true) @ConfigurationProperties(prefix = "spring-boot-plus") public class SpringBootPlusProperties { @@ -55,13 +54,13 @@ public class SpringBootPlusProperties { * 拦截器配置 */ @NestedConfigurationProperty - private SpringBootPlusInterceptorConfig interceptorConfig; + private SpringBootPlusInterceptorProperties interceptor; /** * 过滤器配置 */ @NestedConfigurationProperty - private SpringBootPlusFilterConfig filterConfig; + private SpringBootPlusFilterProperties filter; /** * 上传目录 @@ -107,4 +106,10 @@ public class SpringBootPlusProperties { */ private String resourceHandlers; + /** + * 跨域配置 + */ + @NestedConfigurationProperty + private SpringBootPlusCorsProperties cors = new SpringBootPlusCorsProperties(); + } diff --git a/src/main/java/io/geekidea/springbootplus/resource/web/controller/DownloadController.java b/src/main/java/io/geekidea/springbootplus/resource/web/controller/DownloadController.java index 1510b3ae..0bf03094 100644 --- a/src/main/java/io/geekidea/springbootplus/resource/web/controller/DownloadController.java +++ b/src/main/java/io/geekidea/springbootplus/resource/web/controller/DownloadController.java @@ -17,12 +17,13 @@ package io.geekidea.springbootplus.resource.web.controller; import io.geekidea.springbootplus.common.api.ApiResult; -import io.geekidea.springbootplus.core.SpringBootPlusProperties; +import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; import io.geekidea.springbootplus.util.DownloadUtil; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -46,7 +47,7 @@ public class DownloadController { /** * 下载文件 */ - @RequestMapping("/{downloadFileName}") + @GetMapping("/{downloadFileName}") @ApiOperation(value = "下载文件",notes = "下载文件",response = ApiResult.class) public void download(@PathVariable(required = true) String downloadFileName, HttpServletResponse response) throws Exception{ // 下载目录,既是上传目录 diff --git a/src/main/java/io/geekidea/springbootplus/resource/web/controller/ResourceController.java b/src/main/java/io/geekidea/springbootplus/resource/web/controller/ResourceController.java index d645ac9b..71afbe2b 100644 --- a/src/main/java/io/geekidea/springbootplus/resource/web/controller/ResourceController.java +++ b/src/main/java/io/geekidea/springbootplus/resource/web/controller/ResourceController.java @@ -17,7 +17,7 @@ package io.geekidea.springbootplus.resource.web.controller; import io.geekidea.springbootplus.common.api.ApiResult; -import io.geekidea.springbootplus.core.SpringBootPlusProperties; +import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/io/geekidea/springbootplus/resource/web/controller/UploadController.java b/src/main/java/io/geekidea/springbootplus/resource/web/controller/UploadController.java index cc18985b..702d80ec 100644 --- a/src/main/java/io/geekidea/springbootplus/resource/web/controller/UploadController.java +++ b/src/main/java/io/geekidea/springbootplus/resource/web/controller/UploadController.java @@ -18,7 +18,7 @@ import io.geekidea.springbootplus.common.api.ApiResult; import io.geekidea.springbootplus.common.web.param.IdParam; -import io.geekidea.springbootplus.core.SpringBootPlusProperties; +import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; import io.geekidea.springbootplus.system.web.vo.SysLogQueryVo; import io.geekidea.springbootplus.util.UploadUtil; import io.swagger.annotations.ApiOperation; diff --git a/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/DownloadInterceptor.java b/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/DownloadInterceptor.java index abd0daec..a51e8da3 100644 --- a/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/DownloadInterceptor.java +++ b/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/DownloadInterceptor.java @@ -17,7 +17,7 @@ package io.geekidea.springbootplus.resource.web.interceptor; import io.geekidea.springbootplus.common.api.ApiResult; -import io.geekidea.springbootplus.core.SpringBootPlusProperties; +import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; import io.geekidea.springbootplus.util.HttpServletResponseUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -52,7 +52,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons String fullUrl = request.getRequestURL().toString(); // 未启用资源访问时,返回错误消息 - if (!springBootPlusProperties.getInterceptorConfig().getDownloadConfig().isEnabled()){ + if (!springBootPlusProperties.getInterceptor().getDownload().isEnabled()){ log.error("下载已关闭,非法下载:{}",fullUrl); HttpServletResponseUtil.printJSON(response, ApiResult.fail("非法下载")); return false; diff --git a/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/ResourceInterceptor.java b/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/ResourceInterceptor.java index d5b3db8d..38b0eef1 100644 --- a/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/ResourceInterceptor.java +++ b/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/ResourceInterceptor.java @@ -17,7 +17,7 @@ package io.geekidea.springbootplus.resource.web.interceptor; import io.geekidea.springbootplus.common.api.ApiResult; -import io.geekidea.springbootplus.core.SpringBootPlusProperties; +import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; import io.geekidea.springbootplus.util.HttpServletResponseUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -52,7 +52,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons String fullUrl = request.getRequestURL().toString(); // 未启用资源访问时,返回错误消息 - if (!springBootPlusProperties.getInterceptorConfig().getResourceConfig().isEnabled()){ + if (!springBootPlusProperties.getInterceptor().getResource().isEnabled()){ log.error("资源访问已关闭,非法访问:{}",fullUrl); HttpServletResponseUtil.printJSON(response,ApiResult.fail("非法访问")); return false; diff --git a/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/UploadInterceptor.java b/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/UploadInterceptor.java index 314c2fa4..bbb99d68 100644 --- a/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/UploadInterceptor.java +++ b/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/UploadInterceptor.java @@ -17,7 +17,7 @@ package io.geekidea.springbootplus.resource.web.interceptor; import io.geekidea.springbootplus.common.api.ApiResult; -import io.geekidea.springbootplus.core.SpringBootPlusProperties; +import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; import io.geekidea.springbootplus.util.HttpServletResponseUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -51,7 +51,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons String url = request.getRequestURI(); // 访问全路径 String fullUrl = request.getRequestURL().toString(); - if (!springBootPlusProperties.getInterceptorConfig().getUploadConfig().isEnabled()){ + if (!springBootPlusProperties.getInterceptor().getUpload().isEnabled()){ log.error("上传功能已关闭,非法上传:{}",fullUrl); HttpServletResponseUtil.printJSON(response, ApiResult.fail("非法上传")); return false; diff --git a/src/main/java/io/geekidea/springbootplus/shiro/cache/LoginRedisService.java b/src/main/java/io/geekidea/springbootplus/shiro/cache/LoginRedisService.java index d0542c31..495f14de 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/cache/LoginRedisService.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/cache/LoginRedisService.java @@ -39,7 +39,7 @@ public interface LoginRedisService { void cacheLoginInfo(JwtToken jwtToken, LoginSysUserVo loginSysUserVo, boolean generate); /** - * 通过token,从缓存中获取登陆用户LoginSysUserRedisVo + * 通过用户名,从缓存中获取登陆用户LoginSysUserRedisVo * * @param username * @return diff --git a/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java b/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java index dde4d98d..fb9377a9 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java @@ -17,6 +17,8 @@ package io.geekidea.springbootplus.shiro.config; import com.alibaba.fastjson.JSON; +import io.geekidea.springbootplus.common.web.filter.RequestPathFilter; +import io.geekidea.springbootplus.core.properties.SpringBootPlusFilterProperties; import io.geekidea.springbootplus.shiro.cache.LoginRedisService; import io.geekidea.springbootplus.shiro.exception.ShiroConfigException; import io.geekidea.springbootplus.shiro.jwt.JwtCredentialsMatcher; @@ -27,7 +29,7 @@ import io.geekidea.springbootplus.util.IniUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.map.HashedMap; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; @@ -39,15 +41,13 @@ import org.apache.shiro.mgt.DefaultSubjectDAO; import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.mgt.SessionStorageEvaluator; -import org.apache.shiro.session.mgt.DefaultSessionManager; import org.apache.shiro.spring.LifecycleBeanPostProcessor; import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; import org.apache.shiro.spring.web.ShiroFilterFactoryBean; -import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition; -import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition; import org.apache.shiro.web.mgt.DefaultWebSecurityManager; import org.apache.shiro.web.mgt.DefaultWebSessionStorageEvaluator; import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -55,9 +55,7 @@ import javax.servlet.DispatcherType; import javax.servlet.Filter; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Shiro配置 @@ -70,12 +68,19 @@ **/ @Slf4j @Configuration +@EnableConfigurationProperties({ + ShiroProperties.class +}) public class ShiroConfig { /** * JWT过滤器名称 */ private static final String JWT_FILTER_NAME = "jwtFilter"; + /** + * 请求路径过滤器名称 + */ + private static final String REQUEST_PATH_FILTER_NAME = "path"; /** * Shiro过滤器名称 */ @@ -100,17 +105,6 @@ public JwtRealm jwtRealm(LoginRedisService loginRedisService) { return jwtRealm; } - /** - * 禁用session - * - * @return - */ - @Bean - public DefaultSessionManager sessionManager() { - DefaultSessionManager manager = new DefaultSessionManager(); - manager.setSessionValidationSchedulerEnabled(false); - return manager; - } @Bean public SessionStorageEvaluator sessionStorageEvaluator() { @@ -136,7 +130,6 @@ public DefaultWebSecurityManager securityManager(LoginRedisService loginRedisSer DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); securityManager.setRealm(jwtRealm(loginRedisService)); securityManager.setSubjectDAO(subjectDAO()); - securityManager.setSessionManager(sessionManager()); SecurityUtils.setSecurityManager(securityManager); return securityManager; } @@ -154,41 +147,57 @@ public DefaultWebSecurityManager securityManager(LoginRedisService loginRedisSer public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager, LoginService loginService, LoginRedisService loginRedisService, + SpringBootPlusFilterProperties filterProperties, ShiroProperties shiroProperties, JwtProperties jwtProperties) { ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); shiroFilterFactoryBean.setSecurityManager(securityManager); - Map filterMap = new HashedMap(); - filterMap.put(JWT_FILTER_NAME, new JwtFilter(loginService, loginRedisService, jwtProperties)); + Map filterMap = getFilterMap(loginService, loginRedisService, filterProperties, jwtProperties); shiroFilterFactoryBean.setFilters(filterMap); - Map filterChainMap = shiroFilterChainDefinition(shiroProperties).getFilterChainMap(); + Map filterChainMap = getFilterChainDefinitionMap(shiroProperties); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainMap); return shiroFilterFactoryBean; } + + /** + * 获取filter map + * + * @return + */ + private Map getFilterMap(LoginService loginService, + LoginRedisService loginRedisService, + SpringBootPlusFilterProperties filterProperties, + JwtProperties jwtProperties) { + Map filterMap = new LinkedHashMap(); + filterMap.put(REQUEST_PATH_FILTER_NAME, new RequestPathFilter(filterProperties.getRequestPath())); + filterMap.put(JWT_FILTER_NAME, new JwtFilter(loginService, loginRedisService, jwtProperties)); + return filterMap; + } + + /** * Shiro路径权限配置 * * @return */ - @Bean - public ShiroFilterChainDefinition shiroFilterChainDefinition(ShiroProperties shiroProperties) { - DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition(); + private Map getFilterChainDefinitionMap(ShiroProperties shiroProperties) { + Map filterChainDefinitionMap = new LinkedHashMap(); // 获取ini格式配置 String definitions = shiroProperties.getFilterChainDefinitions(); if (StringUtils.isNotBlank(definitions)) { Map section = IniUtil.parseIni(definitions); log.debug("definitions:{}", JSON.toJSONString(section)); for (Map.Entry entry : section.entrySet()) { - chainDefinition.addPathDefinition(entry.getKey(), entry.getValue()); + filterChainDefinitionMap.put(entry.getKey(), entry.getValue()); } } // 获取自定义权限路径配置集合 - List permissionConfigs = shiroProperties.getPermissionConfig(); + List permissionConfigs = shiroProperties.getPermission(); log.debug("permissionConfigs:{}", JSON.toJSONString(permissionConfigs)); if (CollectionUtils.isNotEmpty(permissionConfigs)) { - for (ShiroPermissionConfig permissionConfig : permissionConfigs) { + for (ShiroPermissionProperties permissionConfig : permissionConfigs) { String url = permissionConfig.getUrl(); String[] urls = permissionConfig.getUrls(); String permission = permissionConfig.getPermission(); @@ -200,24 +209,53 @@ public ShiroFilterChainDefinition shiroFilterChainDefinition(ShiroProperties shi } if (StringUtils.isNotBlank(url)) { - chainDefinition.addPathDefinition(url, permission); + filterChainDefinitionMap.put(url, permission); } if (ArrayUtils.isNotEmpty(urls)) { for (String string : urls) { - chainDefinition.addPathDefinition(string, permission); + filterChainDefinitionMap.put(string, permission); } } } } // 最后一个设置为JWTFilter - chainDefinition.addPathDefinition("/**", JWT_FILTER_NAME); - - Map filterChainMap = chainDefinition.getFilterChainMap(); - log.debug("filterChainMap:{}", JSON.toJSONString(filterChainMap)); + filterChainDefinitionMap.put("/**", JWT_FILTER_NAME); + log.debug("filterChainMap:{}", JSON.toJSONString(filterChainDefinitionMap)); - return chainDefinition; + // 添加默认的filter + Map newFilterChainDefinitionMap = addDefaultFilterDefinition(filterChainDefinitionMap); + return newFilterChainDefinitionMap; } + /** + * 添加默认的filter权限过滤 + * + * @param filterChainDefinitionMap + * @return + */ + private Map addDefaultFilterDefinition(Map filterChainDefinitionMap) { + if (MapUtils.isEmpty(filterChainDefinitionMap)) { + return filterChainDefinitionMap; + } + final Map map = new LinkedHashMap(); + for (Map.Entry entry : filterChainDefinitionMap.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + String definition; + if (value.contains(REQUEST_PATH_FILTER_NAME)) { + definition = value; + } else { + String[] strings = value.split(","); + List list = new ArrayList<>(); + list.addAll(Arrays.asList(strings)); + // 添加默认filter过滤 + list.add(REQUEST_PATH_FILTER_NAME); + definition = String.join(",", list); + } + map.put(key, definition); + } + return map; + } /** * ShiroFilter配置 diff --git a/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroPermissionConfig.java b/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroPermissionProperties.java similarity index 96% rename from src/main/java/io/geekidea/springbootplus/shiro/config/ShiroPermissionConfig.java rename to src/main/java/io/geekidea/springbootplus/shiro/config/ShiroPermissionProperties.java index b7717e47..cba72d52 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroPermissionConfig.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroPermissionProperties.java @@ -26,7 +26,7 @@ * @since 1.3.0.RELEASE **/ @Data -public class ShiroPermissionConfig { +public class ShiroPermissionProperties { /** * 路径 diff --git a/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroProperties.java b/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroProperties.java index 1e4ec98b..5d8b3fc5 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroProperties.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroProperties.java @@ -19,7 +19,6 @@ import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; -import org.springframework.stereotype.Component; import java.util.List; @@ -31,7 +30,6 @@ * @since 1.3.0.RELEASE **/ @Data -@Component @ConfigurationProperties(prefix = "spring-boot-plus.shiro") public class ShiroProperties { @@ -41,6 +39,6 @@ public class ShiroProperties { * 权限配置集合 */ @NestedConfigurationProperty - private List permissionConfig; + private List permission; } diff --git a/src/main/java/io/geekidea/springbootplus/system/web/controller/HelloWorldController.java b/src/main/java/io/geekidea/springbootplus/system/web/controller/HelloWorldController.java new file mode 100644 index 00000000..f3e7c15a --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/system/web/controller/HelloWorldController.java @@ -0,0 +1,47 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.system.web.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * Hello World Controller + * @author geekidea + * @date 2019-10-09 + **/ +@Slf4j +@Api("Hello World") +@RestController +@RequestMapping("/hello") +public class HelloWorldController { + + @RequestMapping(value = "/world", method = {RequestMethod.GET, RequestMethod.POST}) + @ApiOperation(value = "Hello World", notes = "Hello World", response = String.class) + public void print(HttpServletResponse response) throws IOException { + log.debug("Hello World..."); + response.getWriter().print("Hello World"); + } + +} diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 5c3e4ff9..6e4c6c87 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -1,15 +1,15 @@ # spring-boot-plus Common Config -############################# 访问路径、端口tomcat start ############################ +############################# 访问路径、端口tomcat start ############################# server: port: 8888 servlet: - context-path: /api + context-path: / tomcat: max-threads: 1000 min-spare-threads: 30 uri-encoding: UTF-8 -############################# 访问路径、端口tomcat end ############################## +############################# 访问路径、端口tomcat end ############################### ################################ spring config start ############################### @@ -39,31 +39,31 @@ spring: ############################## spring-boot-plus start ############################## spring-boot-plus: # 拦截器配置 - interceptor-config: - permission-config: + interceptor: + permission: enabled: false include-paths: /** exclude-paths: /swagger-resources/**,/api-docs/**,/v2/api-docs/**,/adminLogin,/sysLogin,/login.html,/verificationCode,/doc/**,/error/**,/docs,/resource/** - resource-config: + resource: enabled: true include-paths: ${spring-boot-plus.resource-access-patterns} - upload-config: + upload: enabled: true include-paths: /upload/** - download-config: + download: enabled: true include-paths: /download/** # 过滤器配置 - filter-config: + filter: # 请求路径Filter配置 - request-path-config: - enabled: true - include-paths: /** - # 跨域Filter配置 - cross-domain-config: + request-path: enabled: true include-paths: /** + # 排除路径,多行字符串配置 + exclude-paths: | + /actuator/**,/instances,/logfile,/sba-settings.js,/assets/img/favicon.png, + /swagger-ui.html,/swagger-resources/**,/webjars/springfox-swagger-ui/**,/v2/api-docs # 文件上传下载配置 # 上传路径配置 @@ -78,12 +78,33 @@ spring-boot-plus: allow-upload-file-extensions: jpg,png,docx,xlsx,pptx,pdf allow-download-file-extensions: jpg,png,docx,xlsx,pptx,pdf + ############################ CORS start ############################ + # CORS跨域配置,默认允许跨域 + cors: + # 是否启用跨域,默认启用 + enable: true + # CORS过滤的路径,默认:/** + path: /** + # 允许访问的源 + allowed-origins: '*' + # 允许访问的请求头 + allowed-headers: content-type,token + # 是否允许发送cookie + allow-credentials: true + # 允许访问的请求方式 + allowed-methods: OPTION,GET,POST + # 允许响应的头 + exposed-headers: content-type,token + ############################ CORS end ############################## + + ########################## Resource start ########################## # 静态资源访问配置 resource-handlers: | /static/**=classpath:/static/ /templates/**=classpath:/templates/ swagger-ui.html=classpath:/META-INF/resources/ /webjars/**=classpath:/META-INF/resources/webjars/ + ########################## Resource end ############################ ######################## Spring Shiro start ######################## shiro: @@ -92,8 +113,10 @@ spring-boot-plus: /=anon /static/**=anon /templates/**=anon + /druid/**=anon + /hello/world=anon # 权限配置 - permission-config: + permission: # 排除登陆登出相关 - urls: /login,/logout permission: anon @@ -101,7 +124,7 @@ spring-boot-plus: - urls: /static/**,/templates/** permission: anon # 排除Swagger - - urls: /docs,/swagger-ui.html, /webjars/springfox-swagger-ui/**,/swagger-resources/**,/v2/api-docs + - urls: /docs,/swagger-ui.html,/webjars/springfox-swagger-ui/**,/swagger-resources/**,/v2/api-docs permission: anon # 排除SpringBootAdmin - urls: /,/favicon.ico,/actuator/**,/instances/**,/assets/**,/sba-settings.js,/applications/** @@ -113,9 +136,13 @@ spring-boot-plus: ############################ JWT start ############################# jwt: + # token请求头名称 token-name: token + # jwt密钥 secret: 666666 + # 发行人 issuer: spring-boot-plus + # 观众 audience: web # 默认过期时间1小时,单位:秒 expire-second: 3600 @@ -145,10 +172,10 @@ mybatis-plus: logic-delete-value: 0 logic-not-delete-value: 1 mapper-locations: classpath*:mapper/**/*Mapper.xml -################################ mybatis-plus end ################################# +################################ mybatis-plus end ################################## -############################### DRUID数据源配置 start ############################## +############################### DRUID数据源配置 start ################################ --- spring: datasource: diff --git a/src/test/java/io/geekidea/springbootplus/test/PathMatcherTest.java b/src/test/java/io/geekidea/springbootplus/test/PathMatcherTest.java new file mode 100644 index 00000000..a235e897 --- /dev/null +++ b/src/test/java/io/geekidea/springbootplus/test/PathMatcherTest.java @@ -0,0 +1,36 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.test; + +import org.springframework.util.AntPathMatcher; + +/** + * @author geekidea + * @date 2019-10-10 + **/ +public class PathMatcherTest { + + public static void main(String[] args) { + AntPathMatcher pathMatcher = new AntPathMatcher(); + String pattern = "/hello/**"; + String path = "/hello/world"; + boolean flag = pathMatcher.match(pattern, path); + System.out.println(flag); + + } + +} From 3738c46b4f025515622264bbe6d781fbf27362b3 Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Fri, 11 Oct 2019 11:12:23 +0800 Subject: [PATCH 04/21] =?UTF-8?q?:cn:=20=E9=98=B2=E6=AD=A2Xss=E8=B7=A8?= =?UTF-8?q?=E7=AB=99=E8=84=9A=E6=9C=AC=E6=94=BB=E5=87=BBFilter=E5=A4=84?= =?UTF-8?q?=E7=90=86=EF=BC=8CAop=E5=88=87=E7=82=B9=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=8CAop=20JSON=E5=8F=82=E6=95=B0=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8C=E5=8D=87=E7=BA=A7springboot?= =?UTF-8?q?=E4=B8=BA2.1.9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- README-zh.md | 8 +-- README.md | 8 +-- pom.xml | 23 ++++-- .../SpringBootPlusApplication.java | 5 +- .../springbootplus/common/aop/LogAop.java | 72 ++++++++++--------- .../config/json/jackson/JacksonConfig.java | 33 +++++---- .../core/config/SpringBootPlusConfig.java | 8 +-- .../SpringBootPlusAopProperties.java | 71 ++++++++++++++++++ .../SpringBootPlusFilterProperties.java | 2 + .../SpringBootPlusStaticProperties.java | 48 +++++++++++++ .../shiro/config/ShiroConfig.java | 1 + .../shiro/controller/LoginController.java | 8 --- .../springbootplus/xss/XssFilter.java | 42 +++++++++++ .../xss/XssHttpServletRequestWrapper.java | 65 +++++++++++++++++ .../xss/XssJacksonDeserializer.java | 42 +++++++++++ .../xss/XssJacksonSerializer.java | 44 ++++++++++++ src/main/resources/config/application.yml | 34 ++++----- 18 files changed, 422 insertions(+), 94 deletions(-) create mode 100644 src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusAopProperties.java create mode 100644 src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusStaticProperties.java create mode 100644 src/main/java/io/geekidea/springbootplus/xss/XssFilter.java create mode 100644 src/main/java/io/geekidea/springbootplus/xss/XssHttpServletRequestWrapper.java create mode 100644 src/main/java/io/geekidea/springbootplus/xss/XssJacksonDeserializer.java create mode 100644 src/main/java/io/geekidea/springbootplus/xss/XssJacksonSerializer.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 162e4f04..1da28ab9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,7 +60,7 @@ - [spring-boot-plus java docs](http://geekidea.io/spring-boot-plus-apidocs/) ### 🔨 Dependency Upgrades -- Upgrade to `springboot` 2.1.8.RELEASE +- Upgrade to `springboot` 2.1.9.RELEASE - Upgrade to `Mybatis` 3.5.2 - Upgrade to `Mybatis Plus` 3.2.0 - Upgrade to `Alibaba Druid` 1.1.20 diff --git a/README-zh.md b/README-zh.md index 53a9607f..504fef5a 100644 --- a/README-zh.md +++ b/README-zh.md @@ -9,10 +9,10 @@

- spring-boot-plus version + spring-boot-plus version - spring boot version + spring boot version code style @@ -58,8 +58,8 @@ Redis | 3.2+ | | ### 技术选型 技术 | 版本 | 备注 -|-|- -Spring Boot | 2.1.8.RELEASE | 最新发布稳定版 | -Spring Framework | 5.1.9.RELEASE | 最新发布稳定版 | +Spring Boot | 2.1.9.RELEASE | 最新发布稳定版 | +Spring Framework | 5.1.10.RELEASE | 最新发布稳定版 | Mybatis | 3.5.2 | 持久层框架 | Mybatis Plus | 3.2.0 | mybatis增强框架 | Alibaba Druid | 1.1.20 | 数据源 | diff --git a/README.md b/README.md index b3ec837a..b37b1d61 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,10 @@

- spring-boot-plus version + spring-boot-plus version - spring boot version + spring boot version code style @@ -60,8 +60,8 @@ Redis | 3.2+ | | ### Technology stack Component| Version | Remark -|-|- -Spring Boot | 2.1.8.RELEASE | Latest release stable version | -Spring Framework | 5.1.9.RELEASE | Latest release stable version | +Spring Boot | 2.1.9.RELEASE | Latest release stable version | +Spring Framework | 5.1.10.RELEASE | Latest release stable version | Mybatis | 3.5.2 | DAO Framework | Mybatis Plus | 3.2.0 | mybatis Enhanced framework | Alibaba Druid | 1.1.20 | Data source | diff --git a/pom.xml b/pom.xml index 9737f7b9..c7dc86cc 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ io.geekidea spring-boot-plus - 1.3.0.RELEASE + 1.3.1.RELEASE jar spring-boot-plus @@ -47,7 +47,7 @@ ${utf8} ${parent.version} 1.8 - 2.1.0.RELEASE + 2.1.9.RELEASE 3.2.0 1.2.60 2.6.1 @@ -260,11 +260,12 @@ - - de.codecentric - spring-boot-admin-starter-client - ${spring-boot-admin.version} - + + + + + + @@ -301,6 +302,14 @@ + + + org.apache.commons + commons-text + 1.8 + + + diff --git a/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java b/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java index f47b227d..61faf58c 100644 --- a/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java +++ b/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java @@ -16,12 +16,12 @@ package io.geekidea.springbootplus; -import de.codecentric.boot.admin.server.config.EnableAdminServer; import io.geekidea.springbootplus.util.PrintApplicationInfo; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @@ -37,8 +37,9 @@ @EnableScheduling @EnableTransactionManagement @EnableConfigurationProperties -@EnableAdminServer +//@EnableAdminServer @MapperScan({"io.geekidea.springbootplus.**.mapper"}) +@ServletComponentScan @SpringBootApplication public class SpringBootPlusApplication { diff --git a/src/main/java/io/geekidea/springbootplus/common/aop/LogAop.java b/src/main/java/io/geekidea/springbootplus/common/aop/LogAop.java index 1b0c9bb9..3429bc06 100644 --- a/src/main/java/io/geekidea/springbootplus/common/aop/LogAop.java +++ b/src/main/java/io/geekidea/springbootplus/common/aop/LogAop.java @@ -37,11 +37,10 @@ import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.Map; +import java.util.*; /** *

@@ -60,7 +59,7 @@ public class LogAop { /** * 切点 */ - private static final String POINTCUT = "execution(public * io.geekidea.springbootplus.*.web.controller..*.*(..))"; + private static final String POINTCUT = "execution(public * io.geekidea.springbootplus..*.controller..*.*(..))"; /** * 默认的请求内容类型,表单提交 **/ @@ -98,7 +97,7 @@ public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { HttpServletRequest request = attributes.getRequest(); - Map map = new LinkedHashMap<>(); + Map map = new LinkedHashMap<>(); // 获取请求类名和方法名称 Signature signature = joinPoint.getSignature(); @@ -109,76 +108,74 @@ public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { // 请求全路径 String url = request.getRequestURI(); - map.put("path",url); + map.put("path", url); // IP地址 String ip = IpUtil.getRequestIp(); - map.put("ip",ip); + map.put("ip", ip); // 获取请求方式 String requestMethod = request.getMethod(); - map.put("requestMethod",requestMethod); + map.put("requestMethod", requestMethod); // 获取请求内容类型 String contentType = request.getContentType(); - map.put("contentType",contentType); + map.put("contentType", contentType); // 判断控制器方法参数中是否有RequestBody注解 Annotation[][] annotations = method.getParameterAnnotations(); boolean isRequestBody = isRequestBody(annotations); - map.put("isRequestBody",isRequestBody); + map.put("isRequestBody", isRequestBody); // 设置请求参数 Object requestParamJson = getRequestParamJsonString(joinPoint, request, requestMethod, contentType, isRequestBody); - map.put("param",requestParamJson); + map.put("param", requestParamJson); map.put("time", DateUtil.getYYYYMMDDHHMMSS(new Date())); // 获取请求头token - map.put("token",request.getHeader(JwtTokenUtil.getTokenName())); + map.put("token", request.getHeader(JwtTokenUtil.getTokenName())); String requestInfo = null; try { - if (requestLogFormat){ - requestInfo = "\n" + JSON.toJSONString(map,true); - }else{ + if (requestLogFormat) { + requestInfo = "\n" + JSON.toJSONString(map, true); + } else { requestInfo = JSON.toJSONString(map); } } catch (Exception e) { } - log.info(AnsiUtil.getAnsi(Ansi.Color.GREEN,"requestInfo:" + requestInfo)); + log.info(AnsiUtil.getAnsi(Ansi.Color.GREEN, "requestInfo:" + requestInfo)); } catch (Exception e) { e.printStackTrace(); } - // 执行目标方法,获得返回值 Object result = joinPoint.proceed(); - try{ - if (result != null && result instanceof ApiResult){ + try { + if (result != null && result instanceof ApiResult) { ApiResult apiResult = (ApiResult) result; int code = apiResult.getCode(); String responseResultInfo = "responseResult:"; - if (responseLogFormat){ - responseResultInfo += "\n" + JSON.toJSONString(apiResult,true); - }else{ + if (responseLogFormat) { + responseResultInfo += "\n" + JSON.toJSONString(apiResult, true); + } else { responseResultInfo += JSON.toJSONString(apiResult); } - if (code == ApiCode.SUCCESS.getCode()){ - log.info(AnsiUtil.getAnsi(Ansi.Color.BLUE,responseResultInfo)); - }else{ - log.error(AnsiUtil.getAnsi(Ansi.Color.RED,responseResultInfo)); + if (code == ApiCode.SUCCESS.getCode()) { + log.info(AnsiUtil.getAnsi(Ansi.Color.BLUE, responseResultInfo)); + } else { + log.error(AnsiUtil.getAnsi(Ansi.Color.RED, responseResultInfo)); } } - }catch (Exception e){ - log.error("处理响应结果异常",e); + } catch (Exception e) { + log.error("处理响应结果异常", e); } return result; } - /** * 获取请求参数JSON字符串 * @@ -255,10 +252,21 @@ private Object argsArrayToJsonString(Object[] args) { if (args == null) { return null; } - if (args.length == 1) { - return args[0]; + // 去掉HttpServletRequest和HttpServletResponse + List realArgs = new ArrayList<>(); + for (Object arg : args) { + if (arg instanceof HttpServletRequest) { + continue; + } + if (arg instanceof HttpServletResponse) { + continue; + } + realArgs.add(arg); + } + if (realArgs.size() == 1) { + return realArgs.get(0); } else { - return args; + return realArgs; } } diff --git a/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java b/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java index d1ec2b1a..cecb10a2 100644 --- a/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java +++ b/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java @@ -34,6 +34,8 @@ import io.geekidea.springbootplus.config.json.jackson.deserializer.JacksonDoubleDeserializer; import io.geekidea.springbootplus.config.json.jackson.serializer.JacksonDateSerializer; import io.geekidea.springbootplus.config.json.jackson.serializer.JacksonIntegerDeserializer; +import io.geekidea.springbootplus.xss.XssJacksonDeserializer; +import io.geekidea.springbootplus.xss.XssJacksonSerializer; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; @@ -47,7 +49,6 @@ import java.util.List; /** - * * @author geekidea * @author 2018-11-08 */ @@ -67,29 +68,33 @@ public void extendMessageConverters(List> converters) { simpleModule.addSerializer(Long.class, ToStringSerializer.instance); simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); + // XSS序列化 + simpleModule.addSerializer(String.class, new XssJacksonSerializer()); + simpleModule.addDeserializer(String.class, new XssJacksonDeserializer()); + // Date - simpleModule.addSerializer(Date.class,new JacksonDateSerializer()); - simpleModule.addDeserializer(Date.class,new JacksonDateDeserializer()); + simpleModule.addSerializer(Date.class, new JacksonDateSerializer()); + simpleModule.addDeserializer(Date.class, new JacksonDateDeserializer()); - simpleModule.addDeserializer(Integer.class,new JacksonIntegerDeserializer()); - simpleModule.addDeserializer(Double.class,new JacksonDoubleDeserializer()); + simpleModule.addDeserializer(Integer.class, new JacksonIntegerDeserializer()); + simpleModule.addDeserializer(Double.class, new JacksonDoubleDeserializer()); // jdk8日期序列化和反序列化设置 JavaTimeModule javaTimeModule = new JavaTimeModule(); - javaTimeModule.addSerializer(LocalDateTime.class,new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DatePattern.yyyy_MM_dd_HH_mm_ss))); - javaTimeModule.addDeserializer(LocalDateTime.class,new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DatePattern.yyyy_MM_dd_HH_mm_ss))); - - javaTimeModule.addSerializer(LocalDate.class,new LocalDateSerializer(DateTimeFormatter.ofPattern(DatePattern.yyyy_MM_dd))); - javaTimeModule.addDeserializer(LocalDate.class,new LocalDateDeserializer(DateTimeFormatter.ofPattern(DatePattern.yyyy_MM_dd))); - - javaTimeModule.addSerializer(LocalTime.class,new LocalTimeSerializer(DateTimeFormatter.ofPattern(DatePattern.HH_mm_ss))); - javaTimeModule.addDeserializer(LocalTime.class,new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DatePattern.HH_mm_ss))); + javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DatePattern.yyyy_MM_dd_HH_mm_ss))); + javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DatePattern.yyyy_MM_dd_HH_mm_ss))); + + javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DatePattern.yyyy_MM_dd))); + javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DatePattern.yyyy_MM_dd))); + + javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DatePattern.HH_mm_ss))); + javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DatePattern.HH_mm_ss))); objectMapper.registerModule(simpleModule).registerModule(javaTimeModule).registerModule(new ParameterNamesModule()); jackson2HttpMessageConverter.setObjectMapper(objectMapper); //放到第一个 - converters.add(0,jackson2HttpMessageConverter); + converters.add(0, jackson2HttpMessageConverter); } } \ No newline at end of file diff --git a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java index b125a9de..ea5ffe87 100644 --- a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java @@ -17,10 +17,7 @@ import io.geekidea.springbootplus.common.aop.LogAop; import io.geekidea.springbootplus.common.web.interceptor.PermissionInterceptor; -import io.geekidea.springbootplus.core.properties.SpringBootPlusCorsProperties; -import io.geekidea.springbootplus.core.properties.SpringBootPlusFilterProperties; -import io.geekidea.springbootplus.core.properties.SpringBootPlusInterceptorProperties; -import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; +import io.geekidea.springbootplus.core.properties.*; import io.geekidea.springbootplus.resource.web.interceptor.DownloadInterceptor; import io.geekidea.springbootplus.resource.web.interceptor.ResourceInterceptor; import io.geekidea.springbootplus.resource.web.interceptor.UploadInterceptor; @@ -47,7 +44,8 @@ SpringBootPlusProperties.class, SpringBootPlusCorsProperties.class, SpringBootPlusFilterProperties.class, - SpringBootPlusInterceptorProperties.class + SpringBootPlusInterceptorProperties.class, + SpringBootPlusAopProperties.class }) public class SpringBootPlusConfig { diff --git a/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusAopProperties.java b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusAopProperties.java new file mode 100644 index 00000000..93dfaaa4 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusAopProperties.java @@ -0,0 +1,71 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.core.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.NestedConfigurationProperty; + +/** + * AOP配置属性 + * + * @author geekidea + * @date 2019-09-29 + * @since 1.3.0.RELEASE + **/ +@Data +@ConfigurationProperties(prefix = "spring-boot-plus.aop") +public class SpringBootPlusAopProperties { + + /** + * 请求路径Filter配置 + */ + @NestedConfigurationProperty + private AopConfig log = new LogAopConfig(); + + @Data + public static class AopConfig { + + /** + * 是否启用 + */ + private boolean enabled; + + /** + * 切点表达式 + */ + private String pointcut; + + } + + + @Data + public static class LogAopConfig extends AopConfig{ + + /** + * 请求日志在控制台是否格式化输出,local环境建议开启,服务器环境设置为false + */ + private boolean requestLogFormat; + + /** + * 响应日志在控制台是否格式化输出,local环境建议开启,服务器环境设置为false + */ + private boolean responseLogFormat; + + } + +} diff --git a/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusFilterProperties.java b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusFilterProperties.java index 1fa0310a..5722988d 100644 --- a/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusFilterProperties.java +++ b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusFilterProperties.java @@ -21,6 +21,8 @@ import org.springframework.boot.context.properties.NestedConfigurationProperty; /** + * Filter配置属性 + * * @author geekidea * @date 2019-09-29 * @since 1.3.0.RELEASE diff --git a/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusStaticProperties.java b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusStaticProperties.java new file mode 100644 index 00000000..bbc7dcbe --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusStaticProperties.java @@ -0,0 +1,48 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.core.properties; + +import com.oracle.tools.packager.Log; +import lombok.Data; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +import javax.annotation.PostConstruct; + +/** + * 配置文件属性映射为静态属性 + * + * @author geekidea + * @date 2019-10-11 + * @since 1.3.1.RELEASE + **/ +@Data +@Configuration +public class SpringBootPlusStaticProperties { + + public static String INFO_PROJECT_VERSION = ""; + + @Value("${info.project-version}") + private String infoProjectVersion; + + @PostConstruct + public void init() { + INFO_PROJECT_VERSION = this.infoProjectVersion; + Log.debug("INFO_PROJECT_VERSION:" + INFO_PROJECT_VERSION); + } + +} diff --git a/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java b/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java index fb9377a9..13ea3f91 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java @@ -302,6 +302,7 @@ public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() { @Bean public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() { DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator(); + defaultAdvisorAutoProxyCreator.setProxyTargetClass(true); return defaultAdvisorAutoProxyCreator; } diff --git a/src/main/java/io/geekidea/springbootplus/shiro/controller/LoginController.java b/src/main/java/io/geekidea/springbootplus/shiro/controller/LoginController.java index 237bf88a..76c08381 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/controller/LoginController.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/controller/LoginController.java @@ -17,8 +17,6 @@ package io.geekidea.springbootplus.shiro.controller; import io.geekidea.springbootplus.common.api.ApiResult; -import io.geekidea.springbootplus.shiro.cache.LoginRedisService; -import io.geekidea.springbootplus.shiro.jwt.JwtProperties; import io.geekidea.springbootplus.shiro.param.LoginParam; import io.geekidea.springbootplus.shiro.service.LoginService; import io.geekidea.springbootplus.system.web.vo.SysUserQueryVo; @@ -49,12 +47,6 @@ public class LoginController { @Autowired private LoginService loginService; - @Autowired - private LoginRedisService loginRedisService; - - @Autowired - private JwtProperties jwtProperties; - @PostMapping("/login") @ApiOperation(value = "登陆", notes = "系统用户登陆", response = SysUserQueryVo.class) public ApiResult login(@Valid @RequestBody LoginParam loginParam, HttpServletResponse response) { diff --git a/src/main/java/io/geekidea/springbootplus/xss/XssFilter.java b/src/main/java/io/geekidea/springbootplus/xss/XssFilter.java new file mode 100644 index 00000000..02815830 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/xss/XssFilter.java @@ -0,0 +1,42 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.xss; + +import lombok.extern.slf4j.Slf4j; + +import javax.servlet.*; +import javax.servlet.annotation.WebFilter; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; + +/** + * Xss过滤器 + * + * @author geekidea + * @date 2019-10-10 + * @since 1.3.1.RELEASE + **/ +@Slf4j +@WebFilter(filterName = "xssFilter", urlPatterns = "/*", asyncSupported = true) +public class XssFilter implements Filter { + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + HttpServletRequest request = (HttpServletRequest) servletRequest; + XssHttpServletRequestWrapper xssHttpServletRequestWrapper = new XssHttpServletRequestWrapper(request); + filterChain.doFilter(xssHttpServletRequestWrapper, servletResponse); + } +} diff --git a/src/main/java/io/geekidea/springbootplus/xss/XssHttpServletRequestWrapper.java b/src/main/java/io/geekidea/springbootplus/xss/XssHttpServletRequestWrapper.java new file mode 100644 index 00000000..772593ad --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/xss/XssHttpServletRequestWrapper.java @@ -0,0 +1,65 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.xss; + +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.text.StringEscapeUtils; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; + +/** + * XSS 跨站脚本攻击(Cross Site Scripting) 处理 + * + * @author geekidea + * @date 2019-10-10 + * @since 1.3.1.RELEASE + **/ +public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { + + public XssHttpServletRequestWrapper(HttpServletRequest request) { + super(request); + } + + @Override + public String getQueryString() { + String value = super.getQueryString(); + return StringEscapeUtils.escapeHtml4(value); + } + + @Override + public String getParameter(String name) { + String value = super.getParameter(name); + return StringEscapeUtils.escapeHtml4(value); + } + + @Override + public String[] getParameterValues(String name) { + String[] values = super.getParameterValues(name); + if (ArrayUtils.isEmpty(values)) { + return values; + } + int length = values.length; + String[] escapeValues = new String[length]; + for (int i = 0; i < length; i++) { + String value = values[i]; + escapeValues[i] = StringEscapeUtils.escapeHtml4(value); + } + return escapeValues; + } + +} diff --git a/src/main/java/io/geekidea/springbootplus/xss/XssJacksonDeserializer.java b/src/main/java/io/geekidea/springbootplus/xss/XssJacksonDeserializer.java new file mode 100644 index 00000000..cba32137 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/xss/XssJacksonDeserializer.java @@ -0,0 +1,42 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.xss; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import org.apache.commons.text.StringEscapeUtils; + +import java.io.IOException; + +/** + * Jackson请求参数字符串转义处理 + * + * @author geekidea + * @date 2019-10-10 + * @since 1.3.1.RELEASE + **/ +public class XssJacksonDeserializer extends JsonDeserializer { + + @Override + public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { + String string = jsonParser.getText(); + return StringEscapeUtils.escapeHtml4(string); + } + +} diff --git a/src/main/java/io/geekidea/springbootplus/xss/XssJacksonSerializer.java b/src/main/java/io/geekidea/springbootplus/xss/XssJacksonSerializer.java new file mode 100644 index 00000000..eb988c22 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/xss/XssJacksonSerializer.java @@ -0,0 +1,44 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.xss; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.text.StringEscapeUtils; + +import java.io.IOException; + +/** + * Jackson响应参数字符串转义处理 + * + * @author geekidea + * @date 2019-10-10 + * @since 1.3.1.RELEASE + **/ +public class XssJacksonSerializer extends JsonSerializer { + + @Override + public void serialize(String s, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { + if (StringUtils.isNotBlank(s)) { + String escapeValue = StringEscapeUtils.escapeHtml4(s); + jsonGenerator.writeString(escapeValue); + } + } + +} diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 6e4c6c87..1d3244ad 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -38,6 +38,22 @@ spring: ############################## spring-boot-plus start ############################## spring-boot-plus: + # 是否启用ansi控制台输出有颜色的字体 + enable-ansi: true + # 请求日志在控制台是否格式化输出 + request-log-format: true + # 响应日志在控制台是否格式化输出 + response-log-format: true + # 过滤器配置 + filter: + # 请求路径Filter配置 + request-path: + enabled: true + include-paths: /** + # 排除路径,多行字符串配置 + exclude-paths: | + /actuator/**,/instances,/logfile,/sba-settings.js,/assets/img/favicon.png, + /swagger-ui.html,/swagger-resources/**,/webjars/springfox-swagger-ui/**,/v2/api-docs # 拦截器配置 interceptor: permission: @@ -54,17 +70,6 @@ spring-boot-plus: enabled: true include-paths: /download/** - # 过滤器配置 - filter: - # 请求路径Filter配置 - request-path: - enabled: true - include-paths: /** - # 排除路径,多行字符串配置 - exclude-paths: | - /actuator/**,/instances,/logfile,/sba-settings.js,/assets/img/favicon.png, - /swagger-ui.html,/swagger-resources/**,/webjars/springfox-swagger-ui/**,/v2/api-docs - # 文件上传下载配置 # 上传路径配置 upload-path: /opt/upload/ @@ -115,6 +120,7 @@ spring-boot-plus: /templates/**=anon /druid/**=anon /hello/world=anon + /xss/**=anon # 权限配置 permission: # 排除登陆登出相关 @@ -220,12 +226,6 @@ spring: --- spring: redis: - jedis: - pool: - max-active: 2000 - max-wait: -1ms - min-idle: 8 - max-idle: 200 timeout: 10s lettuce: pool: From 00b49f013a23c40f2ac828075ac8404751577911 Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Fri, 11 Oct 2019 16:33:30 +0800 Subject: [PATCH 05/21] =?UTF-8?q?:cn:=20=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90Validation=E5=AD=97=E6=AE=B5=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 3 +- .../SpringBootPlusStaticProperties.java | 5 +-- .../config/SpringBootPlusMySqlQuery.java | 34 +++++++++++++++++++ .../generator/package-info.java | 21 ++++++++++++ .../springbootplus/test/CodeGenerator.java | 4 +++ src/test/resources/templates/entity.java.vm | 13 +++++++ 6 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 src/main/java/io/geekidea/springbootplus/generator/config/SpringBootPlusMySqlQuery.java create mode 100644 src/main/java/io/geekidea/springbootplus/generator/package-info.java diff --git a/pom.xml b/pom.xml index c7dc86cc..06414511 100644 --- a/pom.xml +++ b/pom.xml @@ -70,6 +70,7 @@ 1.3.0.Final 1.4.1 3.8.3 + 1.8 3.8.1 3.1.0 @@ -306,7 +307,7 @@ org.apache.commons commons-text - 1.8 + ${commons-text.version} diff --git a/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusStaticProperties.java b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusStaticProperties.java index bbc7dcbe..a843354f 100644 --- a/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusStaticProperties.java +++ b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusStaticProperties.java @@ -16,8 +16,8 @@ package io.geekidea.springbootplus.core.properties; -import com.oracle.tools.packager.Log; import lombok.Data; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; @@ -30,6 +30,7 @@ * @date 2019-10-11 * @since 1.3.1.RELEASE **/ +@Slf4j @Data @Configuration public class SpringBootPlusStaticProperties { @@ -42,7 +43,7 @@ public class SpringBootPlusStaticProperties { @PostConstruct public void init() { INFO_PROJECT_VERSION = this.infoProjectVersion; - Log.debug("INFO_PROJECT_VERSION:" + INFO_PROJECT_VERSION); + log.debug("INFO_PROJECT_VERSION:" + INFO_PROJECT_VERSION); } } diff --git a/src/main/java/io/geekidea/springbootplus/generator/config/SpringBootPlusMySqlQuery.java b/src/main/java/io/geekidea/springbootplus/generator/config/SpringBootPlusMySqlQuery.java new file mode 100644 index 00000000..fc92c680 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/generator/config/SpringBootPlusMySqlQuery.java @@ -0,0 +1,34 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.generator.config; + +import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery; + +/** + * MySQL代码生成查询是否为空的列 + * + * @author geekidea + * @date 2019-10-11 + **/ +public class SpringBootPlusMySqlQuery extends MySqlQuery { + + @Override + public String[] fieldCustom() { + return new String[]{"null", "default"}; + } + +} diff --git a/src/main/java/io/geekidea/springbootplus/generator/package-info.java b/src/main/java/io/geekidea/springbootplus/generator/package-info.java new file mode 100644 index 00000000..d70cb518 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/generator/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author geekidea + * @date 2019-10-11 + **/ +package io.geekidea.springbootplus.generator; \ No newline at end of file diff --git a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java index 89e53c56..973e45a0 100644 --- a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java +++ b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java @@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.generator.config.po.TableInfo; import com.baomidou.mybatisplus.generator.config.rules.DateType; import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import io.geekidea.springbootplus.generator.config.SpringBootPlusMySqlQuery; import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; @@ -104,6 +105,9 @@ public static void main(String[] args) { dsc.setDriverName(DRIVER_NAME); dsc.setUsername(USER_NAME); dsc.setPassword(PASSWORD); + // 设置自定义查询 + dsc.setDbQuery(new SpringBootPlusMySqlQuery()); + mpg.setDataSource(dsc); // 包配置 diff --git a/src/test/resources/templates/entity.java.vm b/src/test/resources/templates/entity.java.vm index fc801134..a56d38ad 100644 --- a/src/test/resources/templates/entity.java.vm +++ b/src/test/resources/templates/entity.java.vm @@ -13,6 +13,9 @@ import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; #end +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + /** *

* $!{table.comment} @@ -96,9 +99,19 @@ public class ${entity} implements Serializable { #if(${custom_is_pk}) private ${field.propertyType} ${field.propertyName}; #else +## 如果没有默认值,且不为空,则设置非空校验 +#if(${field.customMap.null} == 'NO' && !${field.customMap.default}) +#if(${field.propertyType} == 'String') +@NotBlank(message = "${field.comment}不能为空") +#else +@NotNull(message = "${field.comment}不能为空") +#end + private ${field.propertyType} ${field.propertyName}; +#else private ${field.propertyType} ${field.propertyName}; #end #end +#end ## ---------- END 字段循环遍历 ---------- #if(!${entityLombokModel}) #foreach($field in ${table.fields}) From a5f5b17e8f3b5a015733e8a384a417a495a2ebe0 Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Fri, 11 Oct 2019 17:50:35 +0800 Subject: [PATCH 06/21] =?UTF-8?q?:cn:=20=E5=8F=AF=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E7=94=9F=E6=88=90Validation=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springbootplus/test/CodeGenerator.java | 18 +++++++++++++----- .../resources/templates/controller.java.vm | 2 ++ src/test/resources/templates/entity.java.vm | 6 ++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java index 973e45a0..d34fffde 100644 --- a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java +++ b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java @@ -61,13 +61,16 @@ public class CodeGenerator { // 作者 private static final String AUTHOR = "geekidea"; // 生成的表名称 - private static final String TABLE_NAME = "sys_log"; + private static final String TABLE_NAME = "sys_role"; // 主键数据库列名称 - private static final String PK_ID_COLUMN_NAME = "log_id"; + private static final String PK_ID_COLUMN_NAME = "id"; // 代码生成策略 true:All/false:SIMPLE private static final boolean GENERATOR_STRATEGY = true; // 分页列表查询是否排序 true:有排序参数/false:无 private static final boolean PAGE_LIST_ORDER = false; + // 是否生成validation校验,true:生成/false:不生成 + private static final boolean PARAM_VALIDATION = true; + // 生成文件配置,是否生成entity/controller/service/serviceImpl/mapper/xml private static final boolean GENERATOR_ENTITY = true; private static final boolean GENERATOR_CONTROLLER = true; @@ -123,6 +126,7 @@ public static void main(String[] args) { @Override public void initMap() { + String camelTableName = underlineToCamel(TABLE_NAME); String pascalTableName = underlineToPascal(TABLE_NAME); Map map = new HashMap<>(); @@ -142,11 +146,11 @@ public void initMap() { // 响应结果类路径 map.put("queryVoPath", queryVoPackage + StringPool.DOT + pascalTableName + "QueryVo"); // 实体对象名称 - map.put("entityObjectName", pascalTableName); + map.put("entityObjectName", camelTableName); // service对象名称 - map.put("serviceObjectName", pascalTableName + "Service"); + map.put("serviceObjectName", camelTableName + "Service"); // mapper对象名称 - map.put("mapperObjectName", pascalTableName + "Mapper"); + map.put("mapperObjectName", camelTableName + "Mapper"); // 主键ID列名 map.put("pkIdColumnName", PK_ID_COLUMN_NAME); // 主键ID驼峰名称 @@ -164,6 +168,8 @@ public void initMap() { map.put("orderQueryParamPath", PARENT_PACKAGE + StringPool.DOT + "common.web.param." + "OrderQueryParam"); // 代码生成策略 map.put("generatorStrategy", GENERATOR_STRATEGY); + // 代码Validation校验 + map.put("paramValidation", PARAM_VALIDATION); this.setMap(map); } }; @@ -267,4 +273,6 @@ public static String underlineToPascal(String underline) { return null; } + + } diff --git a/src/test/resources/templates/controller.java.vm b/src/test/resources/templates/controller.java.vm index 7930f041..8999f58e 100644 --- a/src/test/resources/templates/controller.java.vm +++ b/src/test/resources/templates/controller.java.vm @@ -23,7 +23,9 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.stereotype.Controller; #end +#if(${cfg.paramValidation}) import javax.validation.Valid; +#end import ${cfg.paging}; import ${cfg.idParamPath}; diff --git a/src/test/resources/templates/entity.java.vm b/src/test/resources/templates/entity.java.vm index a56d38ad..0b82076e 100644 --- a/src/test/resources/templates/entity.java.vm +++ b/src/test/resources/templates/entity.java.vm @@ -13,8 +13,10 @@ import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; #end +#if(${cfg.paramValidation}) import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +#end /** *

@@ -100,6 +102,7 @@ public class ${entity} implements Serializable { private ${field.propertyType} ${field.propertyName}; #else ## 如果没有默认值,且不为空,则设置非空校验 +#if(${cfg.paramValidation}) #if(${field.customMap.null} == 'NO' && !${field.customMap.default}) #if(${field.propertyType} == 'String') @NotBlank(message = "${field.comment}不能为空") @@ -110,6 +113,9 @@ public class ${entity} implements Serializable { #else private ${field.propertyType} ${field.propertyName}; #end +#else +private ${field.propertyType} ${field.propertyName}; +#end #end #end ## ---------- END 字段循环遍历 ---------- From 3166019e949728bc1839f84e54e745a17499a2f7 Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Fri, 11 Oct 2019 19:19:02 +0800 Subject: [PATCH 07/21] =?UTF-8?q?:cn:=20=E4=BC=98=E5=8C=96controller?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/geekidea/springbootplus/test/CodeGenerator.java | 2 +- src/test/resources/templates/controller.java.vm | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java index d34fffde..d6d59455 100644 --- a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java +++ b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java @@ -57,7 +57,7 @@ public class CodeGenerator { // ############################ 配置部分 start ############################ // 模块名称 - private static final String MODULE_NAME = "system"; + private static final String MODULE_NAME = "hello"; // 作者 private static final String AUTHOR = "geekidea"; // 生成的表名称 diff --git a/src/test/resources/templates/controller.java.vm b/src/test/resources/templates/controller.java.vm index 8999f58e..3553e91c 100644 --- a/src/test/resources/templates/controller.java.vm +++ b/src/test/resources/templates/controller.java.vm @@ -65,7 +65,7 @@ public class ${table.controllerName} { */ @PostMapping("/add") @ApiOperation(value = "添加${entity}对象", notes = "添加$!{table.comment}", response = ApiResult.class) - public ApiResult add${entity}(@Valid @RequestBody ${entity} ${cfg.entityObjectName}) throws Exception { + public ApiResult add${entity}(#if(${cfg.paramValidation})@Valid#end @RequestBody ${entity} ${cfg.entityObjectName}) throws Exception { boolean flag = ${cfg.serviceObjectName}.save(${cfg.entityObjectName}); return ApiResult.result(flag); } @@ -75,7 +75,7 @@ public class ${table.controllerName} { */ @PostMapping("/update") @ApiOperation(value = "修改${entity}对象", notes = "修改$!{table.comment}", response = ApiResult.class) - public ApiResult update${entity}(@Valid @RequestBody ${entity} ${cfg.entityObjectName}) throws Exception { + public ApiResult update${entity}(#if(${cfg.paramValidation})@Valid#end @RequestBody ${entity} ${cfg.entityObjectName}) throws Exception { boolean flag = ${cfg.serviceObjectName}.updateById(${cfg.entityObjectName}); return ApiResult.result(flag); } @@ -85,7 +85,7 @@ public class ${table.controllerName} { */ @PostMapping("/delete") @ApiOperation(value = "删除${entity}对象", notes = "删除$!{table.comment}", response = ApiResult.class) - public ApiResult delete${entity}(@Valid @RequestBody IdParam idParam) throws Exception { + public ApiResult delete${entity}(#if(${cfg.paramValidation})@Valid#end @RequestBody IdParam idParam) throws Exception { boolean flag = ${cfg.serviceObjectName}.removeById(idParam.getId()); return ApiResult.result(flag); } @@ -95,7 +95,7 @@ public class ${table.controllerName} { */ @PostMapping("/info") @ApiOperation(value = "获取${entity}对象详情", notes = "查看$!{table.comment}", response = ${entity}QueryVo.class) - public ApiResult<${entity}QueryVo> get${entity}(@Valid @RequestBody IdParam idParam) throws Exception { + public ApiResult<${entity}QueryVo> get${entity}(#if(${cfg.paramValidation})@Valid#end @RequestBody IdParam idParam) throws Exception { ${entity}QueryVo ${cfg.entityObjectName}QueryVo = ${cfg.serviceObjectName}.get${entity}ById(idParam.getId()); return ApiResult.ok(${cfg.entityObjectName}QueryVo); } @@ -105,7 +105,7 @@ public class ${table.controllerName} { */ @PostMapping("/getPageList") @ApiOperation(value = "获取${entity}分页列表", notes = "$!{table.comment}分页列表", response = ${entity}QueryVo.class) - public ApiResult> get${entity}PageList(@Valid @RequestBody(required = false) ${entity}QueryParam ${cfg.entityObjectName}QueryParam) throws Exception { + public ApiResult> get${entity}PageList(#if(${cfg.paramValidation})@Valid#end @RequestBody ${entity}QueryParam ${cfg.entityObjectName}QueryParam) throws Exception { Paging<${entity}QueryVo> paging = ${cfg.entityObjectName}Service.get${entity}PageList(${cfg.entityObjectName}QueryParam); return ApiResult.ok(paging); } From 01d3b8cdf839fe6659badfc6a59ca5304020b3cc Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Fri, 11 Oct 2019 19:42:15 +0800 Subject: [PATCH 08/21] =?UTF-8?q?:tiger:=20=E8=B0=83=E6=95=B4controller/pa?= =?UTF-8?q?ram/vo=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E7=9A=84=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springbootplus/test/CodeGenerator.java | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java index d6d59455..b9db8dab 100644 --- a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java +++ b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java @@ -45,14 +45,27 @@ public class CodeGenerator { private static final String DRIVER_NAME = "com.mysql.jdbc.Driver"; private static final String DRIVER_URL = "jdbc:mysql://localhost:3306/spring_boot_plus?useUnicode=true&characterEncoding=UTF-8&useSSL=false"; + // 生成的类路径 + private static final String PROJECT_PACKAGE_PATH = "io/geekidea/springbootplus"; + + // 项目主包路径 private static final String PARENT_PACKAGE = "io.geekidea.springbootplus"; - private static final String SUPER_ENTITY = PARENT_PACKAGE + ".common.entity.BaseEntity"; + private static final String COMMON_PARENT_PACKAGE = PARENT_PACKAGE + ".common"; + + // 父类包路径 + private static final String SUPER_ENTITY = COMMON_PARENT_PACKAGE + ".entity.BaseEntity"; + private static final String SUPER_CONTROLLER = COMMON_PARENT_PACKAGE + ".web.controller.BaseController"; + private static final String SUPER_SERVICE = COMMON_PARENT_PACKAGE + ".service.BaseService"; + private static final String SUPER_SERVICE_IMPL = COMMON_PARENT_PACKAGE + ".service.impl.BaseServiceImpl"; + private static final String SUPER_QUERY_PARAM = COMMON_PARENT_PACKAGE + ".web.param.QueryParam"; private static final String[] SUPER_ENTITY_COMMON_COLUMNS = new String[]{}; - private static final String SUPER_CONTROLLER = PARENT_PACKAGE + ".common.web.controller.BaseController"; - private static final String SUPER_SERVICE = PARENT_PACKAGE + ".common.service.BaseService"; - private static final String SUPER_SERVICE_IMPL = PARENT_PACKAGE + ".common.service.impl.BaseServiceImpl"; - private static final String PROJECT_PACKAGE_PATH = "io/geekidea/springbootplus"; + // 公共类包路径 + private static final String COMMON_ID_PARAM = COMMON_PARENT_PACKAGE + ".web.param.IdParam"; + private static final String COMMON_API_RESULT = COMMON_PARENT_PACKAGE + ".api.ApiResult"; + private static final String COMMON_ORDER_ENUM = COMMON_PARENT_PACKAGE + ".enums.OrderEnum"; + private static final String COMMON_ORDER_QUERY_PARAM = COMMON_PARENT_PACKAGE + ".web.param.OrderQueryParam"; + private static final String COMMON_PAGING = COMMON_PARENT_PACKAGE + ".web.vo.Paging"; // ############################ 配置部分 start ############################ @@ -117,7 +130,7 @@ public static void main(String[] args) { PackageConfig pc = new PackageConfig(); pc.setModuleName(MODULE_NAME); pc.setParent(PARENT_PACKAGE); - pc.setController("web.controller"); + pc.setController("controller"); mpg.setPackageInfo(pc); @@ -132,16 +145,16 @@ public void initMap() { Map map = new HashMap<>(); map.put("customField", "Hello " + this.getConfig().getGlobalConfig().getAuthor()); // 查询参数包路径 - String queryParamPackage = PARENT_PACKAGE + StringPool.DOT + pc.getModuleName() + ".web.param"; + String queryParamPackage = PARENT_PACKAGE + StringPool.DOT + pc.getModuleName() + ".param"; map.put("queryParamPackage", queryParamPackage); // 查询参数类路径 map.put("queryParamPath", queryParamPackage + StringPool.DOT + pascalTableName + "QueryParam"); // 查询参数共公包路径 - map.put("queryParamCommonPath", PARENT_PACKAGE + StringPool.DOT + "common.web.param." + "QueryParam"); + map.put("queryParamCommonPath", SUPER_QUERY_PARAM); // 查询参数共公包路径 - map.put("idParamPath", PARENT_PACKAGE + StringPool.DOT + "common.web.param." + "IdParam"); + map.put("idParamPath", COMMON_ID_PARAM); // 响应结果包路径 - String queryVoPackage = PARENT_PACKAGE + StringPool.DOT + pc.getModuleName() + ".web.vo"; + String queryVoPackage = PARENT_PACKAGE + StringPool.DOT + pc.getModuleName() + ".vo"; map.put("queryVoPackage", queryVoPackage); // 响应结果类路径 map.put("queryVoPath", queryVoPackage + StringPool.DOT + pascalTableName + "QueryVo"); @@ -156,16 +169,15 @@ public void initMap() { // 主键ID驼峰名称 map.put("pkIdCamelName", underlineToCamel(PK_ID_COLUMN_NAME)); // 导入分页类 - map.put("paging", PARENT_PACKAGE + ".common.web.vo.Paging"); + map.put("paging", COMMON_PAGING); // 导入排序枚举 - map.put("orderEnum", PARENT_PACKAGE + ".common.enums.OrderEnum"); + map.put("orderEnum", COMMON_ORDER_ENUM); // ApiResult - // io.geekidea.springbootplus.common.api.ApiResult; - map.put("apiResult", PARENT_PACKAGE + ".common.api.ApiResult"); + map.put("apiResult", COMMON_API_RESULT); // 分页列表查询是否排序 map.put("pageListOrder", PAGE_LIST_ORDER); // 导入排序查询参数类 - map.put("orderQueryParamPath", PARENT_PACKAGE + StringPool.DOT + "common.web.param." + "OrderQueryParam"); + map.put("orderQueryParamPath", COMMON_ORDER_QUERY_PARAM); // 代码生成策略 map.put("generatorStrategy", GENERATOR_STRATEGY); // 代码Validation校验 @@ -192,7 +204,7 @@ public String outputFile(TableInfo tableInfo) { focList.add(new FileOutConfig("/templates/queryParam.java.vm") { @Override public String outputFile(TableInfo tableInfo) { - return projectPath + "/src/main/java/" + PROJECT_PACKAGE_PATH + "/" + pc.getModuleName() + "/web/param/" + tableInfo.getEntityName() + "QueryParam" + StringPool.DOT_JAVA; + return projectPath + "/src/main/java/" + PROJECT_PACKAGE_PATH + "/" + pc.getModuleName() + "/param/" + tableInfo.getEntityName() + "QueryParam" + StringPool.DOT_JAVA; } }); } @@ -202,7 +214,7 @@ public String outputFile(TableInfo tableInfo) { focList.add(new FileOutConfig("/templates/queryVo.java.vm") { @Override public String outputFile(TableInfo tableInfo) { - return projectPath + "/src/main/java/" + PROJECT_PACKAGE_PATH + "/" + pc.getModuleName() + "/web/vo/" + tableInfo.getEntityName() + "QueryVo" + StringPool.DOT_JAVA; + return projectPath + "/src/main/java/" + PROJECT_PACKAGE_PATH + "/" + pc.getModuleName() + "/vo/" + tableInfo.getEntityName() + "QueryVo" + StringPool.DOT_JAVA; } }); } @@ -274,5 +286,4 @@ public static String underlineToPascal(String underline) { } - } From aa5730d76e3094fe4e44b55d8ac0e0bf6b376e76 Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Fri, 11 Oct 2019 23:02:25 +0800 Subject: [PATCH 09/21] =?UTF-8?q?:tiger:=20=E8=B0=83=E6=95=B4common?= =?UTF-8?q?=E5=8C=85=E4=B8=8Bcontroller/param/vo=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=9A=84=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/db/mysql_spring_boot_plus.sql | 2 +- pom.xml | 1 - .../controller/ApiDocController.java | 2 +- .../{web => }/controller/BaseController.java | 2 +- .../{web => }/controller/IndexController.java | 2 +- .../{web => }/filter/RequestPathFilter.java | 2 +- .../interceptor/PermissionInterceptor.java | 2 +- .../springbootplus/common/package-info.java | 22 ----- .../common/{web => }/param/IdParam.java | 2 +- .../common/{web => }/param/IdStatusParam.java | 2 +- .../common/{web => }/param/NameParam.java | 2 +- .../{web => }/param/OrderQueryParam.java | 2 +- .../common/{web => }/param/QueryParam.java | 2 +- .../common/service/impl/BaseServiceImpl.java | 4 +- .../common/{web => }/vo/CommonIdName.java | 2 +- .../common/{web => }/vo/Paging.java | 2 +- .../springbootplus/config/package-info.java | 22 ----- .../core/config/SpringBootPlusConfig.java | 8 +- .../config/SpringBootPlusWebMvcConfig.java | 8 +- .../controller/DownloadController.java | 2 +- .../controller/ResourceController.java | 2 +- .../controller/UploadController.java | 6 +- .../interceptor/DownloadInterceptor.java | 2 +- .../interceptor/ResourceInterceptor.java | 2 +- .../interceptor/UploadInterceptor.java | 2 +- .../springbootplus/resource/package-info.java | 17 ---- .../shiro/config/ShiroConfig.java | 2 +- .../shiro/controller/LoginController.java | 3 +- .../controller/HelloWorldController.java | 2 +- .../system/controller/IpController.java | 90 +++++++++++++++++++ .../controller/SysLogController.java | 55 ++++-------- .../controller/SysUserController.java | 52 ++++------- .../springbootplus/system/entity/Ip.java | 33 ++----- .../springbootplus/system/entity/SysLog.java | 5 +- .../springbootplus/system/entity/SysUser.java | 23 ++--- .../system/mapper/IpMapper.java | 42 +++++---- .../system/mapper/SysLogMapper.java | 26 ++---- .../system/mapper/SysUserMapper.java | 27 ++---- .../system/param/IpQueryParam.java | 24 +++++ .../system/param/SysLogQueryParam.java | 24 +++++ .../system/param/SysUserQueryParam.java | 24 +++++ .../system/service/IpService.java | 40 +++++---- .../system/service/SysLogService.java | 28 ++---- .../system/service/SysUserService.java | 28 ++---- .../system/service/impl/IpServiceImpl.java | 43 ++++----- .../service/impl/SysLogServiceImpl.java | 34 ++----- .../service/impl/SysUserServiceImpl.java | 34 ++----- .../springbootplus/system/vo/IpQueryVo.java | 39 ++++++++ .../system/{web => }/vo/SysLogQueryVo.java | 20 +---- .../system/{web => }/vo/SysUserQueryVo.java | 21 +---- .../system/web/param/SysLogQueryParam.java | 40 --------- .../system/web/param/SysUserQueryParam.java | 40 --------- .../system/web/vo/IpQueryVo.java | 60 ------------- src/main/resources/mapper/system/IpMapper.xml | 27 +++--- .../resources/mapper/system/SysLogMapper.xml | 20 +---- .../resources/mapper/system/SysUserMapper.xml | 20 +---- .../springbootplus/test/CodeGenerator.java | 14 +-- 57 files changed, 423 insertions(+), 641 deletions(-) rename src/main/java/io/geekidea/springbootplus/common/{web => }/controller/ApiDocController.java (95%) rename src/main/java/io/geekidea/springbootplus/common/{web => }/controller/BaseController.java (96%) rename src/main/java/io/geekidea/springbootplus/common/{web => }/controller/IndexController.java (95%) rename src/main/java/io/geekidea/springbootplus/common/{web => }/filter/RequestPathFilter.java (97%) rename src/main/java/io/geekidea/springbootplus/common/{web => }/interceptor/PermissionInterceptor.java (96%) delete mode 100644 src/main/java/io/geekidea/springbootplus/common/package-info.java rename src/main/java/io/geekidea/springbootplus/common/{web => }/param/IdParam.java (95%) rename src/main/java/io/geekidea/springbootplus/common/{web => }/param/IdStatusParam.java (96%) rename src/main/java/io/geekidea/springbootplus/common/{web => }/param/NameParam.java (96%) rename src/main/java/io/geekidea/springbootplus/common/{web => }/param/OrderQueryParam.java (96%) rename src/main/java/io/geekidea/springbootplus/common/{web => }/param/QueryParam.java (97%) rename src/main/java/io/geekidea/springbootplus/common/{web => }/vo/CommonIdName.java (96%) rename src/main/java/io/geekidea/springbootplus/common/{web => }/vo/Paging.java (97%) delete mode 100644 src/main/java/io/geekidea/springbootplus/config/package-info.java rename src/main/java/io/geekidea/springbootplus/resource/{web => }/controller/DownloadController.java (97%) rename src/main/java/io/geekidea/springbootplus/resource/{web => }/controller/ResourceController.java (96%) rename src/main/java/io/geekidea/springbootplus/resource/{web => }/controller/UploadController.java (94%) rename src/main/java/io/geekidea/springbootplus/resource/{web => }/interceptor/DownloadInterceptor.java (97%) rename src/main/java/io/geekidea/springbootplus/resource/{web => }/interceptor/ResourceInterceptor.java (97%) rename src/main/java/io/geekidea/springbootplus/resource/{web => }/interceptor/UploadInterceptor.java (97%) delete mode 100644 src/main/java/io/geekidea/springbootplus/resource/package-info.java rename src/main/java/io/geekidea/springbootplus/system/{web => }/controller/HelloWorldController.java (96%) create mode 100644 src/main/java/io/geekidea/springbootplus/system/controller/IpController.java rename src/main/java/io/geekidea/springbootplus/system/{web => }/controller/SysLogController.java (59%) rename src/main/java/io/geekidea/springbootplus/system/{web => }/controller/SysUserController.java (58%) create mode 100644 src/main/java/io/geekidea/springbootplus/system/param/IpQueryParam.java create mode 100644 src/main/java/io/geekidea/springbootplus/system/param/SysLogQueryParam.java create mode 100644 src/main/java/io/geekidea/springbootplus/system/param/SysUserQueryParam.java create mode 100644 src/main/java/io/geekidea/springbootplus/system/vo/IpQueryVo.java rename src/main/java/io/geekidea/springbootplus/system/{web => }/vo/SysLogQueryVo.java (55%) rename src/main/java/io/geekidea/springbootplus/system/{web => }/vo/SysUserQueryVo.java (62%) delete mode 100644 src/main/java/io/geekidea/springbootplus/system/web/param/SysLogQueryParam.java delete mode 100644 src/main/java/io/geekidea/springbootplus/system/web/param/SysUserQueryParam.java delete mode 100644 src/main/java/io/geekidea/springbootplus/system/web/vo/IpQueryVo.java diff --git a/docs/db/mysql_spring_boot_plus.sql b/docs/db/mysql_spring_boot_plus.sql index 4fd7332b..a8be0c76 100644 --- a/docs/db/mysql_spring_boot_plus.sql +++ b/docs/db/mysql_spring_boot_plus.sql @@ -32,7 +32,7 @@ CREATE TABLE `ip` ( `ip_start_num` bigint(20) NOT NULL, `ip_end_num` bigint(20) NOT NULL, PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 526718 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; +) ENGINE = InnoDB AUTO_INCREMENT = 526718 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'IP地址' ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for sys_log diff --git a/pom.xml b/pom.xml index 06414511..f1c9a802 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,6 @@ UTF-8 ${utf8} ${utf8} - ${parent.version} 1.8 2.1.9.RELEASE 3.2.0 diff --git a/src/main/java/io/geekidea/springbootplus/common/web/controller/ApiDocController.java b/src/main/java/io/geekidea/springbootplus/common/controller/ApiDocController.java similarity index 95% rename from src/main/java/io/geekidea/springbootplus/common/web/controller/ApiDocController.java rename to src/main/java/io/geekidea/springbootplus/common/controller/ApiDocController.java index 51dc6b1e..17a466cc 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/controller/ApiDocController.java +++ b/src/main/java/io/geekidea/springbootplus/common/controller/ApiDocController.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.web.controller; +package io.geekidea.springbootplus.common.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; diff --git a/src/main/java/io/geekidea/springbootplus/common/web/controller/BaseController.java b/src/main/java/io/geekidea/springbootplus/common/controller/BaseController.java similarity index 96% rename from src/main/java/io/geekidea/springbootplus/common/web/controller/BaseController.java rename to src/main/java/io/geekidea/springbootplus/common/controller/BaseController.java index 889d0f4a..eec1326c 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/controller/BaseController.java +++ b/src/main/java/io/geekidea/springbootplus/common/controller/BaseController.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.web.controller; +package io.geekidea.springbootplus.common.controller; import io.geekidea.springbootplus.common.api.ApiController; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/io/geekidea/springbootplus/common/web/controller/IndexController.java b/src/main/java/io/geekidea/springbootplus/common/controller/IndexController.java similarity index 95% rename from src/main/java/io/geekidea/springbootplus/common/web/controller/IndexController.java rename to src/main/java/io/geekidea/springbootplus/common/controller/IndexController.java index 55d654c0..acfee509 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/controller/IndexController.java +++ b/src/main/java/io/geekidea/springbootplus/common/controller/IndexController.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.web.controller; +package io.geekidea.springbootplus.common.controller; import io.geekidea.springbootplus.common.api.ApiResult; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/io/geekidea/springbootplus/common/web/filter/RequestPathFilter.java b/src/main/java/io/geekidea/springbootplus/common/filter/RequestPathFilter.java similarity index 97% rename from src/main/java/io/geekidea/springbootplus/common/web/filter/RequestPathFilter.java rename to src/main/java/io/geekidea/springbootplus/common/filter/RequestPathFilter.java index 7a17016e..0f3c44de 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/filter/RequestPathFilter.java +++ b/src/main/java/io/geekidea/springbootplus/common/filter/RequestPathFilter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.web.filter; +package io.geekidea.springbootplus.common.filter; import io.geekidea.springbootplus.core.properties.SpringBootPlusFilterProperties; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/io/geekidea/springbootplus/common/web/interceptor/PermissionInterceptor.java b/src/main/java/io/geekidea/springbootplus/common/interceptor/PermissionInterceptor.java similarity index 96% rename from src/main/java/io/geekidea/springbootplus/common/web/interceptor/PermissionInterceptor.java rename to src/main/java/io/geekidea/springbootplus/common/interceptor/PermissionInterceptor.java index 8564113e..2c5ac243 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/interceptor/PermissionInterceptor.java +++ b/src/main/java/io/geekidea/springbootplus/common/interceptor/PermissionInterceptor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.web.interceptor; +package io.geekidea.springbootplus.common.interceptor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.servlet.ModelAndView; diff --git a/src/main/java/io/geekidea/springbootplus/common/package-info.java b/src/main/java/io/geekidea/springbootplus/common/package-info.java deleted file mode 100644 index f943efa2..00000000 --- a/src/main/java/io/geekidea/springbootplus/common/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * 公共部分 - * @author geekidea - * @date 2018-11-08 - */ -package io.geekidea.springbootplus.common; \ No newline at end of file diff --git a/src/main/java/io/geekidea/springbootplus/common/web/param/IdParam.java b/src/main/java/io/geekidea/springbootplus/common/param/IdParam.java similarity index 95% rename from src/main/java/io/geekidea/springbootplus/common/web/param/IdParam.java rename to src/main/java/io/geekidea/springbootplus/common/param/IdParam.java index 5da24042..d8126416 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/param/IdParam.java +++ b/src/main/java/io/geekidea/springbootplus/common/param/IdParam.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.web.param; +package io.geekidea.springbootplus.common.param; import io.swagger.annotations.ApiModel; import lombok.Data; diff --git a/src/main/java/io/geekidea/springbootplus/common/web/param/IdStatusParam.java b/src/main/java/io/geekidea/springbootplus/common/param/IdStatusParam.java similarity index 96% rename from src/main/java/io/geekidea/springbootplus/common/web/param/IdStatusParam.java rename to src/main/java/io/geekidea/springbootplus/common/param/IdStatusParam.java index 49038583..eab72401 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/param/IdStatusParam.java +++ b/src/main/java/io/geekidea/springbootplus/common/param/IdStatusParam.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.web.param; +package io.geekidea.springbootplus.common.param; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/src/main/java/io/geekidea/springbootplus/common/web/param/NameParam.java b/src/main/java/io/geekidea/springbootplus/common/param/NameParam.java similarity index 96% rename from src/main/java/io/geekidea/springbootplus/common/web/param/NameParam.java rename to src/main/java/io/geekidea/springbootplus/common/param/NameParam.java index d43a5072..47c52936 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/param/NameParam.java +++ b/src/main/java/io/geekidea/springbootplus/common/param/NameParam.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.web.param; +package io.geekidea.springbootplus.common.param; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/src/main/java/io/geekidea/springbootplus/common/web/param/OrderQueryParam.java b/src/main/java/io/geekidea/springbootplus/common/param/OrderQueryParam.java similarity index 96% rename from src/main/java/io/geekidea/springbootplus/common/web/param/OrderQueryParam.java rename to src/main/java/io/geekidea/springbootplus/common/param/OrderQueryParam.java index 77df968f..bff2701a 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/param/OrderQueryParam.java +++ b/src/main/java/io/geekidea/springbootplus/common/param/OrderQueryParam.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.web.param; +package io.geekidea.springbootplus.common.param; import com.baomidou.mybatisplus.core.metadata.OrderItem; import io.swagger.annotations.ApiModel; diff --git a/src/main/java/io/geekidea/springbootplus/common/web/param/QueryParam.java b/src/main/java/io/geekidea/springbootplus/common/param/QueryParam.java similarity index 97% rename from src/main/java/io/geekidea/springbootplus/common/web/param/QueryParam.java rename to src/main/java/io/geekidea/springbootplus/common/param/QueryParam.java index 6addc339..51bb6592 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/param/QueryParam.java +++ b/src/main/java/io/geekidea/springbootplus/common/param/QueryParam.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.web.param; +package io.geekidea.springbootplus.common.param; import io.geekidea.springbootplus.common.constant.CommonConstant; import io.swagger.annotations.ApiModel; diff --git a/src/main/java/io/geekidea/springbootplus/common/service/impl/BaseServiceImpl.java b/src/main/java/io/geekidea/springbootplus/common/service/impl/BaseServiceImpl.java index ca391f29..7b726bdb 100644 --- a/src/main/java/io/geekidea/springbootplus/common/service/impl/BaseServiceImpl.java +++ b/src/main/java/io/geekidea/springbootplus/common/service/impl/BaseServiceImpl.java @@ -21,8 +21,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import io.geekidea.springbootplus.common.service.BaseService; -import io.geekidea.springbootplus.common.web.param.OrderQueryParam; -import io.geekidea.springbootplus.common.web.param.QueryParam; +import io.geekidea.springbootplus.common.param.OrderQueryParam; +import io.geekidea.springbootplus.common.param.QueryParam; import org.apache.commons.collections.CollectionUtils; import java.util.Arrays; diff --git a/src/main/java/io/geekidea/springbootplus/common/web/vo/CommonIdName.java b/src/main/java/io/geekidea/springbootplus/common/vo/CommonIdName.java similarity index 96% rename from src/main/java/io/geekidea/springbootplus/common/web/vo/CommonIdName.java rename to src/main/java/io/geekidea/springbootplus/common/vo/CommonIdName.java index 6b0197fc..82587eee 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/vo/CommonIdName.java +++ b/src/main/java/io/geekidea/springbootplus/common/vo/CommonIdName.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.web.vo; +package io.geekidea.springbootplus.common.vo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/src/main/java/io/geekidea/springbootplus/common/web/vo/Paging.java b/src/main/java/io/geekidea/springbootplus/common/vo/Paging.java similarity index 97% rename from src/main/java/io/geekidea/springbootplus/common/web/vo/Paging.java rename to src/main/java/io/geekidea/springbootplus/common/vo/Paging.java index 63f3c3f9..80eb7391 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/vo/Paging.java +++ b/src/main/java/io/geekidea/springbootplus/common/vo/Paging.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.web.vo; +package io.geekidea.springbootplus.common.vo; import com.alibaba.fastjson.annotation.JSONField; import com.baomidou.mybatisplus.core.metadata.IPage; diff --git a/src/main/java/io/geekidea/springbootplus/config/package-info.java b/src/main/java/io/geekidea/springbootplus/config/package-info.java deleted file mode 100644 index def6cd80..00000000 --- a/src/main/java/io/geekidea/springbootplus/config/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * 公共配置 - * @author geekidea - * @date 2018-11-08 - */ -package io.geekidea.springbootplus.config; \ No newline at end of file diff --git a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java index ea5ffe87..526e8df9 100644 --- a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java @@ -16,11 +16,11 @@ package io.geekidea.springbootplus.core.config; import io.geekidea.springbootplus.common.aop.LogAop; -import io.geekidea.springbootplus.common.web.interceptor.PermissionInterceptor; +import io.geekidea.springbootplus.common.interceptor.PermissionInterceptor; import io.geekidea.springbootplus.core.properties.*; -import io.geekidea.springbootplus.resource.web.interceptor.DownloadInterceptor; -import io.geekidea.springbootplus.resource.web.interceptor.ResourceInterceptor; -import io.geekidea.springbootplus.resource.web.interceptor.UploadInterceptor; +import io.geekidea.springbootplus.resource.interceptor.DownloadInterceptor; +import io.geekidea.springbootplus.resource.interceptor.ResourceInterceptor; +import io.geekidea.springbootplus.resource.interceptor.UploadInterceptor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.servlet.FilterRegistrationBean; diff --git a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java index 1933d675..cfdb1f42 100644 --- a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java @@ -17,12 +17,12 @@ package io.geekidea.springbootplus.core.config; import com.alibaba.fastjson.JSON; -import io.geekidea.springbootplus.common.web.interceptor.PermissionInterceptor; +import io.geekidea.springbootplus.common.interceptor.PermissionInterceptor; import io.geekidea.springbootplus.core.properties.SpringBootPlusInterceptorProperties; import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; -import io.geekidea.springbootplus.resource.web.interceptor.DownloadInterceptor; -import io.geekidea.springbootplus.resource.web.interceptor.ResourceInterceptor; -import io.geekidea.springbootplus.resource.web.interceptor.UploadInterceptor; +import io.geekidea.springbootplus.resource.interceptor.DownloadInterceptor; +import io.geekidea.springbootplus.resource.interceptor.ResourceInterceptor; +import io.geekidea.springbootplus.resource.interceptor.UploadInterceptor; import io.geekidea.springbootplus.util.IniUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; diff --git a/src/main/java/io/geekidea/springbootplus/resource/web/controller/DownloadController.java b/src/main/java/io/geekidea/springbootplus/resource/controller/DownloadController.java similarity index 97% rename from src/main/java/io/geekidea/springbootplus/resource/web/controller/DownloadController.java rename to src/main/java/io/geekidea/springbootplus/resource/controller/DownloadController.java index 0bf03094..24824762 100644 --- a/src/main/java/io/geekidea/springbootplus/resource/web/controller/DownloadController.java +++ b/src/main/java/io/geekidea/springbootplus/resource/controller/DownloadController.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.resource.web.controller; +package io.geekidea.springbootplus.resource.controller; import io.geekidea.springbootplus.common.api.ApiResult; import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; diff --git a/src/main/java/io/geekidea/springbootplus/resource/web/controller/ResourceController.java b/src/main/java/io/geekidea/springbootplus/resource/controller/ResourceController.java similarity index 96% rename from src/main/java/io/geekidea/springbootplus/resource/web/controller/ResourceController.java rename to src/main/java/io/geekidea/springbootplus/resource/controller/ResourceController.java index 71afbe2b..1413dd3d 100644 --- a/src/main/java/io/geekidea/springbootplus/resource/web/controller/ResourceController.java +++ b/src/main/java/io/geekidea/springbootplus/resource/controller/ResourceController.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.resource.web.controller; +package io.geekidea.springbootplus.resource.controller; import io.geekidea.springbootplus.common.api.ApiResult; import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; diff --git a/src/main/java/io/geekidea/springbootplus/resource/web/controller/UploadController.java b/src/main/java/io/geekidea/springbootplus/resource/controller/UploadController.java similarity index 94% rename from src/main/java/io/geekidea/springbootplus/resource/web/controller/UploadController.java rename to src/main/java/io/geekidea/springbootplus/resource/controller/UploadController.java index 702d80ec..f920f76c 100644 --- a/src/main/java/io/geekidea/springbootplus/resource/web/controller/UploadController.java +++ b/src/main/java/io/geekidea/springbootplus/resource/controller/UploadController.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package io.geekidea.springbootplus.resource.web.controller; +package io.geekidea.springbootplus.resource.controller; import io.geekidea.springbootplus.common.api.ApiResult; -import io.geekidea.springbootplus.common.web.param.IdParam; +import io.geekidea.springbootplus.common.param.IdParam; import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; -import io.geekidea.springbootplus.system.web.vo.SysLogQueryVo; +import io.geekidea.springbootplus.system.vo.SysLogQueryVo; import io.geekidea.springbootplus.util.UploadUtil; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/DownloadInterceptor.java b/src/main/java/io/geekidea/springbootplus/resource/interceptor/DownloadInterceptor.java similarity index 97% rename from src/main/java/io/geekidea/springbootplus/resource/web/interceptor/DownloadInterceptor.java rename to src/main/java/io/geekidea/springbootplus/resource/interceptor/DownloadInterceptor.java index a51e8da3..a2dee017 100644 --- a/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/DownloadInterceptor.java +++ b/src/main/java/io/geekidea/springbootplus/resource/interceptor/DownloadInterceptor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.resource.web.interceptor; +package io.geekidea.springbootplus.resource.interceptor; import io.geekidea.springbootplus.common.api.ApiResult; import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; diff --git a/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/ResourceInterceptor.java b/src/main/java/io/geekidea/springbootplus/resource/interceptor/ResourceInterceptor.java similarity index 97% rename from src/main/java/io/geekidea/springbootplus/resource/web/interceptor/ResourceInterceptor.java rename to src/main/java/io/geekidea/springbootplus/resource/interceptor/ResourceInterceptor.java index 38b0eef1..cdab86ab 100644 --- a/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/ResourceInterceptor.java +++ b/src/main/java/io/geekidea/springbootplus/resource/interceptor/ResourceInterceptor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.resource.web.interceptor; +package io.geekidea.springbootplus.resource.interceptor; import io.geekidea.springbootplus.common.api.ApiResult; import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; diff --git a/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/UploadInterceptor.java b/src/main/java/io/geekidea/springbootplus/resource/interceptor/UploadInterceptor.java similarity index 97% rename from src/main/java/io/geekidea/springbootplus/resource/web/interceptor/UploadInterceptor.java rename to src/main/java/io/geekidea/springbootplus/resource/interceptor/UploadInterceptor.java index bbb99d68..554c7b59 100644 --- a/src/main/java/io/geekidea/springbootplus/resource/web/interceptor/UploadInterceptor.java +++ b/src/main/java/io/geekidea/springbootplus/resource/interceptor/UploadInterceptor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.resource.web.interceptor; +package io.geekidea.springbootplus.resource.interceptor; import io.geekidea.springbootplus.common.api.ApiResult; import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; diff --git a/src/main/java/io/geekidea/springbootplus/resource/package-info.java b/src/main/java/io/geekidea/springbootplus/resource/package-info.java deleted file mode 100644 index 68753d22..00000000 --- a/src/main/java/io/geekidea/springbootplus/resource/package-info.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.geekidea.springbootplus.resource; \ No newline at end of file diff --git a/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java b/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java index 13ea3f91..76bd33a2 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java @@ -17,7 +17,7 @@ package io.geekidea.springbootplus.shiro.config; import com.alibaba.fastjson.JSON; -import io.geekidea.springbootplus.common.web.filter.RequestPathFilter; +import io.geekidea.springbootplus.common.filter.RequestPathFilter; import io.geekidea.springbootplus.core.properties.SpringBootPlusFilterProperties; import io.geekidea.springbootplus.shiro.cache.LoginRedisService; import io.geekidea.springbootplus.shiro.exception.ShiroConfigException; diff --git a/src/main/java/io/geekidea/springbootplus/shiro/controller/LoginController.java b/src/main/java/io/geekidea/springbootplus/shiro/controller/LoginController.java index 76c08381..dee1faa9 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/controller/LoginController.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/controller/LoginController.java @@ -19,7 +19,6 @@ import io.geekidea.springbootplus.common.api.ApiResult; import io.geekidea.springbootplus.shiro.param.LoginParam; import io.geekidea.springbootplus.shiro.service.LoginService; -import io.geekidea.springbootplus.system.web.vo.SysUserQueryVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -48,7 +47,7 @@ public class LoginController { private LoginService loginService; @PostMapping("/login") - @ApiOperation(value = "登陆", notes = "系统用户登陆", response = SysUserQueryVo.class) + @ApiOperation(value = "登陆", notes = "系统用户登陆", response = ApiResult.class) public ApiResult login(@Valid @RequestBody LoginParam loginParam, HttpServletResponse response) { return loginService.login(loginParam, response); } diff --git a/src/main/java/io/geekidea/springbootplus/system/web/controller/HelloWorldController.java b/src/main/java/io/geekidea/springbootplus/system/controller/HelloWorldController.java similarity index 96% rename from src/main/java/io/geekidea/springbootplus/system/web/controller/HelloWorldController.java rename to src/main/java/io/geekidea/springbootplus/system/controller/HelloWorldController.java index f3e7c15a..a2182d43 100644 --- a/src/main/java/io/geekidea/springbootplus/system/web/controller/HelloWorldController.java +++ b/src/main/java/io/geekidea/springbootplus/system/controller/HelloWorldController.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.system.web.controller; +package io.geekidea.springbootplus.system.controller; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/src/main/java/io/geekidea/springbootplus/system/controller/IpController.java b/src/main/java/io/geekidea/springbootplus/system/controller/IpController.java new file mode 100644 index 00000000..7da38b79 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/system/controller/IpController.java @@ -0,0 +1,90 @@ +package io.geekidea.springbootplus.system.controller; + +import io.geekidea.springbootplus.system.entity.Ip; +import io.geekidea.springbootplus.system.service.IpService; +import io.geekidea.springbootplus.system.param.IpQueryParam; +import io.geekidea.springbootplus.system.vo.IpQueryVo; +import io.geekidea.springbootplus.common.api.ApiResult; +import io.geekidea.springbootplus.common.controller.BaseController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +import io.geekidea.springbootplus.common.vo.Paging; +import io.geekidea.springbootplus.common.param.IdParam; + +/** + *

+ * IP地址 前端控制器 + *

+ * + * @author geekidea + * @since 2019-10-11 + */ +@Slf4j +@RestController +@RequestMapping("/ip") +@Api("IP地址 API") +public class IpController extends BaseController { + + @Autowired + private IpService ipService; + + /** + * 添加IP地址 + */ + @PostMapping("/add") + @ApiOperation(value = "添加Ip对象", notes = "添加IP地址", response = ApiResult.class) + public ApiResult addIp( @RequestBody Ip ip) throws Exception { + boolean flag = ipService.save(ip); + return ApiResult.result(flag); + } + + /** + * 修改IP地址 + */ + @PostMapping("/update") + @ApiOperation(value = "修改Ip对象", notes = "修改IP地址", response = ApiResult.class) + public ApiResult updateIp( @RequestBody Ip ip) throws Exception { + boolean flag = ipService.updateById(ip); + return ApiResult.result(flag); + } + + /** + * 删除IP地址 + */ + @PostMapping("/delete") + @ApiOperation(value = "删除Ip对象", notes = "删除IP地址", response = ApiResult.class) + public ApiResult deleteIp( @RequestBody IdParam idParam) throws Exception { + boolean flag = ipService.removeById(idParam.getId()); + return ApiResult.result(flag); + } + + /** + * 获取IP地址 + */ + @PostMapping("/info") + @ApiOperation(value = "获取Ip对象详情", notes = "查看IP地址", response = IpQueryVo.class) + public ApiResult getIp( @RequestBody IdParam idParam) throws Exception { + IpQueryVo ipQueryVo = ipService.getIpById(idParam.getId()); + return ApiResult.ok(ipQueryVo); + } + + /** + * IP地址分页列表 + */ + @PostMapping("/getPageList") + @ApiOperation(value = "获取Ip分页列表", notes = "IP地址分页列表", response = IpQueryVo.class) + public ApiResult> getIpPageList( @RequestBody IpQueryParam ipQueryParam) throws Exception { + Paging paging = ipService.getIpPageList(ipQueryParam); + return ApiResult.ok(paging); + } + +} + diff --git a/src/main/java/io/geekidea/springbootplus/system/web/controller/SysLogController.java b/src/main/java/io/geekidea/springbootplus/system/controller/SysLogController.java similarity index 59% rename from src/main/java/io/geekidea/springbootplus/system/web/controller/SysLogController.java rename to src/main/java/io/geekidea/springbootplus/system/controller/SysLogController.java index eda7ae5f..a1c99fe4 100644 --- a/src/main/java/io/geekidea/springbootplus/system/web/controller/SysLogController.java +++ b/src/main/java/io/geekidea/springbootplus/system/controller/SysLogController.java @@ -1,27 +1,13 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.geekidea.springbootplus.system.web.controller; +package io.geekidea.springbootplus.system.controller; +import io.geekidea.springbootplus.common.api.ApiResult; +import io.geekidea.springbootplus.common.controller.BaseController; +import io.geekidea.springbootplus.common.param.IdParam; +import io.geekidea.springbootplus.common.vo.Paging; import io.geekidea.springbootplus.system.entity.SysLog; +import io.geekidea.springbootplus.system.param.SysLogQueryParam; import io.geekidea.springbootplus.system.service.SysLogService; -import io.geekidea.springbootplus.system.web.param.SysLogQueryParam; -import io.geekidea.springbootplus.system.web.vo.SysLogQueryVo; -import io.geekidea.springbootplus.common.api.ApiResult; -import io.geekidea.springbootplus.common.web.controller.BaseController; +import io.geekidea.springbootplus.system.vo.SysLogQueryVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -33,33 +19,30 @@ import javax.validation.Valid; -import io.geekidea.springbootplus.common.web.vo.Paging; -import io.geekidea.springbootplus.common.web.param.IdParam; - /** *

* 系统日志 前端控制器 *

* * @author geekidea - * @since 2019-10-05 + * @since 2019-10-11 */ @Slf4j @RestController -@RequestMapping("/SysLog") +@RequestMapping("/sysLog") @Api("系统日志 API") public class SysLogController extends BaseController { @Autowired - private SysLogService SysLogService; + private SysLogService sysLogService; /** * 添加系统日志 */ @PostMapping("/add") @ApiOperation(value = "添加SysLog对象", notes = "添加系统日志", response = ApiResult.class) - public ApiResult addSysLog(@Valid @RequestBody SysLog SysLog) throws Exception { - boolean flag = SysLogService.save(SysLog); + public ApiResult addSysLog(@Valid @RequestBody SysLog sysLog) throws Exception { + boolean flag = sysLogService.save(sysLog); return ApiResult.result(flag); } @@ -68,8 +51,8 @@ public ApiResult addSysLog(@Valid @RequestBody SysLog SysLog) throws Ex */ @PostMapping("/update") @ApiOperation(value = "修改SysLog对象", notes = "修改系统日志", response = ApiResult.class) - public ApiResult updateSysLog(@Valid @RequestBody SysLog SysLog) throws Exception { - boolean flag = SysLogService.updateById(SysLog); + public ApiResult updateSysLog(@Valid @RequestBody SysLog sysLog) throws Exception { + boolean flag = sysLogService.updateById(sysLog); return ApiResult.result(flag); } @@ -79,7 +62,7 @@ public ApiResult updateSysLog(@Valid @RequestBody SysLog SysLog) throws @PostMapping("/delete") @ApiOperation(value = "删除SysLog对象", notes = "删除系统日志", response = ApiResult.class) public ApiResult deleteSysLog(@Valid @RequestBody IdParam idParam) throws Exception { - boolean flag = SysLogService.removeById(idParam.getId()); + boolean flag = sysLogService.removeById(idParam.getId()); return ApiResult.result(flag); } @@ -89,8 +72,8 @@ public ApiResult deleteSysLog(@Valid @RequestBody IdParam idParam) thro @PostMapping("/info") @ApiOperation(value = "获取SysLog对象详情", notes = "查看系统日志", response = SysLogQueryVo.class) public ApiResult getSysLog(@Valid @RequestBody IdParam idParam) throws Exception { - SysLogQueryVo SysLogQueryVo = SysLogService.getSysLogById(idParam.getId()); - return ApiResult.ok(SysLogQueryVo); + SysLogQueryVo sysLogQueryVo = sysLogService.getSysLogById(idParam.getId()); + return ApiResult.ok(sysLogQueryVo); } /** @@ -98,8 +81,8 @@ public ApiResult getSysLog(@Valid @RequestBody IdParam idParam) t */ @PostMapping("/getPageList") @ApiOperation(value = "获取SysLog分页列表", notes = "系统日志分页列表", response = SysLogQueryVo.class) - public ApiResult> getSysLogPageList(@Valid @RequestBody(required = false) SysLogQueryParam SysLogQueryParam) throws Exception { - Paging paging = SysLogService.getSysLogPageList(SysLogQueryParam); + public ApiResult> getSysLogPageList(@Valid @RequestBody SysLogQueryParam sysLogQueryParam) throws Exception { + Paging paging = sysLogService.getSysLogPageList(sysLogQueryParam); return ApiResult.ok(paging); } diff --git a/src/main/java/io/geekidea/springbootplus/system/web/controller/SysUserController.java b/src/main/java/io/geekidea/springbootplus/system/controller/SysUserController.java similarity index 58% rename from src/main/java/io/geekidea/springbootplus/system/web/controller/SysUserController.java rename to src/main/java/io/geekidea/springbootplus/system/controller/SysUserController.java index 6133291c..8a02e855 100644 --- a/src/main/java/io/geekidea/springbootplus/system/web/controller/SysUserController.java +++ b/src/main/java/io/geekidea/springbootplus/system/controller/SysUserController.java @@ -1,27 +1,11 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.geekidea.springbootplus.system.web.controller; +package io.geekidea.springbootplus.system.controller; import io.geekidea.springbootplus.system.entity.SysUser; import io.geekidea.springbootplus.system.service.SysUserService; -import io.geekidea.springbootplus.system.web.param.SysUserQueryParam; -import io.geekidea.springbootplus.system.web.vo.SysUserQueryVo; +import io.geekidea.springbootplus.system.param.SysUserQueryParam; +import io.geekidea.springbootplus.system.vo.SysUserQueryVo; import io.geekidea.springbootplus.common.api.ApiResult; -import io.geekidea.springbootplus.common.web.controller.BaseController; +import io.geekidea.springbootplus.common.controller.BaseController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -33,8 +17,8 @@ import javax.validation.Valid; -import io.geekidea.springbootplus.common.web.vo.Paging; -import io.geekidea.springbootplus.common.web.param.IdParam; +import io.geekidea.springbootplus.common.vo.Paging; +import io.geekidea.springbootplus.common.param.IdParam; /** *

@@ -42,24 +26,24 @@ *

* * @author geekidea - * @since 2019-10-05 + * @since 2019-10-11 */ @Slf4j @RestController -@RequestMapping("/SysUser") +@RequestMapping("/sysUser") @Api("SystemUser API") public class SysUserController extends BaseController { @Autowired - private SysUserService SysUserService; + private SysUserService sysUserService; /** * 添加SystemUser */ @PostMapping("/add") @ApiOperation(value = "添加SysUser对象", notes = "添加SystemUser", response = ApiResult.class) - public ApiResult addSysUser(@Valid @RequestBody SysUser SysUser) throws Exception { - boolean flag = SysUserService.save(SysUser); + public ApiResult addSysUser(@Valid @RequestBody SysUser sysUser) throws Exception { + boolean flag = sysUserService.save(sysUser); return ApiResult.result(flag); } @@ -68,8 +52,8 @@ public ApiResult addSysUser(@Valid @RequestBody SysUser SysUser) throws */ @PostMapping("/update") @ApiOperation(value = "修改SysUser对象", notes = "修改SystemUser", response = ApiResult.class) - public ApiResult updateSysUser(@Valid @RequestBody SysUser SysUser) throws Exception { - boolean flag = SysUserService.updateById(SysUser); + public ApiResult updateSysUser(@Valid @RequestBody SysUser sysUser) throws Exception { + boolean flag = sysUserService.updateById(sysUser); return ApiResult.result(flag); } @@ -79,7 +63,7 @@ public ApiResult updateSysUser(@Valid @RequestBody SysUser SysUser) thr @PostMapping("/delete") @ApiOperation(value = "删除SysUser对象", notes = "删除SystemUser", response = ApiResult.class) public ApiResult deleteSysUser(@Valid @RequestBody IdParam idParam) throws Exception { - boolean flag = SysUserService.removeById(idParam.getId()); + boolean flag = sysUserService.removeById(idParam.getId()); return ApiResult.result(flag); } @@ -89,8 +73,8 @@ public ApiResult deleteSysUser(@Valid @RequestBody IdParam idParam) thr @PostMapping("/info") @ApiOperation(value = "获取SysUser对象详情", notes = "查看SystemUser", response = SysUserQueryVo.class) public ApiResult getSysUser(@Valid @RequestBody IdParam idParam) throws Exception { - SysUserQueryVo SysUserQueryVo = SysUserService.getSysUserById(idParam.getId()); - return ApiResult.ok(SysUserQueryVo); + SysUserQueryVo sysUserQueryVo = sysUserService.getSysUserById(idParam.getId()); + return ApiResult.ok(sysUserQueryVo); } /** @@ -98,8 +82,8 @@ public ApiResult getSysUser(@Valid @RequestBody IdParam idParam) */ @PostMapping("/getPageList") @ApiOperation(value = "获取SysUser分页列表", notes = "SystemUser分页列表", response = SysUserQueryVo.class) - public ApiResult> getSysUserPageList(@Valid @RequestBody(required = false) SysUserQueryParam SysUserQueryParam) throws Exception { - Paging paging = SysUserService.getSysUserPageList(SysUserQueryParam); + public ApiResult> getSysUserPageList(@Valid @RequestBody SysUserQueryParam sysUserQueryParam) throws Exception { + Paging paging = sysUserService.getSysUserPageList(sysUserQueryParam); return ApiResult.ok(paging); } diff --git a/src/main/java/io/geekidea/springbootplus/system/entity/Ip.java b/src/main/java/io/geekidea/springbootplus/system/entity/Ip.java index 5f001317..294750d1 100644 --- a/src/main/java/io/geekidea/springbootplus/system/entity/Ip.java +++ b/src/main/java/io/geekidea/springbootplus/system/entity/Ip.java @@ -1,28 +1,13 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package io.geekidea.springbootplus.system.entity; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import io.geekidea.springbootplus.common.entity.BaseEntity; import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + /** *

@@ -30,35 +15,29 @@ *

* * @author geekidea - * @since 2019-08-04 + * @since 2019-10-11 */ @Data +@Accessors(chain = true) @EqualsAndHashCode(callSuper = true) -@ApiModel(value="Ip对象", description="IP地址") +@ApiModel(value = "Ip对象", description = "IP地址") public class Ip extends BaseEntity { private static final long serialVersionUID = 1L; - @ApiModelProperty(value = "ip开始地址") private String ipStart; - @ApiModelProperty(value = "ip结束地址") private String ipEnd; - @ApiModelProperty(value = "区域") private String area; - @ApiModelProperty(value = "运营商") private String operator; - @ApiModelProperty(value = "主键") - @TableId(value = "id", type = IdType.ID_WORKER) + @TableId(value = "id", type = IdType.AUTO) private Long id; - @ApiModelProperty(value = "ip开始地址数字") private Long ipStartNum; - @ApiModelProperty(value = "ip结束地址数字") private Long ipEndNum; } diff --git a/src/main/java/io/geekidea/springbootplus/system/entity/SysLog.java b/src/main/java/io/geekidea/springbootplus/system/entity/SysLog.java index d8c94522..a18906fc 100644 --- a/src/main/java/io/geekidea/springbootplus/system/entity/SysLog.java +++ b/src/main/java/io/geekidea/springbootplus/system/entity/SysLog.java @@ -17,7 +17,6 @@ package io.geekidea.springbootplus.system.entity; import com.baomidou.mybatisplus.annotation.IdType; -import java.util.Date; import com.baomidou.mybatisplus.annotation.TableId; import io.geekidea.springbootplus.common.entity.BaseEntity; import io.swagger.annotations.ApiModel; @@ -26,13 +25,15 @@ import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; +import java.util.Date; + /** *

* 系统日志 *

* * @author geekidea - * @since 2019-10-05 + * @since 2019-10-11 */ @Data @Accessors(chain = true) diff --git a/src/main/java/io/geekidea/springbootplus/system/entity/SysUser.java b/src/main/java/io/geekidea/springbootplus/system/entity/SysUser.java index 8ef9d0b9..845810ba 100644 --- a/src/main/java/io/geekidea/springbootplus/system/entity/SysUser.java +++ b/src/main/java/io/geekidea/springbootplus/system/entity/SysUser.java @@ -1,19 +1,3 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package io.geekidea.springbootplus.system.entity; import com.baomidou.mybatisplus.annotation.IdType; @@ -26,13 +10,16 @@ import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + /** *

* SystemUser *

* * @author geekidea - * @since 2019-10-05 + * @since 2019-10-11 */ @Data @Accessors(chain = true) @@ -47,12 +34,14 @@ public class SysUser extends BaseEntity { private Long id; @ApiModelProperty(value = "用户名") + @NotBlank(message = "用户名不能为空") private String username; @ApiModelProperty(value = "昵称") private String nickname; @ApiModelProperty(value = "密码") + @NotBlank(message = "密码不能为空") private String password; @ApiModelProperty(value = "盐值") diff --git a/src/main/java/io/geekidea/springbootplus/system/mapper/IpMapper.java b/src/main/java/io/geekidea/springbootplus/system/mapper/IpMapper.java index 2644d77e..89e116de 100644 --- a/src/main/java/io/geekidea/springbootplus/system/mapper/IpMapper.java +++ b/src/main/java/io/geekidea/springbootplus/system/mapper/IpMapper.java @@ -1,34 +1,42 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package io.geekidea.springbootplus.system.mapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import io.geekidea.springbootplus.system.entity.Ip; +import io.geekidea.springbootplus.system.param.IpQueryParam; +import io.geekidea.springbootplus.system.vo.IpQueryVo; +import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; +import java.io.Serializable; + /** *

* IP地址 Mapper 接口 *

* * @author geekidea - * @since 2019-08-04 + * @since 2019-10-11 */ @Repository public interface IpMapper extends BaseMapper { + /** + * 根据ID获取查询对象 + * + * @param id + * @return + */ + IpQueryVo getIpById(Serializable id); + + /** + * 获取分页对象 + * + * @param page + * @param ipQueryParam + * @return + */ + IPage getIpPageList(@Param("page") Page page, @Param("param") IpQueryParam ipQueryParam); + } diff --git a/src/main/java/io/geekidea/springbootplus/system/mapper/SysLogMapper.java b/src/main/java/io/geekidea/springbootplus/system/mapper/SysLogMapper.java index 96f62c5b..3f3d7545 100644 --- a/src/main/java/io/geekidea/springbootplus/system/mapper/SysLogMapper.java +++ b/src/main/java/io/geekidea/springbootplus/system/mapper/SysLogMapper.java @@ -1,27 +1,11 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package io.geekidea.springbootplus.system.mapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import io.geekidea.springbootplus.system.entity.SysLog; -import io.geekidea.springbootplus.system.web.param.SysLogQueryParam; -import io.geekidea.springbootplus.system.web.vo.SysLogQueryVo; +import io.geekidea.springbootplus.system.param.SysLogQueryParam; +import io.geekidea.springbootplus.system.vo.SysLogQueryVo; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -33,7 +17,7 @@ *

* * @author geekidea - * @since 2019-10-05 + * @since 2019-10-11 */ @Repository public interface SysLogMapper extends BaseMapper { @@ -50,9 +34,9 @@ public interface SysLogMapper extends BaseMapper { * 获取分页对象 * * @param page - * @param SysLogQueryParam + * @param sysLogQueryParam * @return */ - IPage getSysLogPageList(@Param("page") Page page, @Param("param") SysLogQueryParam SysLogQueryParam); + IPage getSysLogPageList(@Param("page") Page page, @Param("param") SysLogQueryParam sysLogQueryParam); } diff --git a/src/main/java/io/geekidea/springbootplus/system/mapper/SysUserMapper.java b/src/main/java/io/geekidea/springbootplus/system/mapper/SysUserMapper.java index 1a722417..4c61698c 100644 --- a/src/main/java/io/geekidea/springbootplus/system/mapper/SysUserMapper.java +++ b/src/main/java/io/geekidea/springbootplus/system/mapper/SysUserMapper.java @@ -1,28 +1,11 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package io.geekidea.springbootplus.system.mapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import io.geekidea.springbootplus.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.system.entity.SysUser; -import io.geekidea.springbootplus.system.web.param.SysUserQueryParam; -import io.geekidea.springbootplus.system.web.vo.SysUserQueryVo; +import io.geekidea.springbootplus.system.param.SysUserQueryParam; +import io.geekidea.springbootplus.system.vo.SysUserQueryVo; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -34,7 +17,7 @@ *

* * @author geekidea - * @since 2019-10-05 + * @since 2019-10-11 */ @Repository public interface SysUserMapper extends BaseMapper { @@ -51,10 +34,10 @@ public interface SysUserMapper extends BaseMapper { * 获取分页对象 * * @param page - * @param SysUserQueryParam + * @param sysUserQueryParam * @return */ - IPage getSysUserPageList(@Param("page") Page page, @Param("param") SysUserQueryParam SysUserQueryParam); + IPage getSysUserPageList(@Param("page") Page page, @Param("param") SysUserQueryParam sysUserQueryParam); /** * 根据用户名获取用户信息 diff --git a/src/main/java/io/geekidea/springbootplus/system/param/IpQueryParam.java b/src/main/java/io/geekidea/springbootplus/system/param/IpQueryParam.java new file mode 100644 index 00000000..3976fd24 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/system/param/IpQueryParam.java @@ -0,0 +1,24 @@ +package io.geekidea.springbootplus.system.param; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import io.geekidea.springbootplus.common.param.QueryParam; + +/** + *

+ * IP地址 查询参数对象 + *

+ * + * @author geekidea + * @date 2019-10-11 + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = true) +@ApiModel(value = "IpQueryParam对象", description = "IP地址查询参数") +public class IpQueryParam extends QueryParam { + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/io/geekidea/springbootplus/system/param/SysLogQueryParam.java b/src/main/java/io/geekidea/springbootplus/system/param/SysLogQueryParam.java new file mode 100644 index 00000000..d2d3c55b --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/system/param/SysLogQueryParam.java @@ -0,0 +1,24 @@ +package io.geekidea.springbootplus.system.param; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import io.geekidea.springbootplus.common.param.QueryParam; + +/** + *

+ * 系统日志 查询参数对象 + *

+ * + * @author geekidea + * @date 2019-10-11 + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = true) +@ApiModel(value = "SysLogQueryParam对象", description = "系统日志查询参数") +public class SysLogQueryParam extends QueryParam { + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/io/geekidea/springbootplus/system/param/SysUserQueryParam.java b/src/main/java/io/geekidea/springbootplus/system/param/SysUserQueryParam.java new file mode 100644 index 00000000..fb8bea68 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/system/param/SysUserQueryParam.java @@ -0,0 +1,24 @@ +package io.geekidea.springbootplus.system.param; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import io.geekidea.springbootplus.common.param.QueryParam; + +/** + *

+ * SystemUser 查询参数对象 + *

+ * + * @author geekidea + * @date 2019-10-11 + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = true) +@ApiModel(value = "SysUserQueryParam对象", description = "SystemUser查询参数") +public class SysUserQueryParam extends QueryParam { + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/io/geekidea/springbootplus/system/service/IpService.java b/src/main/java/io/geekidea/springbootplus/system/service/IpService.java index 1d42c944..2e0ba43f 100644 --- a/src/main/java/io/geekidea/springbootplus/system/service/IpService.java +++ b/src/main/java/io/geekidea/springbootplus/system/service/IpService.java @@ -1,23 +1,12 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package io.geekidea.springbootplus.system.service; -import io.geekidea.springbootplus.common.service.BaseService; import io.geekidea.springbootplus.system.entity.Ip; +import io.geekidea.springbootplus.common.service.BaseService; +import io.geekidea.springbootplus.system.param.IpQueryParam; +import io.geekidea.springbootplus.system.vo.IpQueryVo; +import io.geekidea.springbootplus.common.vo.Paging; + +import java.io.Serializable; /** *

@@ -25,9 +14,24 @@ *

* * @author geekidea - * @since 2019-08-04 + * @since 2019-10-11 */ public interface IpService extends BaseService { + /** + * 根据ID获取查询对象 + * + * @param id + * @return + */ + IpQueryVo getIpById(Serializable id) throws Exception; + + /** + * 获取分页对象 + * + * @param ipQueryParam + * @return + */ + Paging getIpPageList(IpQueryParam ipQueryParam) throws Exception; } diff --git a/src/main/java/io/geekidea/springbootplus/system/service/SysLogService.java b/src/main/java/io/geekidea/springbootplus/system/service/SysLogService.java index 70869ad8..f1cc9b82 100644 --- a/src/main/java/io/geekidea/springbootplus/system/service/SysLogService.java +++ b/src/main/java/io/geekidea/springbootplus/system/service/SysLogService.java @@ -1,26 +1,10 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package io.geekidea.springbootplus.system.service; import io.geekidea.springbootplus.system.entity.SysLog; import io.geekidea.springbootplus.common.service.BaseService; -import io.geekidea.springbootplus.system.web.param.SysLogQueryParam; -import io.geekidea.springbootplus.system.web.vo.SysLogQueryVo; -import io.geekidea.springbootplus.common.web.vo.Paging; +import io.geekidea.springbootplus.system.param.SysLogQueryParam; +import io.geekidea.springbootplus.system.vo.SysLogQueryVo; +import io.geekidea.springbootplus.common.vo.Paging; import java.io.Serializable; @@ -30,7 +14,7 @@ *

* * @author geekidea - * @since 2019-10-05 + * @since 2019-10-11 */ public interface SysLogService extends BaseService { @@ -45,9 +29,9 @@ public interface SysLogService extends BaseService { /** * 获取分页对象 * - * @param SysLogQueryParam + * @param sysLogQueryParam * @return */ - Paging getSysLogPageList(SysLogQueryParam SysLogQueryParam) throws Exception; + Paging getSysLogPageList(SysLogQueryParam sysLogQueryParam) throws Exception; } diff --git a/src/main/java/io/geekidea/springbootplus/system/service/SysUserService.java b/src/main/java/io/geekidea/springbootplus/system/service/SysUserService.java index c328ca30..c9622aa9 100644 --- a/src/main/java/io/geekidea/springbootplus/system/service/SysUserService.java +++ b/src/main/java/io/geekidea/springbootplus/system/service/SysUserService.java @@ -1,26 +1,10 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package io.geekidea.springbootplus.system.service; import io.geekidea.springbootplus.system.entity.SysUser; import io.geekidea.springbootplus.common.service.BaseService; -import io.geekidea.springbootplus.system.web.param.SysUserQueryParam; -import io.geekidea.springbootplus.system.web.vo.SysUserQueryVo; -import io.geekidea.springbootplus.common.web.vo.Paging; +import io.geekidea.springbootplus.system.param.SysUserQueryParam; +import io.geekidea.springbootplus.system.vo.SysUserQueryVo; +import io.geekidea.springbootplus.common.vo.Paging; import java.io.Serializable; @@ -30,7 +14,7 @@ *

* * @author geekidea - * @since 2019-10-05 + * @since 2019-10-11 */ public interface SysUserService extends BaseService { @@ -45,9 +29,9 @@ public interface SysUserService extends BaseService { /** * 获取分页对象 * - * @param SysUserQueryParam + * @param sysUserQueryParam * @return */ - Paging getSysUserPageList(SysUserQueryParam SysUserQueryParam) throws Exception; + Paging getSysUserPageList(SysUserQueryParam sysUserQueryParam) throws Exception; } diff --git a/src/main/java/io/geekidea/springbootplus/system/service/impl/IpServiceImpl.java b/src/main/java/io/geekidea/springbootplus/system/service/impl/IpServiceImpl.java index c960c9d8..26c3052c 100644 --- a/src/main/java/io/geekidea/springbootplus/system/service/impl/IpServiceImpl.java +++ b/src/main/java/io/geekidea/springbootplus/system/service/impl/IpServiceImpl.java @@ -1,29 +1,21 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package io.geekidea.springbootplus.system.service.impl; -import io.geekidea.springbootplus.common.service.impl.BaseServiceImpl; import io.geekidea.springbootplus.system.entity.Ip; import io.geekidea.springbootplus.system.mapper.IpMapper; import io.geekidea.springbootplus.system.service.IpService; +import io.geekidea.springbootplus.system.param.IpQueryParam; +import io.geekidea.springbootplus.system.vo.IpQueryVo; +import io.geekidea.springbootplus.common.service.impl.BaseServiceImpl; +import io.geekidea.springbootplus.common.vo.Paging; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.beans.factory.annotation.Autowired; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import java.io.Serializable; /** @@ -32,15 +24,26 @@ *

* * @author geekidea - * @since 2019-08-04 + * @since 2019-10-11 */ +@Slf4j @Service @Transactional(rollbackFor = Exception.class) -@Slf4j public class IpServiceImpl extends BaseServiceImpl implements IpService { @Autowired private IpMapper ipMapper; + @Override + public IpQueryVo getIpById(Serializable id) throws Exception { + return ipMapper.getIpById(id); + } + + @Override + public Paging getIpPageList(IpQueryParam ipQueryParam) throws Exception { + Page page = setPageParam(ipQueryParam, OrderItem.desc("create_time")); + IPage iPage = ipMapper.getIpPageList(page, ipQueryParam); + return new Paging(iPage); + } } diff --git a/src/main/java/io/geekidea/springbootplus/system/service/impl/SysLogServiceImpl.java b/src/main/java/io/geekidea/springbootplus/system/service/impl/SysLogServiceImpl.java index 9c325627..fc4e0432 100644 --- a/src/main/java/io/geekidea/springbootplus/system/service/impl/SysLogServiceImpl.java +++ b/src/main/java/io/geekidea/springbootplus/system/service/impl/SysLogServiceImpl.java @@ -1,28 +1,12 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package io.geekidea.springbootplus.system.service.impl; import io.geekidea.springbootplus.system.entity.SysLog; import io.geekidea.springbootplus.system.mapper.SysLogMapper; import io.geekidea.springbootplus.system.service.SysLogService; -import io.geekidea.springbootplus.system.web.param.SysLogQueryParam; -import io.geekidea.springbootplus.system.web.vo.SysLogQueryVo; +import io.geekidea.springbootplus.system.param.SysLogQueryParam; +import io.geekidea.springbootplus.system.vo.SysLogQueryVo; import io.geekidea.springbootplus.common.service.impl.BaseServiceImpl; -import io.geekidea.springbootplus.common.web.vo.Paging; +import io.geekidea.springbootplus.common.vo.Paging; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -40,7 +24,7 @@ *

* * @author geekidea - * @since 2019-10-05 + * @since 2019-10-11 */ @Slf4j @Service @@ -48,17 +32,17 @@ public class SysLogServiceImpl extends BaseServiceImpl implements SysLogService { @Autowired - private SysLogMapper SysLogMapper; + private SysLogMapper sysLogMapper; @Override public SysLogQueryVo getSysLogById(Serializable id) throws Exception { - return SysLogMapper.getSysLogById(id); + return sysLogMapper.getSysLogById(id); } @Override - public Paging getSysLogPageList(SysLogQueryParam SysLogQueryParam) throws Exception { - Page page = setPageParam(SysLogQueryParam, OrderItem.desc("create_time")); - IPage iPage = SysLogMapper.getSysLogPageList(page, SysLogQueryParam); + public Paging getSysLogPageList(SysLogQueryParam sysLogQueryParam) throws Exception { + Page page = setPageParam(sysLogQueryParam, OrderItem.desc("create_time")); + IPage iPage = sysLogMapper.getSysLogPageList(page, sysLogQueryParam); return new Paging(iPage); } diff --git a/src/main/java/io/geekidea/springbootplus/system/service/impl/SysUserServiceImpl.java b/src/main/java/io/geekidea/springbootplus/system/service/impl/SysUserServiceImpl.java index 3a59640b..0b3bb866 100644 --- a/src/main/java/io/geekidea/springbootplus/system/service/impl/SysUserServiceImpl.java +++ b/src/main/java/io/geekidea/springbootplus/system/service/impl/SysUserServiceImpl.java @@ -1,28 +1,12 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package io.geekidea.springbootplus.system.service.impl; import io.geekidea.springbootplus.system.entity.SysUser; import io.geekidea.springbootplus.system.mapper.SysUserMapper; import io.geekidea.springbootplus.system.service.SysUserService; -import io.geekidea.springbootplus.system.web.param.SysUserQueryParam; -import io.geekidea.springbootplus.system.web.vo.SysUserQueryVo; +import io.geekidea.springbootplus.system.param.SysUserQueryParam; +import io.geekidea.springbootplus.system.vo.SysUserQueryVo; import io.geekidea.springbootplus.common.service.impl.BaseServiceImpl; -import io.geekidea.springbootplus.common.web.vo.Paging; +import io.geekidea.springbootplus.common.vo.Paging; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -40,7 +24,7 @@ *

* * @author geekidea - * @since 2019-10-05 + * @since 2019-10-11 */ @Slf4j @Service @@ -48,17 +32,17 @@ public class SysUserServiceImpl extends BaseServiceImpl implements SysUserService { @Autowired - private SysUserMapper SysUserMapper; + private SysUserMapper sysUserMapper; @Override public SysUserQueryVo getSysUserById(Serializable id) throws Exception { - return SysUserMapper.getSysUserById(id); + return sysUserMapper.getSysUserById(id); } @Override - public Paging getSysUserPageList(SysUserQueryParam SysUserQueryParam) throws Exception { - Page page = setPageParam(SysUserQueryParam, OrderItem.desc("create_time")); - IPage iPage = SysUserMapper.getSysUserPageList(page, SysUserQueryParam); + public Paging getSysUserPageList(SysUserQueryParam sysUserQueryParam) throws Exception { + Page page = setPageParam(sysUserQueryParam, OrderItem.desc("create_time")); + IPage iPage = sysUserMapper.getSysUserPageList(page, sysUserQueryParam); return new Paging(iPage); } diff --git a/src/main/java/io/geekidea/springbootplus/system/vo/IpQueryVo.java b/src/main/java/io/geekidea/springbootplus/system/vo/IpQueryVo.java new file mode 100644 index 00000000..77986a44 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/system/vo/IpQueryVo.java @@ -0,0 +1,39 @@ +package io.geekidea.springbootplus.system.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; +import java.io.Serializable; + +import java.util.Date; + +/** + *

+ * IP地址 查询结果对象 + *

+ * + * @author geekidea + * @date 2019-10-11 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "IpQueryVo对象", description = "IP地址查询参数") +public class IpQueryVo implements Serializable { + private static final long serialVersionUID = 1L; + +private String ipStart; + +private String ipEnd; + +private String area; + +private String operator; + +private Long id; + +private Long ipStartNum; + +private Long ipEndNum; + +} \ No newline at end of file diff --git a/src/main/java/io/geekidea/springbootplus/system/web/vo/SysLogQueryVo.java b/src/main/java/io/geekidea/springbootplus/system/vo/SysLogQueryVo.java similarity index 55% rename from src/main/java/io/geekidea/springbootplus/system/web/vo/SysLogQueryVo.java rename to src/main/java/io/geekidea/springbootplus/system/vo/SysLogQueryVo.java index 1106f903..423c646b 100644 --- a/src/main/java/io/geekidea/springbootplus/system/web/vo/SysLogQueryVo.java +++ b/src/main/java/io/geekidea/springbootplus/system/vo/SysLogQueryVo.java @@ -1,20 +1,4 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.geekidea.springbootplus.system.web.vo; +package io.geekidea.springbootplus.system.vo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -30,7 +14,7 @@ *

* * @author geekidea - * @date 2019-10-05 + * @date 2019-10-11 */ @Data @Accessors(chain = true) diff --git a/src/main/java/io/geekidea/springbootplus/system/web/vo/SysUserQueryVo.java b/src/main/java/io/geekidea/springbootplus/system/vo/SysUserQueryVo.java similarity index 62% rename from src/main/java/io/geekidea/springbootplus/system/web/vo/SysUserQueryVo.java rename to src/main/java/io/geekidea/springbootplus/system/vo/SysUserQueryVo.java index 574b2dd4..4b16b434 100644 --- a/src/main/java/io/geekidea/springbootplus/system/web/vo/SysUserQueryVo.java +++ b/src/main/java/io/geekidea/springbootplus/system/vo/SysUserQueryVo.java @@ -1,26 +1,9 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.geekidea.springbootplus.system.web.vo; +package io.geekidea.springbootplus.system.vo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; - import java.io.Serializable; import java.util.Date; @@ -31,7 +14,7 @@ *

* * @author geekidea - * @date 2019-10-05 + * @date 2019-10-11 */ @Data @Accessors(chain = true) diff --git a/src/main/java/io/geekidea/springbootplus/system/web/param/SysLogQueryParam.java b/src/main/java/io/geekidea/springbootplus/system/web/param/SysLogQueryParam.java deleted file mode 100644 index f23755be..00000000 --- a/src/main/java/io/geekidea/springbootplus/system/web/param/SysLogQueryParam.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.geekidea.springbootplus.system.web.param; - -import io.swagger.annotations.ApiModel; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; - -import io.geekidea.springbootplus.common.web.param.QueryParam; - -/** - *

- * 系统日志 查询参数对象 - *

- * - * @author geekidea - * @date 2019-10-05 - */ -@Data -@Accessors(chain = true) -@EqualsAndHashCode(callSuper = true) -@ApiModel(value = "SysLogQueryParam对象", description = "系统日志查询参数") -public class SysLogQueryParam extends QueryParam { - private static final long serialVersionUID = 1L; -} diff --git a/src/main/java/io/geekidea/springbootplus/system/web/param/SysUserQueryParam.java b/src/main/java/io/geekidea/springbootplus/system/web/param/SysUserQueryParam.java deleted file mode 100644 index 8ec57d78..00000000 --- a/src/main/java/io/geekidea/springbootplus/system/web/param/SysUserQueryParam.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.geekidea.springbootplus.system.web.param; - -import io.swagger.annotations.ApiModel; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; - -import io.geekidea.springbootplus.common.web.param.QueryParam; - -/** - *

- * SystemUser 查询参数对象 - *

- * - * @author geekidea - * @date 2019-10-05 - */ -@Data -@Accessors(chain = true) -@EqualsAndHashCode(callSuper = true) -@ApiModel(value = "SysUserQueryParam对象", description = "SystemUser查询参数") -public class SysUserQueryParam extends QueryParam { - private static final long serialVersionUID = 1L; -} diff --git a/src/main/java/io/geekidea/springbootplus/system/web/vo/IpQueryVo.java b/src/main/java/io/geekidea/springbootplus/system/web/vo/IpQueryVo.java deleted file mode 100644 index 1150cae7..00000000 --- a/src/main/java/io/geekidea/springbootplus/system/web/vo/IpQueryVo.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.geekidea.springbootplus.system.web.vo; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import java.io.Serializable; - -/** - *

- * IP地址 查询结果对象 - *

- * - * @author geekidea - * @date 2019-08-04 - */ -@Data -@ApiModel(value="IpQueryVo对象", description="IP地址查询参数") -public class IpQueryVo implements Serializable{ - - private static final long serialVersionUID = 1L; - - @ApiModelProperty(value = "ip开始地址") - private String ipStart; - - @ApiModelProperty(value = "ip结束地址") - private String ipEnd; - - @ApiModelProperty(value = "区域") - private String area; - - @ApiModelProperty(value = "运营商") - private String operator; - - @ApiModelProperty(value = "主键") - private Long id; - - @ApiModelProperty(value = "ip开始地址数字") - private Long ipStartNum; - - @ApiModelProperty(value = "ip结束地址数字") - private Long ipEndNum; - -} \ No newline at end of file diff --git a/src/main/resources/mapper/system/IpMapper.xml b/src/main/resources/mapper/system/IpMapper.xml index 58ba5df5..24ebdfa9 100644 --- a/src/main/resources/mapper/system/IpMapper.xml +++ b/src/main/resources/mapper/system/IpMapper.xml @@ -1,20 +1,4 @@ - - @@ -23,5 +7,16 @@ ip_start, ip_end, area, operator, id, ip_start_num, ip_end_num + + + diff --git a/src/main/resources/mapper/system/SysLogMapper.xml b/src/main/resources/mapper/system/SysLogMapper.xml index e66f8b64..aa52bdaf 100644 --- a/src/main/resources/mapper/system/SysLogMapper.xml +++ b/src/main/resources/mapper/system/SysLogMapper.xml @@ -1,20 +1,4 @@ - - @@ -23,13 +7,13 @@ log_id, type, content, create_id, create_time - select from sys_log where log_id = #{id} - select from sys_log diff --git a/src/main/resources/mapper/system/SysUserMapper.xml b/src/main/resources/mapper/system/SysUserMapper.xml index f553450a..cccade90 100644 --- a/src/main/resources/mapper/system/SysUserMapper.xml +++ b/src/main/resources/mapper/system/SysUserMapper.xml @@ -1,20 +1,4 @@ - - @@ -23,13 +7,13 @@ id, username, nickname, password, salt, remark, status, create_time, update_time - select from sys_user where id = #{id} - select from sys_user diff --git a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java index b9db8dab..fbd84be9 100644 --- a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java +++ b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java @@ -54,18 +54,18 @@ public class CodeGenerator { // 父类包路径 private static final String SUPER_ENTITY = COMMON_PARENT_PACKAGE + ".entity.BaseEntity"; - private static final String SUPER_CONTROLLER = COMMON_PARENT_PACKAGE + ".web.controller.BaseController"; + private static final String SUPER_CONTROLLER = COMMON_PARENT_PACKAGE + ".controller.BaseController"; private static final String SUPER_SERVICE = COMMON_PARENT_PACKAGE + ".service.BaseService"; private static final String SUPER_SERVICE_IMPL = COMMON_PARENT_PACKAGE + ".service.impl.BaseServiceImpl"; - private static final String SUPER_QUERY_PARAM = COMMON_PARENT_PACKAGE + ".web.param.QueryParam"; + private static final String SUPER_QUERY_PARAM = COMMON_PARENT_PACKAGE + ".param.QueryParam"; private static final String[] SUPER_ENTITY_COMMON_COLUMNS = new String[]{}; // 公共类包路径 - private static final String COMMON_ID_PARAM = COMMON_PARENT_PACKAGE + ".web.param.IdParam"; + private static final String COMMON_ID_PARAM = COMMON_PARENT_PACKAGE + ".param.IdParam"; private static final String COMMON_API_RESULT = COMMON_PARENT_PACKAGE + ".api.ApiResult"; private static final String COMMON_ORDER_ENUM = COMMON_PARENT_PACKAGE + ".enums.OrderEnum"; - private static final String COMMON_ORDER_QUERY_PARAM = COMMON_PARENT_PACKAGE + ".web.param.OrderQueryParam"; - private static final String COMMON_PAGING = COMMON_PARENT_PACKAGE + ".web.vo.Paging"; + private static final String COMMON_ORDER_QUERY_PARAM = COMMON_PARENT_PACKAGE + ".param.OrderQueryParam"; + private static final String COMMON_PAGING = COMMON_PARENT_PACKAGE + ".vo.Paging"; // ############################ 配置部分 start ############################ @@ -74,7 +74,7 @@ public class CodeGenerator { // 作者 private static final String AUTHOR = "geekidea"; // 生成的表名称 - private static final String TABLE_NAME = "sys_role"; + private static final String TABLE_NAME = "hello"; // 主键数据库列名称 private static final String PK_ID_COLUMN_NAME = "id"; // 代码生成策略 true:All/false:SIMPLE @@ -82,7 +82,7 @@ public class CodeGenerator { // 分页列表查询是否排序 true:有排序参数/false:无 private static final boolean PAGE_LIST_ORDER = false; // 是否生成validation校验,true:生成/false:不生成 - private static final boolean PARAM_VALIDATION = true; + private static final boolean PARAM_VALIDATION = false; // 生成文件配置,是否生成entity/controller/service/serviceImpl/mapper/xml private static final boolean GENERATOR_ENTITY = true; From fa3f1e668034ad41e599f590a48c36586d0dd09a Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Sat, 12 Oct 2019 09:51:08 +0800 Subject: [PATCH 10/21] =?UTF-8?q?:tiger:=20/ip,/sysLog=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=8E=88=E6=9D=83=EF=BC=8C=E9=BB=98=E8=AE=A4=E4=BD=BF=E7=94=A8?= =?UTF-8?q?Validation=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/config/application.yml | 2 ++ .../java/io/geekidea/springbootplus/test/CodeGenerator.java | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 1d3244ad..935a8b70 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -120,6 +120,8 @@ spring-boot-plus: /templates/**=anon /druid/**=anon /hello/world=anon + /ip/**=anon + /sysLog/**=anon /xss/**=anon # 权限配置 permission: diff --git a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java index fbd84be9..d80d8847 100644 --- a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java +++ b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java @@ -67,6 +67,8 @@ public class CodeGenerator { private static final String COMMON_ORDER_QUERY_PARAM = COMMON_PARENT_PACKAGE + ".param.OrderQueryParam"; private static final String COMMON_PAGING = COMMON_PARENT_PACKAGE + ".vo.Paging"; + // 包名称 + private static final String PACKAGE_CONTROLLER= "controller"; // ############################ 配置部分 start ############################ // 模块名称 @@ -82,7 +84,7 @@ public class CodeGenerator { // 分页列表查询是否排序 true:有排序参数/false:无 private static final boolean PAGE_LIST_ORDER = false; // 是否生成validation校验,true:生成/false:不生成 - private static final boolean PARAM_VALIDATION = false; + private static final boolean PARAM_VALIDATION = true; // 生成文件配置,是否生成entity/controller/service/serviceImpl/mapper/xml private static final boolean GENERATOR_ENTITY = true; @@ -130,7 +132,7 @@ public static void main(String[] args) { PackageConfig pc = new PackageConfig(); pc.setModuleName(MODULE_NAME); pc.setParent(PARENT_PACKAGE); - pc.setController("controller"); + pc.setController(PACKAGE_CONTROLLER); mpg.setPackageInfo(pc); From 0628344dcea1a5ad6b2610da12117a89abea5f98 Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Sat, 12 Oct 2019 10:26:07 +0800 Subject: [PATCH 11/21] =?UTF-8?q?:tiger:=20=E5=8D=87=E7=BA=A7fastjson=201.?= =?UTF-8?q?2.62?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 15 ++++++++------- src/main/resources/config/application.yml | 1 - 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index f1c9a802..ac3d4507 100644 --- a/pom.xml +++ b/pom.xml @@ -47,29 +47,29 @@ ${utf8} 1.8 2.1.9.RELEASE + 2.1.6 3.2.0 - 1.2.60 2.6.1 3.9 4.4 + 2.6 + 1.13 + 3.6 + 2.7.0 + 1.8 + 1.2.62 1.7 5.1.47 1.1.20 - 2.6 0.9.11 - 1.13 - 3.6 1.18 1.18.8 - 2.7.0 - 2.1.6 4.6.4 4.12 0.5.4 1.3.0.Final 1.4.1 3.8.3 - 1.8 3.8.1 3.1.0 @@ -495,6 +495,7 @@ Spring Milestones https://maven.aliyun.com/repository/spring + central maven-central diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 935a8b70..5e375125 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -122,7 +122,6 @@ spring-boot-plus: /hello/world=anon /ip/**=anon /sysLog/**=anon - /xss/**=anon # 权限配置 permission: # 排除登陆登出相关 From 8713d5ab386a756dba3f45d0a2ef0a2aa98c843e Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Sun, 13 Oct 2019 12:12:22 +0800 Subject: [PATCH 12/21] =?UTF-8?q?:tiger:=20fix=20springbootadmin=20xss=20j?= =?UTF-8?q?son=E5=BA=8F=E5=88=97=E5=8C=96=E9=97=AE=E9=A2=98=EF=BC=8Caop/fi?= =?UTF-8?q?lter/interceptor=E5=8C=85=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 11 +++-- .../SpringBootPlusApplication.java | 3 +- .../{common => }/aop/LogAop.java | 2 +- .../common/constraints/Email.java | 45 ------------------- .../common/constraints/EmailValidator.java | 43 ------------------ .../common/constraints/EnumType.java | 2 +- .../common/param/QueryParam.java | 2 +- .../config/json/jackson/JacksonConfig.java | 5 +-- .../JacksonLocalDateTimeDeserializer.java | 2 +- .../serializer/JacksonDateSerializer.java | 10 +++-- .../JacksonLocalDateTimeSerializer.java | 12 ++--- .../{common => }/constant/CacheKey.java | 2 +- .../{common => }/constant/CommonConstant.java | 2 +- .../{common => }/constant/CommonRedisKey.java | 2 +- .../{common => }/constant/DatePattern.java | 2 +- .../core/config/SpringBootPlusConfig.java | 4 +- .../config/SpringBootPlusWebMvcConfig.java | 2 +- .../filter/RequestPathFilter.java | 2 +- .../interceptor/PermissionInterceptor.java | 2 +- .../cache/impl/LoginRedisServiceImpl.java | 2 +- .../shiro/config/ShiroConfig.java | 2 +- .../shiro/jwt/JwtProperties.java | 2 +- .../shiro/service/impl/LoginServiceImpl.java | 2 +- .../springbootplus/shiro/util/JwtUtil.java | 2 +- .../springbootplus/shiro/util/LoginUtil.java | 2 +- .../springbootplus/xss/XssFilter.java | 3 +- .../xss/XssJacksonSerializer.java | 8 ++-- src/main/resources/config/application.yml | 5 ++- .../test/RedisTemplateTest.java | 2 +- 29 files changed, 49 insertions(+), 136 deletions(-) rename src/main/java/io/geekidea/springbootplus/{common => }/aop/LogAop.java (99%) delete mode 100644 src/main/java/io/geekidea/springbootplus/common/constraints/Email.java delete mode 100644 src/main/java/io/geekidea/springbootplus/common/constraints/EmailValidator.java rename src/main/java/io/geekidea/springbootplus/{common => }/constant/CacheKey.java (92%) rename src/main/java/io/geekidea/springbootplus/{common => }/constant/CommonConstant.java (97%) rename src/main/java/io/geekidea/springbootplus/{common => }/constant/CommonRedisKey.java (95%) rename src/main/java/io/geekidea/springbootplus/{common => }/constant/DatePattern.java (96%) rename src/main/java/io/geekidea/springbootplus/{common => }/filter/RequestPathFilter.java (98%) rename src/main/java/io/geekidea/springbootplus/{common => }/interceptor/PermissionInterceptor.java (96%) diff --git a/pom.xml b/pom.xml index ac3d4507..e9fa05a1 100644 --- a/pom.xml +++ b/pom.xml @@ -260,12 +260,11 @@ - - - - - - + + de.codecentric + spring-boot-admin-starter-client + ${spring-boot-admin.version} + diff --git a/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java b/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java index 61faf58c..7b73d33b 100644 --- a/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java +++ b/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java @@ -16,6 +16,7 @@ package io.geekidea.springbootplus; +import de.codecentric.boot.admin.server.config.EnableAdminServer; import io.geekidea.springbootplus.util.PrintApplicationInfo; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; @@ -37,7 +38,7 @@ @EnableScheduling @EnableTransactionManagement @EnableConfigurationProperties -//@EnableAdminServer +@EnableAdminServer @MapperScan({"io.geekidea.springbootplus.**.mapper"}) @ServletComponentScan @SpringBootApplication diff --git a/src/main/java/io/geekidea/springbootplus/common/aop/LogAop.java b/src/main/java/io/geekidea/springbootplus/aop/LogAop.java similarity index 99% rename from src/main/java/io/geekidea/springbootplus/common/aop/LogAop.java rename to src/main/java/io/geekidea/springbootplus/aop/LogAop.java index 3429bc06..9251a97f 100644 --- a/src/main/java/io/geekidea/springbootplus/common/aop/LogAop.java +++ b/src/main/java/io/geekidea/springbootplus/aop/LogAop.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.aop; +package io.geekidea.springbootplus.aop; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; diff --git a/src/main/java/io/geekidea/springbootplus/common/constraints/Email.java b/src/main/java/io/geekidea/springbootplus/common/constraints/Email.java deleted file mode 100644 index 88c532c3..00000000 --- a/src/main/java/io/geekidea/springbootplus/common/constraints/Email.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.geekidea.springbootplus.common.constraints; - - -import javax.validation.Constraint; -import javax.validation.Payload; -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * 自定义系统内的枚举验证注解 - * @author geekidea - * @date 2018-11-08 - */ -@Documented -@Constraint(validatedBy = { EmailValidator.class }) -@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) -@Retention(RUNTIME) -public @interface Email { - String message() default "请输入有效的邮箱"; - - Class[] groups() default { }; - - Class[] payload() default { }; - -} diff --git a/src/main/java/io/geekidea/springbootplus/common/constraints/EmailValidator.java b/src/main/java/io/geekidea/springbootplus/common/constraints/EmailValidator.java deleted file mode 100644 index 83c4ad0d..00000000 --- a/src/main/java/io/geekidea/springbootplus/common/constraints/EmailValidator.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.geekidea.springbootplus.common.constraints; - -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; -import java.util.regex.Pattern; - -/** - * 自定义邮箱验证注解实现类 - * @author geekidea - * @date 2018-11-08 - */ -public class EmailValidator implements ConstraintValidator { - private static final String REG_EX = "^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.[a-zA-Z0-9]{2,6}$"; - private static final Pattern PATTERN = Pattern.compile(REG_EX); - - @Override - public void initialize(Email parameters) { - } - - @Override - public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) { - if (value ==null){ - return true; - } - return PATTERN.matcher(value).matches(); - } -} diff --git a/src/main/java/io/geekidea/springbootplus/common/constraints/EnumType.java b/src/main/java/io/geekidea/springbootplus/common/constraints/EnumType.java index 1ffc4829..18f40ad8 100644 --- a/src/main/java/io/geekidea/springbootplus/common/constraints/EnumType.java +++ b/src/main/java/io/geekidea/springbootplus/common/constraints/EnumType.java @@ -28,7 +28,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; /** - * 自定义邮箱正则验证注解 + * 枚举类型注解 * @author geekidea * @date 2018-11-08 */ diff --git a/src/main/java/io/geekidea/springbootplus/common/param/QueryParam.java b/src/main/java/io/geekidea/springbootplus/common/param/QueryParam.java index 51bb6592..bb7b1cd6 100644 --- a/src/main/java/io/geekidea/springbootplus/common/param/QueryParam.java +++ b/src/main/java/io/geekidea/springbootplus/common/param/QueryParam.java @@ -16,7 +16,7 @@ package io.geekidea.springbootplus.common.param; -import io.geekidea.springbootplus.common.constant.CommonConstant; +import io.geekidea.springbootplus.constant.CommonConstant; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; diff --git a/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java b/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java index cecb10a2..b4046d21 100644 --- a/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java +++ b/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java @@ -29,12 +29,11 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; -import io.geekidea.springbootplus.common.constant.DatePattern; +import io.geekidea.springbootplus.constant.DatePattern; import io.geekidea.springbootplus.config.json.jackson.deserializer.JacksonDateDeserializer; import io.geekidea.springbootplus.config.json.jackson.deserializer.JacksonDoubleDeserializer; import io.geekidea.springbootplus.config.json.jackson.serializer.JacksonDateSerializer; import io.geekidea.springbootplus.config.json.jackson.serializer.JacksonIntegerDeserializer; -import io.geekidea.springbootplus.xss.XssJacksonDeserializer; import io.geekidea.springbootplus.xss.XssJacksonSerializer; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; @@ -70,7 +69,7 @@ public void extendMessageConverters(List> converters) { // XSS序列化 simpleModule.addSerializer(String.class, new XssJacksonSerializer()); - simpleModule.addDeserializer(String.class, new XssJacksonDeserializer()); +// simpleModule.addDeserializer(String.class, new XssJacksonDeserializer()); // Date simpleModule.addSerializer(Date.class, new JacksonDateSerializer()); diff --git a/src/main/java/io/geekidea/springbootplus/config/json/jackson/deserializer/JacksonLocalDateTimeDeserializer.java b/src/main/java/io/geekidea/springbootplus/config/json/jackson/deserializer/JacksonLocalDateTimeDeserializer.java index a82ac84c..ffe1a9a7 100644 --- a/src/main/java/io/geekidea/springbootplus/config/json/jackson/deserializer/JacksonLocalDateTimeDeserializer.java +++ b/src/main/java/io/geekidea/springbootplus/config/json/jackson/deserializer/JacksonLocalDateTimeDeserializer.java @@ -19,7 +19,7 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; -import io.geekidea.springbootplus.common.constant.DatePattern; +import io.geekidea.springbootplus.constant.DatePattern; import org.apache.commons.lang3.StringUtils; import java.io.IOException; diff --git a/src/main/java/io/geekidea/springbootplus/config/json/jackson/serializer/JacksonDateSerializer.java b/src/main/java/io/geekidea/springbootplus/config/json/jackson/serializer/JacksonDateSerializer.java index 52a5ae21..e79b3b4d 100644 --- a/src/main/java/io/geekidea/springbootplus/config/json/jackson/serializer/JacksonDateSerializer.java +++ b/src/main/java/io/geekidea/springbootplus/config/json/jackson/serializer/JacksonDateSerializer.java @@ -27,17 +27,19 @@ /** *

- * Jackson Date反序列化器 + * Jackson Date反序列化器 *

+ * * @author geekidea * @date 2018-11-08 */ public class JacksonDateSerializer extends JsonSerializer { @Override public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { - if (date != null){ - String dateString = DateUtil.getYYYYMMDDHHMMSS(date); - jsonGenerator.writeString(dateString); + String string = null; + if (date != null) { + string = DateUtil.getYYYYMMDDHHMMSS(date); } + jsonGenerator.writeString(string); } } diff --git a/src/main/java/io/geekidea/springbootplus/config/json/jackson/serializer/JacksonLocalDateTimeSerializer.java b/src/main/java/io/geekidea/springbootplus/config/json/jackson/serializer/JacksonLocalDateTimeSerializer.java index 7131d216..89354dc2 100644 --- a/src/main/java/io/geekidea/springbootplus/config/json/jackson/serializer/JacksonLocalDateTimeSerializer.java +++ b/src/main/java/io/geekidea/springbootplus/config/json/jackson/serializer/JacksonLocalDateTimeSerializer.java @@ -20,7 +20,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; -import io.geekidea.springbootplus.common.constant.DatePattern; +import io.geekidea.springbootplus.constant.DatePattern; import java.io.IOException; import java.time.LocalDateTime; @@ -28,8 +28,9 @@ /** *

- * Jackson LocalDateTime 自定义序列化器 + * Jackson LocalDateTime 自定义序列化器 *

+ * * @author geekidea * @date 2018/11/8 */ @@ -37,10 +38,11 @@ public class JacksonLocalDateTimeSerializer extends JsonSerializer diff --git a/src/main/java/io/geekidea/springbootplus/common/constant/DatePattern.java b/src/main/java/io/geekidea/springbootplus/constant/DatePattern.java similarity index 96% rename from src/main/java/io/geekidea/springbootplus/common/constant/DatePattern.java rename to src/main/java/io/geekidea/springbootplus/constant/DatePattern.java index 35a02a5e..e7ab00b9 100644 --- a/src/main/java/io/geekidea/springbootplus/common/constant/DatePattern.java +++ b/src/main/java/io/geekidea/springbootplus/constant/DatePattern.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.constant; +package io.geekidea.springbootplus.constant; /** *

diff --git a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java index 526e8df9..52d4b4ec 100644 --- a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java @@ -15,8 +15,8 @@ */ package io.geekidea.springbootplus.core.config; -import io.geekidea.springbootplus.common.aop.LogAop; -import io.geekidea.springbootplus.common.interceptor.PermissionInterceptor; +import io.geekidea.springbootplus.aop.LogAop; +import io.geekidea.springbootplus.interceptor.PermissionInterceptor; import io.geekidea.springbootplus.core.properties.*; import io.geekidea.springbootplus.resource.interceptor.DownloadInterceptor; import io.geekidea.springbootplus.resource.interceptor.ResourceInterceptor; diff --git a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java index cfdb1f42..1c249b76 100644 --- a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java @@ -17,7 +17,7 @@ package io.geekidea.springbootplus.core.config; import com.alibaba.fastjson.JSON; -import io.geekidea.springbootplus.common.interceptor.PermissionInterceptor; +import io.geekidea.springbootplus.interceptor.PermissionInterceptor; import io.geekidea.springbootplus.core.properties.SpringBootPlusInterceptorProperties; import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; import io.geekidea.springbootplus.resource.interceptor.DownloadInterceptor; diff --git a/src/main/java/io/geekidea/springbootplus/common/filter/RequestPathFilter.java b/src/main/java/io/geekidea/springbootplus/filter/RequestPathFilter.java similarity index 98% rename from src/main/java/io/geekidea/springbootplus/common/filter/RequestPathFilter.java rename to src/main/java/io/geekidea/springbootplus/filter/RequestPathFilter.java index 0f3c44de..fb446467 100644 --- a/src/main/java/io/geekidea/springbootplus/common/filter/RequestPathFilter.java +++ b/src/main/java/io/geekidea/springbootplus/filter/RequestPathFilter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.filter; +package io.geekidea.springbootplus.filter; import io.geekidea.springbootplus.core.properties.SpringBootPlusFilterProperties; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/io/geekidea/springbootplus/common/interceptor/PermissionInterceptor.java b/src/main/java/io/geekidea/springbootplus/interceptor/PermissionInterceptor.java similarity index 96% rename from src/main/java/io/geekidea/springbootplus/common/interceptor/PermissionInterceptor.java rename to src/main/java/io/geekidea/springbootplus/interceptor/PermissionInterceptor.java index 2c5ac243..d17dcfb9 100644 --- a/src/main/java/io/geekidea/springbootplus/common/interceptor/PermissionInterceptor.java +++ b/src/main/java/io/geekidea/springbootplus/interceptor/PermissionInterceptor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.interceptor; +package io.geekidea.springbootplus.interceptor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.servlet.ModelAndView; diff --git a/src/main/java/io/geekidea/springbootplus/shiro/cache/impl/LoginRedisServiceImpl.java b/src/main/java/io/geekidea/springbootplus/shiro/cache/impl/LoginRedisServiceImpl.java index 31541400..b8b60009 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/cache/impl/LoginRedisServiceImpl.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/cache/impl/LoginRedisServiceImpl.java @@ -16,7 +16,7 @@ package io.geekidea.springbootplus.shiro.cache.impl; -import io.geekidea.springbootplus.common.constant.CommonRedisKey; +import io.geekidea.springbootplus.constant.CommonRedisKey; import io.geekidea.springbootplus.shiro.cache.LoginRedisService; import io.geekidea.springbootplus.shiro.convert.ShiroMapstructConvert; import io.geekidea.springbootplus.shiro.jwt.JwtProperties; diff --git a/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java b/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java index 76bd33a2..ae79ac56 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/config/ShiroConfig.java @@ -17,7 +17,7 @@ package io.geekidea.springbootplus.shiro.config; import com.alibaba.fastjson.JSON; -import io.geekidea.springbootplus.common.filter.RequestPathFilter; +import io.geekidea.springbootplus.filter.RequestPathFilter; import io.geekidea.springbootplus.core.properties.SpringBootPlusFilterProperties; import io.geekidea.springbootplus.shiro.cache.LoginRedisService; import io.geekidea.springbootplus.shiro.exception.ShiroConfigException; diff --git a/src/main/java/io/geekidea/springbootplus/shiro/jwt/JwtProperties.java b/src/main/java/io/geekidea/springbootplus/shiro/jwt/JwtProperties.java index fa1ffd72..ff0232c3 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/jwt/JwtProperties.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/jwt/JwtProperties.java @@ -16,7 +16,7 @@ package io.geekidea.springbootplus.shiro.jwt; -import io.geekidea.springbootplus.common.constant.CommonConstant; +import io.geekidea.springbootplus.constant.CommonConstant; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; diff --git a/src/main/java/io/geekidea/springbootplus/shiro/service/impl/LoginServiceImpl.java b/src/main/java/io/geekidea/springbootplus/shiro/service/impl/LoginServiceImpl.java index e5a6bd5c..384c9084 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/service/impl/LoginServiceImpl.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/service/impl/LoginServiceImpl.java @@ -19,7 +19,7 @@ import com.auth0.jwt.interfaces.DecodedJWT; import io.geekidea.springbootplus.common.api.ApiCode; import io.geekidea.springbootplus.common.api.ApiResult; -import io.geekidea.springbootplus.common.constant.CommonConstant; +import io.geekidea.springbootplus.constant.CommonConstant; import io.geekidea.springbootplus.shiro.cache.LoginRedisService; import io.geekidea.springbootplus.shiro.jwt.JwtProperties; import io.geekidea.springbootplus.shiro.jwt.JwtToken; diff --git a/src/main/java/io/geekidea/springbootplus/shiro/util/JwtUtil.java b/src/main/java/io/geekidea/springbootplus/shiro/util/JwtUtil.java index cfeaea04..e38c49c2 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/util/JwtUtil.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/util/JwtUtil.java @@ -21,7 +21,7 @@ import com.auth0.jwt.JWTVerifier; import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.interfaces.DecodedJWT; -import io.geekidea.springbootplus.common.constant.CommonConstant; +import io.geekidea.springbootplus.constant.CommonConstant; import io.geekidea.springbootplus.shiro.jwt.JwtProperties; import io.geekidea.springbootplus.util.UUIDUtil; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/io/geekidea/springbootplus/shiro/util/LoginUtil.java b/src/main/java/io/geekidea/springbootplus/shiro/util/LoginUtil.java index 66adac2b..4dbcc6ef 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/util/LoginUtil.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/util/LoginUtil.java @@ -16,7 +16,7 @@ package io.geekidea.springbootplus.shiro.util; -import io.geekidea.springbootplus.common.constant.CommonRedisKey; +import io.geekidea.springbootplus.constant.CommonRedisKey; import io.geekidea.springbootplus.shiro.vo.LoginSysUserRedisVo; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; diff --git a/src/main/java/io/geekidea/springbootplus/xss/XssFilter.java b/src/main/java/io/geekidea/springbootplus/xss/XssFilter.java index 02815830..f201d7b2 100644 --- a/src/main/java/io/geekidea/springbootplus/xss/XssFilter.java +++ b/src/main/java/io/geekidea/springbootplus/xss/XssFilter.java @@ -19,7 +19,6 @@ import lombok.extern.slf4j.Slf4j; import javax.servlet.*; -import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; import java.io.IOException; @@ -31,7 +30,7 @@ * @since 1.3.1.RELEASE **/ @Slf4j -@WebFilter(filterName = "xssFilter", urlPatterns = "/*", asyncSupported = true) +//@WebFilter(filterName = "xssFilter", urlPatterns = "/*", asyncSupported = true) public class XssFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { diff --git a/src/main/java/io/geekidea/springbootplus/xss/XssJacksonSerializer.java b/src/main/java/io/geekidea/springbootplus/xss/XssJacksonSerializer.java index eb988c22..71bdbde8 100644 --- a/src/main/java/io/geekidea/springbootplus/xss/XssJacksonSerializer.java +++ b/src/main/java/io/geekidea/springbootplus/xss/XssJacksonSerializer.java @@ -19,7 +19,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; -import org.apache.commons.lang3.StringUtils; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.text.StringEscapeUtils; import java.io.IOException; @@ -31,14 +31,12 @@ * @date 2019-10-10 * @since 1.3.1.RELEASE **/ +@Slf4j public class XssJacksonSerializer extends JsonSerializer { @Override public void serialize(String s, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { - if (StringUtils.isNotBlank(s)) { - String escapeValue = StringEscapeUtils.escapeHtml4(s); - jsonGenerator.writeString(escapeValue); - } + jsonGenerator.writeString(StringEscapeUtils.escapeHtml4(s)); } } diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 5e375125..47538541 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -52,8 +52,9 @@ spring-boot-plus: include-paths: /** # 排除路径,多行字符串配置 exclude-paths: | - /actuator/**,/instances,/logfile,/sba-settings.js,/assets/img/favicon.png, - /swagger-ui.html,/swagger-resources/**,/webjars/springfox-swagger-ui/**,/v2/api-docs + /applications/**,/actuator/**,/instances/**,/logfile,/sba-settings.js,/assets/img/favicon.png, + /swagger-ui.html,/swagger-resources/**,/webjars/springfox-swagger-ui/**,/v2/api-docs, + /druid/**,/favicon.ico # 拦截器配置 interceptor: permission: diff --git a/src/test/java/io/geekidea/springbootplus/test/RedisTemplateTest.java b/src/test/java/io/geekidea/springbootplus/test/RedisTemplateTest.java index 9942fb16..222afbf1 100644 --- a/src/test/java/io/geekidea/springbootplus/test/RedisTemplateTest.java +++ b/src/test/java/io/geekidea/springbootplus/test/RedisTemplateTest.java @@ -16,7 +16,7 @@ package io.geekidea.springbootplus.test; -import io.geekidea.springbootplus.common.constant.CommonRedisKey; +import io.geekidea.springbootplus.constant.CommonRedisKey; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; From 32faacaf589a60a3faef7bd36b18960dfff8f660 Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Sun, 13 Oct 2019 15:02:34 +0800 Subject: [PATCH 13/21] =?UTF-8?q?:tiger:=20=E4=BC=98=E5=8C=96xss?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 23 +++++++++++++++++++ .../config/json/jackson/JacksonConfig.java | 5 ++-- .../springbootplus/xss/XssFilter.java | 3 ++- .../xss/XssJacksonDeserializer.java | 3 +-- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1da28ab9..ca4fdb14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ # 更新日志 CHANGELOG + +## [V1.3.1-RELEASE] 2019.10.15 + +### ⭐️ New Features + + +### ⚡️ Optimization + + +### 📝 Added/Modified + + +### 🐞 Bug Fixes + + +### 📔 Documentation + + +### 🔨 Dependency Upgrades +- Upgrade to `spring-boot` 2.1.9.RELEASE +- Upgrade to `Fastjson` 1.2.62 + + ## [V1.3.0-RELEASE] 2019.10.06 ### ⭐️ New Features diff --git a/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java b/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java index b4046d21..0a9e4908 100644 --- a/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java +++ b/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java @@ -29,11 +29,12 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; -import io.geekidea.springbootplus.constant.DatePattern; import io.geekidea.springbootplus.config.json.jackson.deserializer.JacksonDateDeserializer; import io.geekidea.springbootplus.config.json.jackson.deserializer.JacksonDoubleDeserializer; import io.geekidea.springbootplus.config.json.jackson.serializer.JacksonDateSerializer; import io.geekidea.springbootplus.config.json.jackson.serializer.JacksonIntegerDeserializer; +import io.geekidea.springbootplus.constant.DatePattern; +import io.geekidea.springbootplus.xss.XssJacksonDeserializer; import io.geekidea.springbootplus.xss.XssJacksonSerializer; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; @@ -69,7 +70,7 @@ public void extendMessageConverters(List> converters) { // XSS序列化 simpleModule.addSerializer(String.class, new XssJacksonSerializer()); -// simpleModule.addDeserializer(String.class, new XssJacksonDeserializer()); + simpleModule.addDeserializer(String.class, new XssJacksonDeserializer()); // Date simpleModule.addSerializer(Date.class, new JacksonDateSerializer()); diff --git a/src/main/java/io/geekidea/springbootplus/xss/XssFilter.java b/src/main/java/io/geekidea/springbootplus/xss/XssFilter.java index f201d7b2..02815830 100644 --- a/src/main/java/io/geekidea/springbootplus/xss/XssFilter.java +++ b/src/main/java/io/geekidea/springbootplus/xss/XssFilter.java @@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j; import javax.servlet.*; +import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; import java.io.IOException; @@ -30,7 +31,7 @@ * @since 1.3.1.RELEASE **/ @Slf4j -//@WebFilter(filterName = "xssFilter", urlPatterns = "/*", asyncSupported = true) +@WebFilter(filterName = "xssFilter", urlPatterns = "/*", asyncSupported = true) public class XssFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { diff --git a/src/main/java/io/geekidea/springbootplus/xss/XssJacksonDeserializer.java b/src/main/java/io/geekidea/springbootplus/xss/XssJacksonDeserializer.java index cba32137..d612dbdb 100644 --- a/src/main/java/io/geekidea/springbootplus/xss/XssJacksonDeserializer.java +++ b/src/main/java/io/geekidea/springbootplus/xss/XssJacksonDeserializer.java @@ -35,8 +35,7 @@ public class XssJacksonDeserializer extends JsonDeserializer { @Override public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { - String string = jsonParser.getText(); - return StringEscapeUtils.escapeHtml4(string); + return StringEscapeUtils.escapeHtml4(jsonParser.getText()); } } From 04ddff9bf19bc2a7180e1c853c1189db9f6deb2a Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Mon, 14 Oct 2019 09:55:19 +0800 Subject: [PATCH 14/21] =?UTF-8?q?:tiger:=20=E4=BC=98=E5=8C=96xss?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 23 ++++++++++++++----- .../xss/XssHttpServletRequestWrapper.java | 9 +++----- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca4fdb14..1ddc44fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,24 +4,35 @@ ## [V1.3.1-RELEASE] 2019.10.15 ### ⭐️ New Features - +- Xss跨站脚本工具处理 +- CORS跨域配置 ### ⚡️ Optimization - +- 代码生成器可自定义配置生成哪些文件 +- 请求路径filter配置,配置文件属性名称调整 +- Aop切点优化,`Aop` JSON参数输出优化 +- 可配置是否生成`Validation`验证代码 +- 优化`controller`,`entity`模版生成 +- 优化代码生成器 CodeGenerator +- 调整 `aop`, `filter`,`interceptor`,`controller`,`param`,`vo`代码目录结构 ### 📝 Added/Modified - +- Add `XssFilter`,`XssHttpServletRequestWrapper`,`XssJacksonDeserializer`,`XssJacksonSerializer` +- Add `SpringBootPlusCorsProperties` +- Update `JacksonConfig` +- Update `LogAop`,`RequestPathFilter`,`ShiroConfig` ### 🐞 Bug Fixes - +- fix druid控制面板无法访问问题 ### 📔 Documentation - +- [https://springboot.plus/guide/xss.html](https://springboot.plus/guide/xss.html) +- [https://springboot.plus/guide/cors.html](https://springboot.plus/guide/cors.html) ### 🔨 Dependency Upgrades - Upgrade to `spring-boot` 2.1.9.RELEASE - Upgrade to `Fastjson` 1.2.62 - +- Add `commons-text` 1.8 ## [V1.3.0-RELEASE] 2019.10.06 diff --git a/src/main/java/io/geekidea/springbootplus/xss/XssHttpServletRequestWrapper.java b/src/main/java/io/geekidea/springbootplus/xss/XssHttpServletRequestWrapper.java index 772593ad..8a91ccd0 100644 --- a/src/main/java/io/geekidea/springbootplus/xss/XssHttpServletRequestWrapper.java +++ b/src/main/java/io/geekidea/springbootplus/xss/XssHttpServletRequestWrapper.java @@ -37,14 +37,12 @@ public XssHttpServletRequestWrapper(HttpServletRequest request) { @Override public String getQueryString() { - String value = super.getQueryString(); - return StringEscapeUtils.escapeHtml4(value); + return StringEscapeUtils.escapeHtml4(super.getQueryString()); } @Override public String getParameter(String name) { - String value = super.getParameter(name); - return StringEscapeUtils.escapeHtml4(value); + return StringEscapeUtils.escapeHtml4(super.getParameter(name)); } @Override @@ -56,8 +54,7 @@ public String[] getParameterValues(String name) { int length = values.length; String[] escapeValues = new String[length]; for (int i = 0; i < length; i++) { - String value = values[i]; - escapeValues[i] = StringEscapeUtils.escapeHtml4(value); + escapeValues[i] = StringEscapeUtils.escapeHtml4(values[i]); } return escapeValues; } From 61d53967a4c47afee3525fe17f81ba0a458fcee5 Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Mon, 14 Oct 2019 11:44:07 +0800 Subject: [PATCH 15/21] =?UTF-8?q?:tiger:=20=E4=BC=98=E5=8C=96LogAop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/io/geekidea/springbootplus/aop/LogAop.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/io/geekidea/springbootplus/aop/LogAop.java b/src/main/java/io/geekidea/springbootplus/aop/LogAop.java index 9251a97f..4c8dfc7b 100644 --- a/src/main/java/io/geekidea/springbootplus/aop/LogAop.java +++ b/src/main/java/io/geekidea/springbootplus/aop/LogAop.java @@ -35,6 +35,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -261,6 +263,12 @@ private Object argsArrayToJsonString(Object[] args) { if (arg instanceof HttpServletResponse) { continue; } + if (arg instanceof MultipartFile) { + continue; + } + if (arg instanceof ModelAndView) { + continue; + } realArgs.add(arg); } if (realArgs.size() == 1) { From 4a7793fff784c0ad294aad6ffa8ee0a693fe6def Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Mon, 14 Oct 2019 12:59:08 +0800 Subject: [PATCH 16/21] =?UTF-8?q?:tiger:=20=E4=BC=98=E5=8C=96cors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/deploy.sh | 2 +- src/main/resources/config/application.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/deploy.sh b/deploy/deploy.sh index 1837ab42..184e98d4 100644 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -52,7 +52,7 @@ pwd # 2. maven打包 mvn clean -mvn clean package -Ptest +mvn package -Ptest # 3. 停服 cd .. diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 47538541..a0f98f0c 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -94,7 +94,7 @@ spring-boot-plus: # 允许访问的源 allowed-origins: '*' # 允许访问的请求头 - allowed-headers: content-type,token + allowed-headers: x-requested-with,content-type,token # 是否允许发送cookie allow-credentials: true # 允许访问的请求方式 From c8aafc30e127687dc2a3a6d622fa8977184c925a Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Mon, 14 Oct 2019 15:40:19 +0800 Subject: [PATCH 17/21] =?UTF-8?q?:tiger:=20fix=20start.sh=20=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/startup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/startup.sh b/src/bin/startup.sh index 382e85a6..921db085 100644 --- a/src/bin/startup.sh +++ b/src/bin/startup.sh @@ -122,7 +122,7 @@ STARTUP_LOG="${STARTUP_LOG}application background startup command: nohup java ${ #====================================================================== # 执行启动命令:后台启动项目,并将日志输出到项目根目录下的logs文件夹下 #====================================================================== -nohup java ${JAVA_OPT} -jar ${BASE_PATH}/lib/${APPLICATION_JAR} --spring.config.location=${CONFIG_DIR} > ${LOG_PATH} 2>&1 & +nohup java ${JAVA_OPT} -jar ${BASE_PATH}/lib/${APPLICATION_JAR} --spring.config.location=${CONFIG_DIR} --logging.config=${CONFIG_DIR}logback.xml > ${LOG_PATH} 2>&1 & # 进程ID From b53de784076008dc463a34bc83355d62ace85f0e Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Mon, 14 Oct 2019 23:40:50 +0800 Subject: [PATCH 18/21] =?UTF-8?q?:tiger:=20=E4=BC=98=E5=8C=96deploy.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/deploy.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/deploy/deploy.sh b/deploy/deploy.sh index 184e98d4..d9e11be7 100644 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -43,7 +43,7 @@ else if [[ ! $PULL_RESULT == *up-to-date* ]] then - echo "Update code..." + echo "update code..." IS_UPDATE=1 fi fi @@ -54,8 +54,16 @@ pwd mvn clean mvn package -Ptest +pwd +# 判断是否生成成功 +if [ ! -f "target/spring-boot-plus-server-assembly.tar.gz" ]; then + echo "maven build fail" + exit +fi + # 3. 停服 cd .. +pwd if [ -d "spring-boot-plus-server" ]; then sh spring-boot-plus-server/bin/shutdown.sh @@ -72,18 +80,18 @@ if [[ $IS_UPDATE == 1 ]] then echo "Back spring-boot-plus-server..." mv spring-boot-plus-server spring-boot-plus-server-back/spring-boot-plus-server-back-"${NOW}" + echo "back success" fi echo "Copy spring-boot-plus-server-assembly.tar.gz..." # 复制到项目同级目录,如果有,则覆盖 cp -r -f spring-boot-plus/target/spring-boot-plus-server-assembly.tar.gz spring-boot-plus-server-assembly.tar.gz +echo "copy success" +pwd # 5. 运行spring-boot-plus tar -zxvf spring-boot-plus-server-assembly.tar.gz -cd spring-boot-plus-server/bin -sh restart.sh +echo "tar.gz decompression success" -# 6. 访问项目 -# 输出项目日志 -# http://localhost:8888/docs +sh spring-boot-plus-server/bin/restart.sh From 876162e9e73a9d8126aa589624044a303a8e28e9 Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Mon, 14 Oct 2019 23:54:48 +0800 Subject: [PATCH 19/21] =?UTF-8?q?:tiger:=20=E4=BC=98=E5=8C=96deploy.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/deploy.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/deploy/deploy.sh b/deploy/deploy.sh index d9e11be7..f97ff1db 100644 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -78,12 +78,12 @@ fi if [[ $IS_UPDATE == 1 ]] then - echo "Back spring-boot-plus-server..." + echo "back spring-boot-plus-server..." mv spring-boot-plus-server spring-boot-plus-server-back/spring-boot-plus-server-back-"${NOW}" echo "back success" fi -echo "Copy spring-boot-plus-server-assembly.tar.gz..." +echo "copy spring-boot-plus-server-assembly.tar.gz..." # 复制到项目同级目录,如果有,则覆盖 cp -r -f spring-boot-plus/target/spring-boot-plus-server-assembly.tar.gz spring-boot-plus-server-assembly.tar.gz echo "copy success" @@ -93,5 +93,7 @@ pwd tar -zxvf spring-boot-plus-server-assembly.tar.gz echo "tar.gz decompression success" -sh spring-boot-plus-server/bin/restart.sh +pwd +sh spring-boot-plus-server/bin/shutdown.sh +sh spring-boot-plus-server/bin/startup.sh From 33b5bfb36f51323db8a188f40729f100edd22565 Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Tue, 15 Oct 2019 00:04:37 +0800 Subject: [PATCH 20/21] =?UTF-8?q?:tiger:=20=E4=BC=98=E5=8C=96cors=E5=8D=87?= =?UTF-8?q?=E7=BA=A7hutool=204.6.10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + pom.xml | 2 +- .../core/config/SpringBootPlusConfig.java | 30 +-------- .../core/config/SpringBootPlusCorsConfig.java | 65 +++++++++++++++++++ .../SpringBootPlusCorsProperties.java | 7 +- src/main/resources/config/application.yml | 5 +- 6 files changed, 78 insertions(+), 32 deletions(-) create mode 100644 src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusCorsConfig.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ddc44fd..e2a7b082 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ ### 🔨 Dependency Upgrades - Upgrade to `spring-boot` 2.1.9.RELEASE - Upgrade to `Fastjson` 1.2.62 +- Upgrade to `hutool` 4.6.10 - Add `commons-text` 1.8 ## [V1.3.0-RELEASE] 2019.10.06 diff --git a/pom.xml b/pom.xml index e9fa05a1..2d1627d3 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ 0.9.11 1.18 1.18.8 - 4.6.4 + 4.6.10 4.12 0.5.4 1.3.0.Final diff --git a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java index 52d4b4ec..77833618 100644 --- a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java @@ -16,20 +16,15 @@ package io.geekidea.springbootplus.core.config; import io.geekidea.springbootplus.aop.LogAop; -import io.geekidea.springbootplus.interceptor.PermissionInterceptor; import io.geekidea.springbootplus.core.properties.*; +import io.geekidea.springbootplus.interceptor.PermissionInterceptor; import io.geekidea.springbootplus.resource.interceptor.DownloadInterceptor; import io.geekidea.springbootplus.resource.interceptor.ResourceInterceptor; import io.geekidea.springbootplus.resource.interceptor.UploadInterceptor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.Ordered; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import org.springframework.web.filter.CorsFilter; /** * spring-boot-plus配置 @@ -49,29 +44,6 @@ }) public class SpringBootPlusConfig { - /** - * CORS跨域设置 - * - * @return - */ - @Bean - public FilterRegistrationBean corsFilter(SpringBootPlusCorsProperties corsProperties) { - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - CorsConfiguration corsConfiguration = new CorsConfiguration(); - // 跨域配置 - corsConfiguration.setAllowedOrigins(corsProperties.getAllowedOrigins()); - corsConfiguration.setAllowedHeaders(corsProperties.getAllowedHeaders()); - corsConfiguration.setAllowedMethods(corsProperties.getAllowedMethods()); - corsConfiguration.setAllowCredentials(corsProperties.isAllowCredentials()); - corsConfiguration.setExposedHeaders(corsProperties.getExposedHeaders()); - source.registerCorsConfiguration(corsProperties.getPath(), corsConfiguration); - - FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source)); - bean.setOrder(Ordered.HIGHEST_PRECEDENCE); - bean.setEnabled(corsProperties.isEnable()); - return bean; - } - /** * 配置日志AOP * diff --git a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusCorsConfig.java b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusCorsConfig.java new file mode 100644 index 00000000..5a9392d6 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusCorsConfig.java @@ -0,0 +1,65 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.core.config; + +import io.geekidea.springbootplus.core.properties.SpringBootPlusCorsProperties; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * 跨域配置 + * + * @author geekidea + * @date 2019/10/14 + * @since 1.3.1.RELEASE + */ +@Slf4j +@Configuration +public class SpringBootPlusCorsConfig { + + /** + * CORS跨域设置 + * + * @return + */ + @Bean + public FilterRegistrationBean corsFilter(SpringBootPlusCorsProperties corsProperties) { + log.debug("corsProperties:{}", corsProperties); + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration corsConfiguration = new CorsConfiguration(); + // 跨域配置 + corsConfiguration.setAllowedOrigins(corsProperties.getAllowedOrigins()); + corsConfiguration.setAllowedHeaders(corsProperties.getAllowedHeaders()); + corsConfiguration.setAllowedMethods(corsProperties.getAllowedMethods()); + corsConfiguration.setAllowCredentials(corsProperties.isAllowCredentials()); + corsConfiguration.setExposedHeaders(corsProperties.getExposedHeaders()); + corsConfiguration.setMaxAge(corsConfiguration.getMaxAge()); + + source.registerCorsConfiguration(corsProperties.getPath(), corsConfiguration); + FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source)); + bean.setOrder(Ordered.HIGHEST_PRECEDENCE); + bean.setEnabled(corsProperties.isEnable()); + return bean; + } + +} diff --git a/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusCorsProperties.java b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusCorsProperties.java index 1df26d54..bbfa02d1 100644 --- a/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusCorsProperties.java +++ b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusCorsProperties.java @@ -67,6 +67,11 @@ public class SpringBootPlusCorsProperties { /** * 允许响应的头 */ - private List exposedHeaders = Arrays.asList("content-type", "token"); + private List exposedHeaders = Arrays.asList("token"); + + /** + * 该响应的有效时间默认为30分钟,在有效时间内,浏览器无须为同一请求再次发起预检请求 + */ + private Long maxAge = 1800L; } diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index a0f98f0c..88f2e405 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -100,7 +100,10 @@ spring-boot-plus: # 允许访问的请求方式 allowed-methods: OPTION,GET,POST # 允许响应的头 - exposed-headers: content-type,token + exposed-headers: token + # 该响应的有效时间默认为30分钟,在有效时间内,浏览器无须为同一请求再次发起预检请求 + max-age: 1800 + ############################ CORS end ############################## ########################## Resource start ########################## From f4fba822d7449338112c3bebab7872d38d185c5e Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Tue, 15 Oct 2019 00:05:28 +0800 Subject: [PATCH 21/21] =?UTF-8?q?:tiger:=20=E4=BC=98=E5=8C=96cors=E5=8D=87?= =?UTF-8?q?=E7=BA=A7hutool=204.6.10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-zh.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README-zh.md b/README-zh.md index 504fef5a..0b820fe1 100644 --- a/README-zh.md +++ b/README-zh.md @@ -73,7 +73,7 @@ reflections | 0.9.11 | 反射工具包 | hibernate-validator | 6.0.17.Final | 后台参数校验注解 | Shiro | 1.4.1 | 权限控制 | JWT | 3.8.3 | JSON WEB TOKEN | -hutool-all | 4.6.4 | 常用工具集 | +hutool-all | 4.6.10 | 常用工具集 | lombok | 1.18.8 | 注解生成Java Bean等工具 | mapstruct | 1.3.0.Final | 对象属性复制工具 | diff --git a/README.md b/README.md index b37b1d61..c5f97fe6 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ reflections | 0.9.11 | Reflection Toolkit | hibernate-validator | 6.0.17.Final | Validator toolkit | Shiro | 1.4.1 | Permission control | JWT | 3.8.3 | JSON WEB TOKEN | -hutool-all | 4.6.4 | Common toolset | +hutool-all | 4.6.10 | Common toolset | lombok | 1.18.8 | Automatically plugs | mapstruct | 1.3.0.Final | Object property replication tool |