feat: 新增系统模块代码生成器
This commit is contained in:
@@ -17,7 +17,7 @@ import java.util.*;
|
|||||||
* @see <a href="https://baomidou.com/pages/981406">代码生成器配置新</a>
|
* @see <a href="https://baomidou.com/pages/981406">代码生成器配置新</a>
|
||||||
* @since 2024/4/9
|
* @since 2024/4/9
|
||||||
*/
|
*/
|
||||||
public class SystemGenerator {
|
public class SystemCodeGenerator {
|
||||||
|
|
||||||
private static final DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig
|
private static final DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig
|
||||||
.Builder("jdbc:mysql://localhost:3306/youlai_boot?serverTimezone=Asia/Shanghai", "root", "123456");
|
.Builder("jdbc:mysql://localhost:3306/youlai_boot?serverTimezone=Asia/Shanghai", "root", "123456");
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
package com.youlai.boot.system.generator;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
|
|
||||||
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
|
||||||
import com.baomidou.mybatisplus.generator.config.builder.CustomFile;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 代码交互式生成
|
|
||||||
* <p>
|
|
||||||
* 代码生成、MySQL表生成代码、自动代码生成
|
|
||||||
*
|
|
||||||
* @author Ray Hao
|
|
||||||
* @see <a href="https://baomidou.com/pages/981406/">代码生成器配置新</a>
|
|
||||||
* @since 2024/4/9
|
|
||||||
*/
|
|
||||||
public class FastAutoGeneratorTest {
|
|
||||||
|
|
||||||
private static final DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig
|
|
||||||
.Builder("jdbc:mysql://localhost:3306/youlai_boot?serverTimezone=Asia/Shanghai", "root", "123456");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行 run
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
FastAutoGenerator.create(DATA_SOURCE_CONFIG)
|
|
||||||
// 全局配置
|
|
||||||
.globalConfig((scanner, builder) -> {
|
|
||||||
builder.outputDir(System.getProperty("user.dir") + "/src/main/java")
|
|
||||||
.author("Ray Hao") // 设置作者
|
|
||||||
;
|
|
||||||
})
|
|
||||||
// 包配置
|
|
||||||
.packageConfig(builder -> {
|
|
||||||
builder
|
|
||||||
.parent("com.youlai.boot.system")
|
|
||||||
.entity("model.entity")
|
|
||||||
.mapper("mapper")
|
|
||||||
.service("service")
|
|
||||||
.serviceImpl("service.impl")
|
|
||||||
.controller("controller")
|
|
||||||
.pathInfo(Collections.singletonMap(OutputFile.xml, System.getProperty("user.dir") + "/src/main/resources/mapper"));
|
|
||||||
}
|
|
||||||
)
|
|
||||||
// 注入配置(设置扩展类的模板路径和包路径)
|
|
||||||
.injectionConfig(consumer -> {
|
|
||||||
List<CustomFile> customFiles = new ArrayList<>();
|
|
||||||
customFiles.add(new CustomFile.Builder().fileName("VO.java").templatePath("/templates/codegen/vo.java.vm").packageName("model.vo").build());
|
|
||||||
customFiles.add(new CustomFile.Builder().fileName("BO.java").templatePath("/templates/codegen/bo.java.vm").packageName("model.bo").build());
|
|
||||||
customFiles.add(new CustomFile.Builder().fileName("PageQuery.java").templatePath("/templates/codegen/query.java.vm").packageName("model.query").build());
|
|
||||||
customFiles.add(new CustomFile.Builder().fileName("PageVO.java").templatePath("/templates/codegen/pageVO.java.vm").packageName("model.vo").build());
|
|
||||||
customFiles.add(new CustomFile.Builder().fileName("Form.java").templatePath("/templates/codegen/form.java.vm").packageName("model.form").build());
|
|
||||||
customFiles.add(new CustomFile.Builder().fileName("Converter.java").templatePath("/templates/codegen/converter.java.vm").packageName("converter").build());
|
|
||||||
consumer.customFile(customFiles);
|
|
||||||
consumer.beforeOutputFile((tableInfo, objectMap) -> {
|
|
||||||
// 为每个表生成首字母小写的实体名
|
|
||||||
String entityName = tableInfo.getEntityName();
|
|
||||||
String lowerCaseEntity = entityName.substring(0, 1).toLowerCase() + entityName.substring(1);
|
|
||||||
// 注入自定义参数
|
|
||||||
objectMap.put("lowerFirstEntityName", lowerCaseEntity);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
})
|
|
||||||
// 策略配置
|
|
||||||
.strategyConfig((scanner, builder) -> {
|
|
||||||
|
|
||||||
builder.entityBuilder()
|
|
||||||
.enableLombok() // 是否使用lombok
|
|
||||||
//.enableFileOverride() // 开启覆盖已生成的文件
|
|
||||||
.logicDeleteColumnName("deleted") // 逻辑删除字段名
|
|
||||||
.enableRemoveIsPrefix() // 开启移除is前缀
|
|
||||||
;
|
|
||||||
|
|
||||||
builder.mapperBuilder()
|
|
||||||
.enableBaseColumnList()
|
|
||||||
.enableBaseResultMap()
|
|
||||||
;
|
|
||||||
|
|
||||||
builder.serviceBuilder()
|
|
||||||
.formatServiceFileName("%sService"
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
builder.addTablePrefix("sys_") // 过滤移除表前缀 sys_user 表生成的实体类 User.java
|
|
||||||
.addInclude(scanner.apply("请输入表名,多个表名用,隔开"));
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.execute()
|
|
||||||
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.youlai.boot.system.laboratory;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SpringBoot 配置加载顺序单元测试类
|
|
||||||
*
|
|
||||||
* @author haoxr
|
|
||||||
* @since 2023/02/23
|
|
||||||
*/
|
|
||||||
@SpringBootTest
|
|
||||||
@Slf4j
|
|
||||||
public class ConfigLoadOrderTests {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试配置加载顺序
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testConfigLoadOrder(ApplicationContext context) {
|
|
||||||
Environment environment = context.getEnvironment();
|
|
||||||
String property = environment.getProperty("config.name");
|
|
||||||
log.info(property);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package com.youlai.boot.system.middleware;
|
|
||||||
|
|
||||||
import com.youlai.boot.system.model.entity.User;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Redis 单元测试
|
|
||||||
*
|
|
||||||
* @author haoxr
|
|
||||||
* @since 2023/02/17
|
|
||||||
*/
|
|
||||||
@SpringBootTest
|
|
||||||
@Slf4j
|
|
||||||
public class RedisTests {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RedisTemplate redisTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Redis 序列化测试
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testRedisSerializer() {
|
|
||||||
User user = new User();
|
|
||||||
user.setId(1l);
|
|
||||||
user.setNickname("张三");
|
|
||||||
// 写
|
|
||||||
redisTemplate.opsForValue().set("user", user);
|
|
||||||
|
|
||||||
// 读
|
|
||||||
User userCache = (User)redisTemplate.opsForValue().get("user");
|
|
||||||
log.info("userCache:{}", userCache);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user