修改代码生成器
This commit is contained in:
parent
87e8c59cf0
commit
88d44f0a77
|
|
@ -0,0 +1,83 @@
|
|||
package com.czg.system.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 版本管理 实体类。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-12
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("tb_version")
|
||||
public class Version implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* LDBL_APP;WX;
|
||||
*/
|
||||
private String source;
|
||||
|
||||
/**
|
||||
* ios;android;
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 版本号
|
||||
*/
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* 0:不更新;1:更新
|
||||
*/
|
||||
private Integer isUp;
|
||||
|
||||
/**
|
||||
* 更新提示内容
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 下载地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 选中 0否 1是
|
||||
*/
|
||||
private Integer sel;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.czg.system.service;
|
||||
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.system.entity.Version;
|
||||
|
||||
/**
|
||||
* 版本管理 服务层。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-12
|
||||
*/
|
||||
public interface VersionService extends IService<Version> {
|
||||
|
||||
}
|
||||
|
|
@ -24,35 +24,42 @@ public class Main {
|
|||
dataSource.setUsername(USERNAME);
|
||||
dataSource.setPassword(PASSWORD);
|
||||
|
||||
//创建配置内容,两种风格都可以。
|
||||
GlobalConfig globalConfig = createGlobalConfigUseStyle();
|
||||
|
||||
//通过 datasource 和 globalConfig 创建代码生成器
|
||||
Generator generator = new Generator(dataSource, globalConfig);
|
||||
|
||||
//生成代码
|
||||
generator.generate();
|
||||
}
|
||||
|
||||
public static GlobalConfig createGlobalConfigUseStyle() {
|
||||
//创建配置内容
|
||||
GlobalConfig globalConfig = new GlobalConfig();
|
||||
|
||||
String currentWorkingDirectory = System.getProperty("user.dir");
|
||||
// String projectPath = currentWorkingDirectory + "/cash-service/system-service";
|
||||
String projectPath = currentWorkingDirectory + "/cash-service/account-service";
|
||||
String projectPath = currentWorkingDirectory + "/cash-service/system-service";
|
||||
// String projectPath = currentWorkingDirectory + "/cash-service/account-service";
|
||||
// String projectPath = currentWorkingDirectory + "/cash-service/product-service";
|
||||
// String projectPath = currentWorkingDirectory + "/cash-service/order-service";
|
||||
|
||||
String packageName = "com.czg.service.system";
|
||||
// String packageName = "com.czg.service.account";
|
||||
// String packageName = "com.czg.service.product";
|
||||
// String packageName = "com.czg.service.order";
|
||||
|
||||
String servicePackageName = "com.czg.system";
|
||||
// String servicePackageName = "com.czg.account";
|
||||
// String servicePackageName = "com.czg.product";
|
||||
// String servicePackageName = "com.czg.order";
|
||||
|
||||
// 生成 mapper 和 service实现
|
||||
GlobalConfig globalConfig = createGlobalConfigUseStyle(projectPath, packageName, "tb", "tb_version");
|
||||
Generator generator = new Generator(dataSource, globalConfig);
|
||||
generator.generate();
|
||||
|
||||
// 生成 entity 和 service
|
||||
GlobalConfig serviceConfig = createServiceGlobalConfigUseStyle(currentWorkingDirectory + "/cash-common/cash-common-service",
|
||||
servicePackageName, "tb", "tb_version");
|
||||
Generator serviceGenerator = new Generator(dataSource, serviceConfig);
|
||||
serviceGenerator.generate();
|
||||
}
|
||||
|
||||
public static GlobalConfig createGlobalConfigUseStyle(String projectPath, String packageName, String tablePrefix, String... tableNames) {
|
||||
//创建配置内容
|
||||
GlobalConfig globalConfig = new GlobalConfig();
|
||||
|
||||
//设置根包
|
||||
globalConfig.getPackageConfig()
|
||||
.setSourceDir(projectPath + "/src/main/java")
|
||||
.setBasePackage("com.czg.service.account");
|
||||
|
||||
globalConfig.getServiceConfig()
|
||||
.setClassSuffix("Service")
|
||||
.setSuperClass(IService.class);
|
||||
globalConfig.enableService();
|
||||
.setBasePackage(packageName);
|
||||
|
||||
globalConfig.getServiceImplConfig()
|
||||
.setClassSuffix("ServiceImpl")
|
||||
|
|
@ -68,17 +75,39 @@ public class Main {
|
|||
|
||||
//设置表前缀和只生成哪些表,setGenerateTable 未配置时,生成所有表
|
||||
globalConfig.getStrategyConfig()
|
||||
.setTablePrefix("tb")
|
||||
.setGenerateTable("tb_user_info");
|
||||
.setTablePrefix(tablePrefix)
|
||||
.setGenerateTable(tableNames);
|
||||
|
||||
//设置生成 mapper
|
||||
globalConfig.enableMapper();
|
||||
|
||||
return globalConfig;
|
||||
}
|
||||
|
||||
public static GlobalConfig createServiceGlobalConfigUseStyle(String projectPath, String packageName, String tablePrefix, String... tableNames) {
|
||||
//创建配置内容
|
||||
GlobalConfig globalConfig = new GlobalConfig();
|
||||
|
||||
//设置根包
|
||||
globalConfig.getPackageConfig()
|
||||
.setSourceDir(projectPath + "/src/main/java")
|
||||
.setBasePackage(packageName);
|
||||
|
||||
globalConfig.getServiceConfig()
|
||||
.setClassSuffix("Service")
|
||||
.setSuperClass(IService.class);
|
||||
globalConfig.enableService();
|
||||
|
||||
//设置表前缀和只生成哪些表,setGenerateTable 未配置时,生成所有表
|
||||
globalConfig.getStrategyConfig()
|
||||
.setTablePrefix(tablePrefix)
|
||||
.setGenerateTable(tableNames);
|
||||
|
||||
//设置生成 entity 并启用 Lombok
|
||||
globalConfig.enableEntity()
|
||||
.setWithLombok(true)
|
||||
.setJdkVersion(23);
|
||||
|
||||
//设置生成 mapper
|
||||
globalConfig.enableMapper();
|
||||
|
||||
//可以单独配置某个列
|
||||
ColumnConfig createTime = new ColumnConfig();
|
||||
createTime.setColumnName("create_time");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package com.czg.service.system.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.system.entity.Version;
|
||||
|
||||
/**
|
||||
* 版本管理 映射层。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-12
|
||||
*/
|
||||
public interface VersionMapper extends BaseMapper<Version> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.czg.service.system.service.impl;
|
||||
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.system.entity.Version;
|
||||
import com.czg.service.system.mapper.VersionMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 版本管理 服务层实现。
|
||||
*
|
||||
* @author mac
|
||||
* @since 2025-02-12
|
||||
*/
|
||||
@Service
|
||||
public class VersionServiceImpl extends ServiceImpl<VersionMapper, Version> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.system.mapper.VersionMapper">
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue