项目优化,构建文件Lombok异常问题修复

This commit is contained in:
2026-06-29 13:55:42 +08:00
parent 53b3b2c989
commit 0799f9cb4d
47 changed files with 1034 additions and 865 deletions
@@ -2,30 +2,35 @@
package com.weather.common.utils;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* 树节点,所有需要实现树节点的,都需要继承该类
* 树节点接口,所有需要实现树节点的,都需要实现该接口
*
* @author 123
* @since 1.0.0
*/
@Data
public class TreeNode<T> implements Serializable {
private static final long serialVersionUID = 1L;
public interface TreeNode<T> extends Serializable {
/**
* 主键
*/
private Long id;
Long getId();
void setId(Long id);
/**
* 上级ID
*/
private Long pid;
Long getPid();
void setPid(Long pid);
/**
* 子节点列表
*/
private List<T> children = new ArrayList<>();
List<T> getChildren();
void setChildren(List<T> children);
}
@@ -20,7 +20,7 @@ public class TreeUtils {
/**
* 根据pid,构建树节点
*/
public static <T extends TreeNode> List<T> build(List<T> treeNodes, Long pid) {
public static <T extends TreeNode<T>> List<T> build(List<T> treeNodes, Long pid) {
//pid不能为空
AssertUtils.isNull(pid, "pid");
@@ -37,7 +37,7 @@ public class TreeUtils {
/**
* 查找子节点
*/
private static <T extends TreeNode> T findChildren(List<T> treeNodes, T rootNode) {
private static <T extends TreeNode<T>> T findChildren(List<T> treeNodes, T rootNode) {
for(T treeNode : treeNodes) {
if(rootNode.getId().equals(treeNode.getPid())) {
rootNode.getChildren().add(findChildren(treeNodes, treeNode));
@@ -49,7 +49,7 @@ public class TreeUtils {
/**
* 构建树节点
*/
public static <T extends TreeNode> List<T> build(List<T> treeNodes) {
public static <T extends TreeNode<T>> List<T> build(List<T> treeNodes) {
List<T> result = new ArrayList<>();
//list转map
@@ -6,12 +6,11 @@ import com.weather.common.exception.CommonException;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.validation.beanvalidation.MessageSourceResourceBundleLocator;
import java.util.Locale;
import java.util.Set;
/**
@@ -23,11 +22,16 @@ import java.util.Set;
*/
public class ValidatorUtils {
private static ResourceBundleMessageSource getMessageSource() {
ResourceBundleMessageSource bundleMessageSource = new ResourceBundleMessageSource();
bundleMessageSource.setDefaultEncoding("UTF-8");
bundleMessageSource.setBasenames("i18n/validation");
return bundleMessageSource;
private static final ValidatorFactory VALIDATOR_FACTORY;
static {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setDefaultEncoding("UTF-8");
messageSource.setBasenames("i18n/validation");
VALIDATOR_FACTORY = Validation.byDefaultProvider().configure().messageInterpolator(
new ResourceBundleMessageInterpolator(new MessageSourceResourceBundleLocator(messageSource)))
.buildValidatorFactory();
}
/**
@@ -37,14 +41,11 @@ public class ValidatorUtils {
*/
public static void validateEntity(Object object, Class<?>... groups)
throws CommonException {
Locale.setDefault(LocaleContextHolder.getLocale());
Validator validator = Validation.byDefaultProvider().configure().messageInterpolator(
new ResourceBundleMessageInterpolator(new MessageSourceResourceBundleLocator(getMessageSource())))
.buildValidatorFactory().getValidator();
Validator validator = VALIDATOR_FACTORY.getValidator();
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups);
if (!constraintViolations.isEmpty()) {
ConstraintViolation<Object> constraint = constraintViolations.iterator().next();
ConstraintViolation<Object> constraint = constraintViolations.iterator().next();
throw new CommonException(constraint.getMessage());
}
}