diff --git a/CHANGELOG.md b/CHANGELOG.md index 162e4f04..e2a7b082 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,40 @@ # 更新日志 CHANGELOG + +## [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 +- Upgrade to `hutool` 4.6.10 +- Add `commons-text` 1.8 + ## [V1.3.0-RELEASE] 2019.10.06 ### ⭐️ New Features @@ -60,7 +95,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..0b820fe1 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 | 数据源 | @@ -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 b3ec837a..c5f97fe6 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 | @@ -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 | diff --git a/deploy/deploy.sh b/deploy/deploy.sh index 1837ab42..f97ff1db 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 @@ -52,10 +52,18 @@ pwd # 2. maven打包 mvn clean -mvn clean package -Ptest +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 @@ -70,20 +78,22 @@ 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" +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 +pwd +sh spring-boot-plus-server/bin/shutdown.sh +sh spring-boot-plus-server/bin/startup.sh 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 9737f7b9..2d1627d3 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 @@ -45,26 +45,26 @@ UTF-8 ${utf8} ${utf8} - ${parent.version} 1.8 - 2.1.0.RELEASE + 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.6.10 4.12 0.5.4 1.3.0.Final @@ -301,6 +301,14 @@ + + + org.apache.commons + commons-text + ${commons-text.version} + + + @@ -486,6 +494,7 @@ Spring Milestones https://maven.aliyun.com/repository/spring + central maven-central 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 diff --git a/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java b/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java index f47b227d..7b73d33b 100644 --- a/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java +++ b/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java @@ -22,6 +22,7 @@ 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; @@ -39,6 +40,7 @@ @EnableConfigurationProperties @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/aop/LogAop.java similarity index 80% rename from src/main/java/io/geekidea/springbootplus/common/aop/LogAop.java rename to src/main/java/io/geekidea/springbootplus/aop/LogAop.java index 1b0c9bb9..4c8dfc7b 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; @@ -35,13 +35,14 @@ 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; 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 +61,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 +99,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 +110,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 +254,27 @@ 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; + } + if (arg instanceof MultipartFile) { + continue; + } + if (arg instanceof ModelAndView) { + 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/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/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/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 93% 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..bb7b1cd6 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,9 +14,9 @@ * 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.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/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/common/web/filter/CrossDomainFilter.java b/src/main/java/io/geekidea/springbootplus/common/web/filter/CrossDomainFilter.java deleted file mode 100644 index 431a6772..00000000 --- a/src/main/java/io/geekidea/springbootplus/common/web/filter/CrossDomainFilter.java +++ /dev/null @@ -1,73 +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; - 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/config/json/jackson/JacksonConfig.java b/src/main/java/io/geekidea/springbootplus/config/json/jackson/JacksonConfig.java index d1ec2b1a..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,13 @@ 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.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; 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/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/SpringBootPlusConfig.java b/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusConfig.java deleted file mode 100644 index 10bf6b82..00000000 --- a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusConfig.java +++ /dev/null @@ -1,150 +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.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; -import io.geekidea.springbootplus.resource.web.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.annotation.Order; - -import javax.servlet.Filter; - -/** - * spring-boot-plus配置 - * @author geekidea - * @date 2019/8/4 - * @since 1.2.0-RELEASE - */ -@Slf4j -@Configuration -@EnableConfigurationProperties({SpringBootPlusProperties.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 - @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; - } - - /** - * 配置日志AOP - * @param springBootPlusProperties - * @return - */ - @Bean - public LogAop logAop(SpringBootPlusProperties springBootPlusProperties){ - LogAop logAop = new LogAop(); - logAop.setRequestLogFormat(springBootPlusProperties.isRequestLogFormat()); - logAop.setResponseLogFormat(springBootPlusProperties.isResponseLogFormat()); - log.info("init LogAop success"); - return logAop; - } - - /** - * JWT TOKEN验证拦截器 - * @return - */ -// @Bean -// public JwtInterceptor jwtInterceptor(){ -// JwtInterceptor jwtInterceptor = new JwtInterceptor(); -// return jwtInterceptor; -// } - - /** - * 权限拦截器 - * @return - */ - @Bean - 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(){ - UploadInterceptor uploadInterceptor = new UploadInterceptor(); - return uploadInterceptor; - } - - /** - * 资源拦截器 - * @return - */ - @Bean - public ResourceInterceptor resourceInterceptor(){ - ResourceInterceptor resourceInterceptor = new ResourceInterceptor(); - return resourceInterceptor; - } - - /** - * 下载拦截器 - * @return - */ - @Bean - public DownloadInterceptor downloadInterceptor(){ - DownloadInterceptor downloadInterceptor = new DownloadInterceptor(); - return downloadInterceptor; - } -} diff --git a/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java new file mode 100644 index 00000000..77833618 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java @@ -0,0 +1,105 @@ +/* + * 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.aop.LogAop; +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.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * spring-boot-plus配置 + * + * @author geekidea + * @date 2019/8/4 + * @since 1.2.0-RELEASE + */ +@Slf4j +@Configuration +@EnableConfigurationProperties({ + SpringBootPlusProperties.class, + SpringBootPlusCorsProperties.class, + SpringBootPlusFilterProperties.class, + SpringBootPlusInterceptorProperties.class, + SpringBootPlusAopProperties.class +}) +public class SpringBootPlusConfig { + + /** + * 配置日志AOP + * + * @param springBootPlusProperties + * @return + */ + @Bean + public LogAop logAop(SpringBootPlusProperties springBootPlusProperties) { + LogAop logAop = new LogAop(); + logAop.setRequestLogFormat(springBootPlusProperties.isRequestLogFormat()); + logAop.setResponseLogFormat(springBootPlusProperties.isResponseLogFormat()); + log.debug("init LogAop success"); + return logAop; + } + + /** + * 权限拦截器 + * + * @return + */ + @Bean + public PermissionInterceptor permissionInterceptor() { + PermissionInterceptor permissionInterceptor = new PermissionInterceptor(); + return permissionInterceptor; + } + + /** + * 上传拦截器 + * + * @return + */ + @Bean + public UploadInterceptor uploadInterceptor() { + UploadInterceptor uploadInterceptor = new UploadInterceptor(); + return uploadInterceptor; + } + + /** + * 资源拦截器 + * + * @return + */ + @Bean + public ResourceInterceptor resourceInterceptor() { + ResourceInterceptor resourceInterceptor = new ResourceInterceptor(); + return resourceInterceptor; + } + + /** + * 下载拦截器 + * + * @return + */ + @Bean + public DownloadInterceptor downloadInterceptor() { + DownloadInterceptor downloadInterceptor = new DownloadInterceptor(); + return downloadInterceptor; + } +} 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/SpringBootPlusWebMvcConfig.java b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java similarity index 78% 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..1c249b76 100644 --- a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusWebMvcConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusWebMvcConfig.java @@ -14,13 +14,15 @@ * 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.resource.web.interceptor.DownloadInterceptor; -import io.geekidea.springbootplus.resource.web.interceptor.ResourceInterceptor; -import io.geekidea.springbootplus.resource.web.interceptor.UploadInterceptor; +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; +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; @@ -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/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/SpringBootPlusCorsProperties.java b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusCorsProperties.java new file mode 100644 index 00000000..bbfa02d1 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusCorsProperties.java @@ -0,0 +1,77 @@ +/* + * 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("token"); + + /** + * 该响应的有效时间默认为30分钟,在有效时间内,浏览器无须为同一请求再次发起预检请求 + */ + private Long maxAge = 1800L; + +} 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..5722988d 100644 --- a/src/main/java/io/geekidea/springbootplus/core/SpringBootPlusFilterConfig.java +++ b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusFilterProperties.java @@ -14,32 +14,28 @@ * 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; /** + * Filter配置属性 + * * @author geekidea * @date 2019-09-29 * @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/core/properties/SpringBootPlusStaticProperties.java b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusStaticProperties.java new file mode 100644 index 00000000..a843354f --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusStaticProperties.java @@ -0,0 +1,49 @@ +/* + * 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 lombok.extern.slf4j.Slf4j; +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 + **/ +@Slf4j +@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/common/web/filter/RequestPathFilter.java b/src/main/java/io/geekidea/springbootplus/filter/RequestPathFilter.java similarity index 55% rename from src/main/java/io/geekidea/springbootplus/common/web/filter/RequestPathFilter.java rename to src/main/java/io/geekidea/springbootplus/filter/RequestPathFilter.java index ce8dca80..fb446467 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/filter/RequestPathFilter.java +++ b/src/main/java/io/geekidea/springbootplus/filter/RequestPathFilter.java @@ -14,33 +14,37 @@ * limitations under the License. */ -package io.geekidea.springbootplus.common.web.filter; +package io.geekidea.springbootplus.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/config/package-info.java b/src/main/java/io/geekidea/springbootplus/generator/config/SpringBootPlusMySqlQuery.java similarity index 64% rename from src/main/java/io/geekidea/springbootplus/config/package-info.java rename to src/main/java/io/geekidea/springbootplus/generator/config/SpringBootPlusMySqlQuery.java index def6cd80..fc92c680 100644 --- a/src/main/java/io/geekidea/springbootplus/config/package-info.java +++ b/src/main/java/io/geekidea/springbootplus/generator/config/SpringBootPlusMySqlQuery.java @@ -14,9 +14,21 @@ * limitations under the License. */ +package io.geekidea.springbootplus.generator.config; + +import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery; + /** - * 公共配置 + * MySQL代码生成查询是否为空的列 + * * @author geekidea - * @date 2018-11-08 - */ -package io.geekidea.springbootplus.config; \ No newline at end of file + * @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/common/package-info.java b/src/main/java/io/geekidea/springbootplus/generator/package-info.java similarity index 88% rename from src/main/java/io/geekidea/springbootplus/common/package-info.java rename to src/main/java/io/geekidea/springbootplus/generator/package-info.java index f943efa2..d70cb518 100644 --- a/src/main/java/io/geekidea/springbootplus/common/package-info.java +++ b/src/main/java/io/geekidea/springbootplus/generator/package-info.java @@ -15,8 +15,7 @@ */ /** - * 公共部分 * @author geekidea - * @date 2018-11-08 - */ -package io.geekidea.springbootplus.common; \ No newline at end of file + * @date 2019-10-11 + **/ +package io.geekidea.springbootplus.generator; \ No newline at end of file diff --git a/src/main/java/io/geekidea/springbootplus/common/web/interceptor/PermissionInterceptor.java b/src/main/java/io/geekidea/springbootplus/interceptor/PermissionInterceptor.java similarity index 69% rename from src/main/java/io/geekidea/springbootplus/common/web/interceptor/PermissionInterceptor.java rename to src/main/java/io/geekidea/springbootplus/interceptor/PermissionInterceptor.java index 52d434f1..d17dcfb9 100644 --- a/src/main/java/io/geekidea/springbootplus/common/web/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.web.interceptor; +package io.geekidea.springbootplus.interceptor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.servlet.ModelAndView; @@ -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/resource/web/controller/DownloadController.java b/src/main/java/io/geekidea/springbootplus/resource/controller/DownloadController.java similarity index 92% 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 1510b3ae..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,15 +14,16 @@ * 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.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/controller/ResourceController.java similarity index 93% 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 d645ac9b..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,10 +14,10 @@ * 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.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/controller/UploadController.java similarity index 93% 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 cc18985b..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.core.SpringBootPlusProperties; -import io.geekidea.springbootplus.system.web.vo.SysLogQueryVo; +import io.geekidea.springbootplus.common.param.IdParam; +import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties; +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 92% 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 abd0daec..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,10 +14,10 @@ * 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.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/interceptor/ResourceInterceptor.java similarity index 92% 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 d5b3db8d..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,10 +14,10 @@ * 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.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/interceptor/UploadInterceptor.java similarity index 92% 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 314c2fa4..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,10 +14,10 @@ * 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.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/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 dde4d98d..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,6 +17,8 @@ package io.geekidea.springbootplus.shiro.config; import com.alibaba.fastjson.JSON; +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; 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配置 @@ -264,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/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/shiro/controller/LoginController.java b/src/main/java/io/geekidea/springbootplus/shiro/controller/LoginController.java index 237bf88a..dee1faa9 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/controller/LoginController.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/controller/LoginController.java @@ -17,11 +17,8 @@ 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; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -49,14 +46,8 @@ public class LoginController { @Autowired private LoginService loginService; - @Autowired - private LoginRedisService loginRedisService; - - @Autowired - private JwtProperties jwtProperties; - @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/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/system/controller/HelloWorldController.java b/src/main/java/io/geekidea/springbootplus/system/controller/HelloWorldController.java new file mode 100644 index 00000000..a2182d43 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/system/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.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/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/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..8a91ccd0 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/xss/XssHttpServletRequestWrapper.java @@ -0,0 +1,62 @@ +/* + * 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() { + return StringEscapeUtils.escapeHtml4(super.getQueryString()); + } + + @Override + public String getParameter(String name) { + return StringEscapeUtils.escapeHtml4(super.getParameter(name)); + } + + @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++) { + escapeValues[i] = StringEscapeUtils.escapeHtml4(values[i]); + } + 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..d612dbdb --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/xss/XssJacksonDeserializer.java @@ -0,0 +1,41 @@ +/* + * 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 { + return StringEscapeUtils.escapeHtml4(jsonParser.getText()); + } + +} 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..71bdbde8 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/xss/XssJacksonSerializer.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.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.text.StringEscapeUtils; + +import java.io.IOException; + +/** + * Jackson响应参数字符串转义处理 + * + * @author geekidea + * @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 { + jsonGenerator.writeString(StringEscapeUtils.escapeHtml4(s)); + } + +} diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 5c3e4ff9..88f2e405 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 ############################### @@ -38,33 +38,39 @@ 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: | + /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-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配置 - request-path-config: - enabled: true - include-paths: /** - # 跨域Filter配置 - cross-domain-config: - enabled: true - include-paths: /** - # 文件上传下载配置 # 上传路径配置 upload-path: /opt/upload/ @@ -78,12 +84,36 @@ 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: x-requested-with,content-type,token + # 是否允许发送cookie + allow-credentials: true + # 允许访问的请求方式 + allowed-methods: OPTION,GET,POST + # 允许响应的头 + exposed-headers: token + # 该响应的有效时间默认为30分钟,在有效时间内,浏览器无须为同一请求再次发起预检请求 + max-age: 1800 + + ############################ 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 +122,12 @@ spring-boot-plus: /=anon /static/**=anon /templates/**=anon + /druid/**=anon + /hello/world=anon + /ip/**=anon + /sysLog/**=anon # 权限配置 - permission-config: + permission: # 排除登陆登出相关 - urls: /login,/logout permission: anon @@ -101,7 +135,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 +147,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 +183,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: @@ -193,12 +231,6 @@ spring: --- spring: redis: - jedis: - pool: - max-active: 2000 - max-wait: -1ms - min-idle: 8 - max-idle: 200 timeout: 10s lettuce: pool: 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 3e7e15e3..d80d8847 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; @@ -44,29 +45,56 @@ 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 + ".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 + ".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 + ".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 + ".param.OrderQueryParam"; + private static final String COMMON_PAGING = COMMON_PARENT_PACKAGE + ".vo.Paging"; + // 包名称 + private static final String PACKAGE_CONTROLLER= "controller"; // ############################ 配置部分 start ############################ // 模块名称 - private static final String MODULE_NAME = "system"; + private static final String MODULE_NAME = "hello"; // 作者 private static final String AUTHOR = "geekidea"; // 生成的表名称 - private static final String TABLE_NAME = "sys_user"; + private static final String TABLE_NAME = "hello"; // 主键数据库列名称 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; + 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 ############################ @@ -95,13 +123,16 @@ public static void main(String[] args) { dsc.setDriverName(DRIVER_NAME); dsc.setUsername(USER_NAME); dsc.setPassword(PASSWORD); + // 设置自定义查询 + dsc.setDbQuery(new SpringBootPlusMySqlQuery()); + mpg.setDataSource(dsc); // 包配置 PackageConfig pc = new PackageConfig(); pc.setModuleName(MODULE_NAME); pc.setParent(PARENT_PACKAGE); - pc.setController("web.controller"); + pc.setController(PACKAGE_CONTROLLER); mpg.setPackageInfo(pc); @@ -110,80 +141,114 @@ public static void main(String[] args) { @Override public void initMap() { + String camelTableName = underlineToCamel(TABLE_NAME); String pascalTableName = underlineToPascal(TABLE_NAME); 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"); // 实体对象名称 - 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驼峰名称 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校验 + map.put("paramValidation", PARAM_VALIDATION); this.setMap(map); } }; 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() + "/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() + "/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(); @@ -222,4 +287,5 @@ public static String underlineToPascal(String underline) { return null; } + } diff --git a/src/main/java/io/geekidea/springbootplus/resource/package-info.java b/src/test/java/io/geekidea/springbootplus/test/PathMatcherTest.java similarity index 58% rename from src/main/java/io/geekidea/springbootplus/resource/package-info.java rename to src/test/java/io/geekidea/springbootplus/test/PathMatcherTest.java index 68753d22..a235e897 100644 --- a/src/main/java/io/geekidea/springbootplus/resource/package-info.java +++ b/src/test/java/io/geekidea/springbootplus/test/PathMatcherTest.java @@ -14,4 +14,23 @@ * limitations under the License. */ -package io.geekidea.springbootplus.resource; \ No newline at end of file +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); + + } + +} 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; diff --git a/src/test/resources/templates/controller.java.vm b/src/test/resources/templates/controller.java.vm index 7930f041..3553e91c 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}; @@ -63,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); } @@ -73,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); } @@ -83,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); } @@ -93,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); } @@ -103,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); } diff --git a/src/test/resources/templates/entity.java.vm b/src/test/resources/templates/entity.java.vm index fc801134..0b82076e 100644 --- a/src/test/resources/templates/entity.java.vm +++ b/src/test/resources/templates/entity.java.vm @@ -13,6 +13,11 @@ import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; #end +#if(${cfg.paramValidation}) +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +#end + /** *

* $!{table.comment} @@ -96,8 +101,22 @@ public class ${entity} implements Serializable { #if(${custom_is_pk}) 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}不能为空") +#else +@NotNull(message = "${field.comment}不能为空") +#end + private ${field.propertyType} ${field.propertyName}; +#else private ${field.propertyType} ${field.propertyName}; #end +#else +private ${field.propertyType} ${field.propertyName}; +#end +#end #end ## ---------- END 字段循环遍历 ---------- #if(!${entityLombokModel})