plusone-commons 重构,代码随之重构调整。

This commit is contained in:
2023-02-24 17:30:18 +08:00
parent 9293ba6817
commit a0b16afde2
33 changed files with 91 additions and 97 deletions

View File

@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import lombok.extern.slf4j.Slf4j;
import xyz.zhouxy.plusone.util.RestfulResult;
import xyz.zhouxy.plusone.commons.util.RestfulResult;
/**
* 默认异常的处理器

View File

@@ -8,8 +8,8 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import lombok.extern.slf4j.Slf4j;
import xyz.zhouxy.plusone.commons.util.RestfulResult;
import xyz.zhouxy.plusone.exception.SysException;
import xyz.zhouxy.plusone.util.RestfulResult;
@RestControllerAdvice
@Slf4j

View File

@@ -1,5 +1,7 @@
package xyz.zhouxy.plusone.exception;
import xyz.zhouxy.plusone.commons.exception.BaseException;
/**
* 业务异常
*

View File

@@ -1,5 +1,7 @@
package xyz.zhouxy.plusone.exception;
import xyz.zhouxy.plusone.commons.exception.BaseException;
public class SysException extends BaseException {
@java.io.Serial
private static final long serialVersionUID = 8821240827443168118L;

View File

@@ -1,6 +1,6 @@
package xyz.zhouxy.plusone.constant;
import xyz.zhouxy.plusone.util.Enumeration;
import xyz.zhouxy.plusone.commons.util.Enumeration;
/**
* 实体状态

View File

@@ -1,36 +0,0 @@
package xyz.zhouxy.plusone.util;
import java.util.regex.Pattern;
public class RegexUtil {
private RegexUtil() {
throw new IllegalStateException("Utility class");
}
public static boolean matches(CharSequence input, String regex) {
return Pattern.matches(regex, input);
}
public static boolean matchesOr(CharSequence input, String... regexs) {
boolean isMatched;
for (var regex : regexs) {
isMatched = Pattern.matches(regex, input);
if (isMatched) {
return true;
}
}
return false;
}
public static boolean matchesAnd(CharSequence input, String... regexs) {
boolean isMatched;
for (var regex : regexs) {
isMatched = Pattern.matches(regex, input);
if (!isMatched) {
return false;
}
}
return true;
}
}

View File

@@ -15,8 +15,8 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import xyz.zhouxy.plusone.commons.util.NumberUtil;
import xyz.zhouxy.plusone.exception.DataOperationResultException;
import xyz.zhouxy.plusone.util.NumberUtil;
public abstract class PlusoneJdbcDaoSupport {
protected final NamedParameterJdbcTemplate jdbc;

View File

@@ -1,11 +1,13 @@
package xyz.zhouxy.plusone.validatortest;
import java.util.regex.Pattern;
import org.junit.jupiter.api.Test;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import xyz.zhouxy.plusone.constant.RegexConsts;
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
import xyz.zhouxy.plusone.validator.BaseValidator;
class BaseValidatorTest {
@@ -34,11 +36,11 @@ class LoginCommandValidator extends BaseValidator<LoginCommand> {
private LoginCommandValidator() {
ruleForString(LoginCommand::getAccount)
.notNull("邮箱地址不能为空")
.matchesOr(new String[] { RegexConsts.EMAIL, RegexConsts.MOBILE_PHONE },
.matchesOr(new Pattern[] { PatternConsts.EMAIL, PatternConsts.MOBILE_PHONE },
value -> new RuntimeException('"' + value + "\" 不是邮箱地址或手机号"));
ruleForString(LoginCommand::getPwd)
.notNull("密码不能为空")
.notEmpty("密码不能为空")
.matches(RegexConsts.PASSWORD, "密码格式错误");
.matches(PatternConsts.PASSWORD, "密码格式错误");
}
}