style: 使用常量优化部分魔法值

This commit is contained in:
2023-03-31 23:31:30 +08:00
parent 48de2e85e0
commit e6f7429fa3
10 changed files with 27 additions and 11 deletions

View File

@@ -45,6 +45,11 @@ public class StringConsts implements StrPool {
*/
public static final String ASTERISK = "*";
/**
* 问号
*/
public static final String QUESTION_MARK = "?";
/**
* 中文逗号
*/

View File

@@ -25,6 +25,8 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import top.charles7c.cnadmin.common.constant.StringConsts;
/**
* 异常工具类
*
@@ -99,7 +101,7 @@ public class ExceptionUtils {
* @return /
*/
public static String exToBlank(ExSupplier<String> exSupplier) {
return exToDefault(exSupplier, "");
return exToDefault(exSupplier, StringConsts.EMPTY);
}
/**

View File

@@ -24,6 +24,7 @@ import lombok.extern.slf4j.Slf4j;
import cn.hutool.core.util.StrUtil;
import top.charles7c.cnadmin.common.constant.StringConsts;
import top.charles7c.cnadmin.common.exception.ServiceException;
/**
@@ -52,8 +53,8 @@ public class CheckUtils extends Validator {
* 字段值
*/
public static void throwIfNotExists(Object obj, String entityName, String fieldName, Object fieldValue) {
String message =
String.format("%s 为 [%s] 的 %s 记录已不存在", fieldName, fieldValue, StrUtil.replace(entityName, "DO", ""));
String message = String.format("%s 为 [%s] 的 %s 记录已不存在", fieldName, fieldValue,
StrUtil.replace(entityName, "DO", StringConsts.EMPTY));
throwIfNull(obj, message, EXCEPTION_TYPE);
}