mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-12 05:01:41 +08:00
refactor: 优化部分错误提示信息和代码注释
This commit is contained in:
@@ -44,7 +44,7 @@ public class Validator {
|
|||||||
* 如果为空,抛出异常
|
* 如果为空,抛出异常
|
||||||
*
|
*
|
||||||
* @param obj 被检测的对象
|
* @param obj 被检测的对象
|
||||||
* @param message 错误信息
|
* @param message 提示信息
|
||||||
* @param exceptionType 异常类型
|
* @param exceptionType 异常类型
|
||||||
*/
|
*/
|
||||||
protected static void throwIfNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
protected static void throwIfNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
||||||
@@ -55,7 +55,7 @@ public class Validator {
|
|||||||
* 如果不为空,抛出异常
|
* 如果不为空,抛出异常
|
||||||
*
|
*
|
||||||
* @param obj 被检测的对象
|
* @param obj 被检测的对象
|
||||||
* @param message 错误信息
|
* @param message 提示信息
|
||||||
* @param exceptionType 异常类型
|
* @param exceptionType 异常类型
|
||||||
*/
|
*/
|
||||||
protected static void throwIfNotNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
protected static void throwIfNotNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
||||||
@@ -66,7 +66,7 @@ public class Validator {
|
|||||||
* 如果为空,抛出异常
|
* 如果为空,抛出异常
|
||||||
*
|
*
|
||||||
* @param obj 被检测的对象
|
* @param obj 被检测的对象
|
||||||
* @param message 错误信息
|
* @param message 提示信息
|
||||||
* @param exceptionType 异常类型
|
* @param exceptionType 异常类型
|
||||||
*/
|
*/
|
||||||
protected static void throwIfEmpty(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
protected static void throwIfEmpty(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
||||||
@@ -77,7 +77,7 @@ public class Validator {
|
|||||||
* 如果不为空,抛出异常
|
* 如果不为空,抛出异常
|
||||||
*
|
*
|
||||||
* @param obj 被检测的对象
|
* @param obj 被检测的对象
|
||||||
* @param message 错误信息
|
* @param message 提示信息
|
||||||
* @param exceptionType 异常类型
|
* @param exceptionType 异常类型
|
||||||
*/
|
*/
|
||||||
protected static void throwIfNotEmpty(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
protected static void throwIfNotEmpty(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
||||||
@@ -88,7 +88,7 @@ public class Validator {
|
|||||||
* 如果为空,抛出异常
|
* 如果为空,抛出异常
|
||||||
*
|
*
|
||||||
* @param str 被检测的字符串
|
* @param str 被检测的字符串
|
||||||
* @param message 错误信息
|
* @param message 提示信息
|
||||||
* @param exceptionType 异常类型
|
* @param exceptionType 异常类型
|
||||||
*/
|
*/
|
||||||
protected static void throwIfBlank(CharSequence str,
|
protected static void throwIfBlank(CharSequence str,
|
||||||
@@ -101,7 +101,7 @@ public class Validator {
|
|||||||
* 如果不为空,抛出异常
|
* 如果不为空,抛出异常
|
||||||
*
|
*
|
||||||
* @param str 被检测的字符串
|
* @param str 被检测的字符串
|
||||||
* @param message 错误信息
|
* @param message 提示信息
|
||||||
* @param exceptionType 异常类型
|
* @param exceptionType 异常类型
|
||||||
*/
|
*/
|
||||||
protected static void throwIfNotBlank(CharSequence str,
|
protected static void throwIfNotBlank(CharSequence str,
|
||||||
@@ -115,7 +115,7 @@ public class Validator {
|
|||||||
*
|
*
|
||||||
* @param obj1 要比较的对象1
|
* @param obj1 要比较的对象1
|
||||||
* @param obj2 要比较的对象2
|
* @param obj2 要比较的对象2
|
||||||
* @param message 错误信息
|
* @param message 提示信息
|
||||||
* @param exceptionType 异常类型
|
* @param exceptionType 异常类型
|
||||||
*/
|
*/
|
||||||
protected static void throwIfEqual(Object obj1,
|
protected static void throwIfEqual(Object obj1,
|
||||||
@@ -130,7 +130,7 @@ public class Validator {
|
|||||||
*
|
*
|
||||||
* @param obj1 要比较的对象1
|
* @param obj1 要比较的对象1
|
||||||
* @param obj2 要比较的对象2
|
* @param obj2 要比较的对象2
|
||||||
* @param message 错误信息
|
* @param message 提示信息
|
||||||
* @param exceptionType 异常类型
|
* @param exceptionType 异常类型
|
||||||
*/
|
*/
|
||||||
protected static void throwIfNotEqual(Object obj1,
|
protected static void throwIfNotEqual(Object obj1,
|
||||||
@@ -145,7 +145,7 @@ public class Validator {
|
|||||||
*
|
*
|
||||||
* @param str1 要比较的字符串1
|
* @param str1 要比较的字符串1
|
||||||
* @param str2 要比较的字符串2
|
* @param str2 要比较的字符串2
|
||||||
* @param message 错误信息
|
* @param message 提示信息
|
||||||
* @param exceptionType 异常类型
|
* @param exceptionType 异常类型
|
||||||
*/
|
*/
|
||||||
protected static void throwIfEqualIgnoreCase(CharSequence str1,
|
protected static void throwIfEqualIgnoreCase(CharSequence str1,
|
||||||
@@ -160,7 +160,7 @@ public class Validator {
|
|||||||
*
|
*
|
||||||
* @param str1 要比较的字符串1
|
* @param str1 要比较的字符串1
|
||||||
* @param str2 要比较的字符串2
|
* @param str2 要比较的字符串2
|
||||||
* @param message 错误信息
|
* @param message 提示信息
|
||||||
* @param exceptionType 异常类型
|
* @param exceptionType 异常类型
|
||||||
*/
|
*/
|
||||||
protected static void throwIfNotEqualIgnoreCase(CharSequence str1,
|
protected static void throwIfNotEqualIgnoreCase(CharSequence str1,
|
||||||
@@ -174,7 +174,7 @@ public class Validator {
|
|||||||
* 如果条件成立,抛出异常
|
* 如果条件成立,抛出异常
|
||||||
*
|
*
|
||||||
* @param condition 条件
|
* @param condition 条件
|
||||||
* @param message 错误信息
|
* @param message 提示信息
|
||||||
* @param exceptionType 异常类型
|
* @param exceptionType 异常类型
|
||||||
*/
|
*/
|
||||||
protected static void throwIf(boolean condition, String message, Class<? extends RuntimeException> exceptionType) {
|
protected static void throwIf(boolean condition, String message, Class<? extends RuntimeException> exceptionType) {
|
||||||
|
@@ -67,7 +67,7 @@ public class SqlInjectionUtils {
|
|||||||
* 检查参数是否存在 SQL 注入
|
* 检查参数是否存在 SQL 注入
|
||||||
*
|
*
|
||||||
* @param value 检查参数
|
* @param value 检查参数
|
||||||
* @return true:非法;false:合法
|
* @return true:存在;false:不存在
|
||||||
*/
|
*/
|
||||||
public static boolean check(String value) {
|
public static boolean check(String value) {
|
||||||
return check(value, null);
|
return check(value, null);
|
||||||
@@ -78,7 +78,7 @@ public class SqlInjectionUtils {
|
|||||||
*
|
*
|
||||||
* @param value 检查参数
|
* @param value 检查参数
|
||||||
* @param customKeyword 自定义关键字
|
* @param customKeyword 自定义关键字
|
||||||
* @return true:非法;false:合法
|
* @return true:存在;false:不存在
|
||||||
*/
|
*/
|
||||||
public static boolean check(String value, String customKeyword) {
|
public static boolean check(String value, String customKeyword) {
|
||||||
if (CharSequenceUtil.isBlank(value)) {
|
if (CharSequenceUtil.isBlank(value)) {
|
||||||
@@ -114,7 +114,7 @@ public class SqlInjectionUtils {
|
|||||||
*
|
*
|
||||||
* @param value 检查参数
|
* @param value 检查参数
|
||||||
* @param keywords 关键字列表
|
* @param keywords 关键字列表
|
||||||
* @return true:非法;false:合法
|
* @return true:存在;false:不存在
|
||||||
*/
|
*/
|
||||||
private static boolean checkKeyword(String value, String[] keywords) {
|
private static boolean checkKeyword(String value, String[] keywords) {
|
||||||
for (String keyword : keywords) {
|
for (String keyword : keywords) {
|
||||||
|
@@ -92,7 +92,7 @@ public class QueryWrapperHelper {
|
|||||||
if (sort != null && sort.isSorted()) {
|
if (sort != null && sort.isSorted()) {
|
||||||
for (Sort.Order order : sort) {
|
for (Sort.Order order : sort) {
|
||||||
String field = CharSequenceUtil.toUnderlineCase(order.getProperty());
|
String field = CharSequenceUtil.toUnderlineCase(order.getProperty());
|
||||||
ValidationUtils.throwIf(SqlInjectionUtils.check(field), "排序字段包含非法字符");
|
ValidationUtils.throwIf(SqlInjectionUtils.check(field), "排序字段包含无效字符");
|
||||||
queryWrapper.orderBy(field, order.isAscending());
|
queryWrapper.orderBy(field, order.isAscending());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -104,7 +104,7 @@ public class QueryWrapperHelper {
|
|||||||
if (sort != null && sort.isSorted()) {
|
if (sort != null && sort.isSorted()) {
|
||||||
for (Sort.Order order : sort) {
|
for (Sort.Order order : sort) {
|
||||||
String field = CharSequenceUtil.toUnderlineCase(order.getProperty());
|
String field = CharSequenceUtil.toUnderlineCase(order.getProperty());
|
||||||
ValidationUtils.throwIf(SqlInjectionUtils.check(field), "排序字段包含非法字符");
|
ValidationUtils.throwIf(SqlInjectionUtils.check(field), "排序字段包含无效字符");
|
||||||
queryWrapper.orderBy(true, order.isAscending(), field);
|
queryWrapper.orderBy(true, order.isAscending(), field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -56,7 +56,7 @@ public class SortQuery implements Serializable {
|
|||||||
if (ArrayUtil.isEmpty(sort)) {
|
if (ArrayUtil.isEmpty(sort)) {
|
||||||
return Sort.unsorted();
|
return Sort.unsorted();
|
||||||
}
|
}
|
||||||
ValidationUtils.throwIf(sort.length < 2, "排序条件非法");
|
ValidationUtils.throwIf(sort.length < 2, "排序条件无效");
|
||||||
List<Sort.Order> orders = new ArrayList<>(sort.length);
|
List<Sort.Order> orders = new ArrayList<>(sort.length);
|
||||||
if (CharSequenceUtil.contains(sort[0], StringConstants.COMMA)) {
|
if (CharSequenceUtil.contains(sort[0], StringConstants.COMMA)) {
|
||||||
// e.g "sort=createTime,desc&sort=name,asc"
|
// e.g "sort=createTime,desc&sort=name,asc"
|
||||||
@@ -83,7 +83,7 @@ public class SortQuery implements Serializable {
|
|||||||
* @return 排序条件
|
* @return 排序条件
|
||||||
*/
|
*/
|
||||||
private Sort.Order getOrder(String field, String direction) {
|
private Sort.Order getOrder(String field, String direction) {
|
||||||
ValidationUtils.throwIf(SqlInjectionUtils.check(field), "排序字段包含非法字符");
|
ValidationUtils.throwIf(SqlInjectionUtils.check(field), "排序字段包含无效字符");
|
||||||
return new Sort.Order(Sort.Direction.valueOf(direction.toUpperCase()), field);
|
return new Sort.Order(Sort.Direction.valueOf(direction.toUpperCase()), field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -174,7 +174,7 @@ public class MailConfig {
|
|||||||
javaMailProperties.put("mail.smtp.auth", true);
|
javaMailProperties.put("mail.smtp.auth", true);
|
||||||
javaMailProperties.put("mail.smtp.ssl.enable", this.isSslEnabled());
|
javaMailProperties.put("mail.smtp.ssl.enable", this.isSslEnabled());
|
||||||
if (this.isSslEnabled()) {
|
if (this.isSslEnabled()) {
|
||||||
ValidationUtils.throwIfNull(this.getSslPort(), "邮件配置错误:SSL端口不能为空");
|
ValidationUtils.throwIfNull(this.getSslPort(), "邮件配置不正确:SSL端口不能为空");
|
||||||
javaMailProperties.put("mail.smtp.socketFactory.port", this.sslPort);
|
javaMailProperties.put("mail.smtp.socketFactory.port", this.sslPort);
|
||||||
javaMailProperties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
javaMailProperties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
||||||
}
|
}
|
||||||
|
@@ -42,20 +42,20 @@ public interface MailConfigurer {
|
|||||||
*/
|
*/
|
||||||
default void apply(MailConfig mailConfig, JavaMailSenderImpl sender) {
|
default void apply(MailConfig mailConfig, JavaMailSenderImpl sender) {
|
||||||
String protocolLowerCase = mailConfig.getProtocol().toLowerCase();
|
String protocolLowerCase = mailConfig.getProtocol().toLowerCase();
|
||||||
ValidationUtils.throwIfNotEqual(MailConfig.DEFAULT_PROTOCOL, protocolLowerCase, "邮件配置错误:不支持的邮件发送协议: %s"
|
ValidationUtils.throwIfNotEqual(MailConfig.DEFAULT_PROTOCOL, protocolLowerCase, "邮件配置不正确:不支持的邮件发送协议: %s"
|
||||||
.formatted(mailConfig.getProtocol()));
|
.formatted(mailConfig.getProtocol()));
|
||||||
sender.setProtocol(mailConfig.getProtocol());
|
sender.setProtocol(mailConfig.getProtocol());
|
||||||
|
|
||||||
ValidationUtils.throwIfBlank(mailConfig.getHost(), "邮件配置错误:服务器地址不能为空");
|
ValidationUtils.throwIfBlank(mailConfig.getHost(), "邮件配置不正确:服务器地址不能为空");
|
||||||
sender.setHost(mailConfig.getHost());
|
sender.setHost(mailConfig.getHost());
|
||||||
|
|
||||||
ValidationUtils.throwIfNull(mailConfig.getPort(), "邮件配置错误:服务器端口不能为空");
|
ValidationUtils.throwIfNull(mailConfig.getPort(), "邮件配置不正确:服务器端口不能为空");
|
||||||
sender.setPort(mailConfig.getPort());
|
sender.setPort(mailConfig.getPort());
|
||||||
|
|
||||||
ValidationUtils.throwIfBlank(mailConfig.getUsername(), "邮件配置错误:用户名不能为空");
|
ValidationUtils.throwIfBlank(mailConfig.getUsername(), "邮件配置不正确:用户名不能为空");
|
||||||
sender.setUsername(mailConfig.getUsername());
|
sender.setUsername(mailConfig.getUsername());
|
||||||
|
|
||||||
ValidationUtils.throwIfBlank(mailConfig.getPassword(), "邮件配置错误:密码不能为空");
|
ValidationUtils.throwIfBlank(mailConfig.getPassword(), "邮件配置不正确:密码不能为空");
|
||||||
sender.setPassword(mailConfig.getPassword());
|
sender.setPassword(mailConfig.getPassword());
|
||||||
|
|
||||||
if (mailConfig.getDefaultEncoding() != null) {
|
if (mailConfig.getDefaultEncoding() != null) {
|
||||||
|
@@ -374,7 +374,8 @@ public class OssStorageStrategy implements StorageStrategy<OssClient> {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 如果 getBucketAcl 失败,可能是权限或连接问题
|
// 如果 getBucketAcl 失败,可能是权限或连接问题
|
||||||
log.error("获取桶 ACL 失败: {}", e.getMessage());
|
log.error("获取桶 ACL 失败: {}", e.getMessage());
|
||||||
return true; // 出现错误时,默认认为桶是私有的
|
// 出现错误时,默认认为桶是私有的
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user