更新依赖;解决依赖冲突;调整、重构代码。
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
package xyz.zhouxy.plusone.exception.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHolder;
|
||||
|
||||
@Configuration
|
||||
public class PlusoneExceptionHandlerConfig {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
ExceptionInfoHolder exceptionInfoHolder() {
|
||||
return new ExceptionInfoHolder(ErrorCodeConsts.DEFAULT_ERROR_CODE);
|
||||
}
|
||||
}
|
@@ -4,8 +4,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHolder;
|
||||
|
||||
/**
|
||||
* AllExceptionHandlerConfig
|
||||
*/
|
||||
@@ -14,7 +12,7 @@ import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHo
|
||||
public class AllExceptionHandlerConfig {
|
||||
|
||||
@Bean
|
||||
AllExceptionHandler getAllExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||
return new AllExceptionHandler(exceptionInfoHolder);
|
||||
AllExceptionHandler getAllExceptionHandler() {
|
||||
return new AllExceptionHandler(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder());
|
||||
}
|
||||
}
|
||||
|
@@ -41,13 +41,13 @@ import xyz.zhouxy.plusone.util.RestfulResult;
|
||||
@Slf4j
|
||||
public class DefaultExceptionHandler extends BaseExceptionHandler {
|
||||
|
||||
public DefaultExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
|
||||
super(exceptionInfoHolder);
|
||||
public DefaultExceptionHandler() {
|
||||
super(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder());
|
||||
set(IllegalArgumentException.class, 4010000, "格式错误", HttpStatus.FORBIDDEN);
|
||||
set(DataAccessException.class, 6030000, "数据库错误", HttpStatus.INTERNAL_SERVER_ERROR, true);
|
||||
set(MethodArgumentNotValidException.class,
|
||||
4040401,
|
||||
e -> ((MethodArgumentNotValidException) e).getAllErrors()
|
||||
e -> e.getAllErrors()
|
||||
.stream()
|
||||
.map(DefaultMessageSourceResolvable::getDefaultMessage)
|
||||
.toList()
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>plusone-basic</artifactId>
|
||||
@@ -39,12 +39,12 @@
|
||||
<dependency>
|
||||
<groupId>xyz.zhouxy.plusone</groupId>
|
||||
<artifactId>plusone-validator</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.zhouxy.plusone</groupId>
|
||||
<artifactId>plusone-exception-handler</artifactId>
|
||||
<version>0.0.5-SNAPSHOT</version>
|
||||
<version>0.0.6-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@@ -0,0 +1,15 @@
|
||||
package xyz.zhouxy.plusone.exception.handler;
|
||||
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHolder;
|
||||
|
||||
public class ExceptionInfoHolderFactory {
|
||||
|
||||
private ExceptionInfoHolderFactory() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static ExceptionInfoHolder newDefaultExceptionInfoHolder() {
|
||||
return new ExceptionInfoHolder(ErrorCodeConsts.DEFAULT_ERROR_CODE);
|
||||
}
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
package xyz.zhouxy.plusone.sql;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.ibatis.jdbc.AbstractSQL;
|
||||
|
||||
/**
|
||||
* 扩展 MyBatis 中的 SQL 语句构造器
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
public class SQL extends AbstractSQL<SQL> {
|
||||
|
||||
public SQL SET_IF(boolean condition, String sets) {
|
||||
return condition ? SET(sets) : getSelf();
|
||||
}
|
||||
|
||||
public SQL SET_IF_NOT_NULL(Object param, String sets) {
|
||||
return Objects.nonNull(param) ? SET(sets) : getSelf();
|
||||
}
|
||||
|
||||
public SQL WHERE_IF(boolean condition, String sqlCondition) {
|
||||
return condition ? WHERE(sqlCondition) : getSelf();
|
||||
}
|
||||
|
||||
public SQL WHERE_IF_NOT_NULL(Object param, String sqlCondition) {
|
||||
return Objects.nonNull(param) ? WHERE(sqlCondition) : getSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQL getSelf() {
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -2,14 +2,14 @@ package xyz.zhouxy.plusone.validator;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler;
|
||||
import xyz.zhouxy.plusone.exception.handler.ExceptionInfoHolderFactory;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class InvalidInputExceptionHandler extends BaseExceptionHandler {
|
||||
|
||||
protected InvalidInputExceptionHandler() {
|
||||
super(new ExceptionInfoHolder(ErrorCodeConsts.DEFAULT_ERROR_CODE));
|
||||
super(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder());
|
||||
set(InvalidInputException.class, InvalidInputException.ERROR_CODE, "无效的用户输入");
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import xyz.zhouxy.plusone.constant.RegexConsts;
|
||||
import xyz.zhouxy.plusone.validator.validator2.BaseValidator2;
|
||||
import xyz.zhouxy.plusone.validator.BaseValidator;
|
||||
|
||||
class BaseValidator2Test {
|
||||
|
||||
@@ -27,15 +27,16 @@ class LoginCommand {
|
||||
private boolean rememberMe;
|
||||
}
|
||||
|
||||
class LoginCommandValidator extends BaseValidator2<LoginCommand> {
|
||||
class LoginCommandValidator extends BaseValidator<LoginCommand> {
|
||||
|
||||
public static final LoginCommandValidator INSTANCE = new LoginCommandValidator();
|
||||
|
||||
private LoginCommandValidator() {
|
||||
ruleFor(LoginCommand::getAccount)
|
||||
ruleForString(LoginCommand::getAccount)
|
||||
.notNull("邮箱地址不能为空")
|
||||
.matchesOr(new String[] { RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE }, value -> new RuntimeException('"' + value + "\" 不是邮箱地址或手机号"));
|
||||
ruleFor(LoginCommand::getPwd)
|
||||
.matchesOr(new String[] { RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE },
|
||||
value -> new RuntimeException('"' + value + "\" 不是邮箱地址或手机号"));
|
||||
ruleForString(LoginCommand::getPwd)
|
||||
.notNull("密码不能为空")
|
||||
.notEmpty("密码不能为空")
|
||||
.matches(RegexConsts.PASSWORD, "密码格式错误");
|
||||
|
Reference in New Issue
Block a user