|
@@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.template.TemplateConfig;
|
|
|
import cn.hutool.extra.template.TemplateEngine;
|
|
|
import cn.hutool.extra.template.engine.velocity.VelocityEngine;
|
|
|
+import cn.hutool.system.SystemUtil;
|
|
|
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
@@ -35,10 +36,11 @@ import com.google.common.annotations.VisibleForTesting;
|
|
|
import com.google.common.collect.ImmutableTable;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.google.common.collect.Table;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
import jakarta.annotation.PostConstruct;
|
|
|
import jakarta.annotation.Resource;
|
|
|
+import lombok.Setter;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
import java.util.*;
|
|
|
|
|
|
import static cn.hutool.core.map.MapUtil.getStr;
|
|
@@ -156,6 +158,15 @@ public class CodegenEngine {
|
|
|
@Resource
|
|
|
private CodegenProperties codegenProperties;
|
|
|
|
|
|
+ /**
|
|
|
+ * 是否使用 jakarta 包,用于解决 Spring Boot 2.X 和 3.X 的兼容性问题
|
|
|
+ *
|
|
|
+ * true - 使用 jakarta.validation.constraints.*
|
|
|
+ * false - 使用 javax.validation.constraints.*
|
|
|
+ */
|
|
|
+ @Setter // 允许设置的原因,是因为单测需要手动改变
|
|
|
+ private Boolean jakartaEnable;
|
|
|
+
|
|
|
/**
|
|
|
* 模板引擎,由 hutool 实现
|
|
|
*/
|
|
@@ -170,6 +181,8 @@ public class CodegenEngine {
|
|
|
TemplateConfig config = new TemplateConfig();
|
|
|
config.setResourceMode(TemplateConfig.ResourceMode.CLASSPATH);
|
|
|
this.templateEngine = new VelocityEngine(config);
|
|
|
+ // 设置 javaxEnable,按照是否使用 JDK17 来判断
|
|
|
+ this.jakartaEnable = SystemUtil.getJavaInfo().isJavaVersionAtLeast(1700); // 17.00 * 100
|
|
|
}
|
|
|
|
|
|
@PostConstruct
|
|
@@ -179,6 +192,7 @@ public class CodegenEngine {
|
|
|
globalBindingMap.put("basePackage", codegenProperties.getBasePackage());
|
|
|
globalBindingMap.put("baseFrameworkPackage", codegenProperties.getBasePackage()
|
|
|
+ '.' + "framework"); // 用于后续获取测试类的 package 地址
|
|
|
+ globalBindingMap.put("jakartaPackage", jakartaEnable ? "jakarta" : "javax");
|
|
|
// 全局 Java Bean
|
|
|
globalBindingMap.put("CommonResultClassName", CommonResult.class.getName());
|
|
|
globalBindingMap.put("PageResultClassName", PageResult.class.getName());
|