Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
8b83858f59
|
|
@ -1,8 +1,7 @@
|
||||||
package com.czg;
|
package com.czg;
|
||||||
|
|
||||||
import com.mybatisflex.codegen.Generator;
|
import com.mybatisflex.codegen.Generator;
|
||||||
import com.mybatisflex.codegen.config.ColumnConfig;
|
import com.mybatisflex.codegen.config.*;
|
||||||
import com.mybatisflex.codegen.config.GlobalConfig;
|
|
||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
|
@ -16,38 +15,37 @@ public class Main {
|
||||||
private final static String USERNAME = "cashier";
|
private final static String USERNAME = "cashier";
|
||||||
private final static String PASSWORD = "Cashier@1@";
|
private final static String PASSWORD = "Cashier@1@";
|
||||||
private final static String DATABASE = "czg_cashier";
|
private final static String DATABASE = "czg_cashier";
|
||||||
|
static String currentWorkingDirectory = System.getProperty("user.dir");
|
||||||
|
static String basePackage = "com.czg.";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
// packageName 指定生成代码项目
|
||||||
|
// tableName 指定需要生成的表
|
||||||
|
|
||||||
|
// String servicePackageName = "system";
|
||||||
|
// String servicePackageName = "account";
|
||||||
|
// String servicePackageName = "product";
|
||||||
|
String packageName = "order";
|
||||||
|
|
||||||
|
String tableName = "tb_order_info";
|
||||||
|
|
||||||
//配置数据源
|
//配置数据源
|
||||||
HikariDataSource dataSource = new HikariDataSource();
|
HikariDataSource dataSource = new HikariDataSource();
|
||||||
dataSource.setJdbcUrl("jdbc:mysql://" + BASE_URL + ":" + PORT + "/" + DATABASE);
|
dataSource.setJdbcUrl("jdbc:mysql://" + BASE_URL + ":" + PORT + "/" + DATABASE);
|
||||||
dataSource.setUsername(USERNAME);
|
dataSource.setUsername(USERNAME);
|
||||||
dataSource.setPassword(PASSWORD);
|
dataSource.setPassword(PASSWORD);
|
||||||
|
|
||||||
String currentWorkingDirectory = System.getProperty("user.dir");
|
String projectPath = currentWorkingDirectory + "/cash-service/" + packageName + "-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实现
|
// 生成 mapper 和 service实现
|
||||||
GlobalConfig globalConfig = createGlobalConfigUseStyle(projectPath, packageName, "tb", "tb_version");
|
GlobalConfig globalConfig = createGlobalConfigUseStyle(projectPath, packageName, "tb", tableName);
|
||||||
Generator generator = new Generator(dataSource, globalConfig);
|
Generator generator = new Generator(dataSource, globalConfig);
|
||||||
generator.generate();
|
generator.generate();
|
||||||
|
|
||||||
// 生成 entity 和 service
|
// 生成 entity 和 service
|
||||||
GlobalConfig serviceConfig = createServiceGlobalConfigUseStyle(currentWorkingDirectory + "/cash-common/cash-common-service",
|
GlobalConfig serviceConfig = createServiceGlobalConfigUseStyle(currentWorkingDirectory + "/cash-common/cash-common-service",
|
||||||
servicePackageName, "tb", "tb_version");
|
basePackage + packageName, "tb", tableName);
|
||||||
Generator serviceGenerator = new Generator(dataSource, serviceConfig);
|
Generator serviceGenerator = new Generator(dataSource, serviceConfig);
|
||||||
serviceGenerator.generate();
|
serviceGenerator.generate();
|
||||||
}
|
}
|
||||||
|
|
@ -59,12 +57,23 @@ public class Main {
|
||||||
//设置根包
|
//设置根包
|
||||||
globalConfig.getPackageConfig()
|
globalConfig.getPackageConfig()
|
||||||
.setSourceDir(projectPath + "/src/main/java")
|
.setSourceDir(projectPath + "/src/main/java")
|
||||||
.setBasePackage(packageName);
|
|
||||||
|
.setEntityPackage(basePackage + packageName + ".entity")
|
||||||
|
.setServicePackage(basePackage + packageName + ".service")
|
||||||
|
|
||||||
|
.setServiceImplPackage(basePackage + "service." + packageName + ".service.impl")
|
||||||
|
.setMapperPackage(basePackage + "service." + packageName + ".mapper")
|
||||||
|
|
||||||
|
.setBasePackage(basePackage + "service." + packageName);
|
||||||
|
|
||||||
|
globalConfig.getServiceConfig()
|
||||||
|
.setClassSuffix("Service");
|
||||||
|
|
||||||
globalConfig.getServiceImplConfig()
|
globalConfig.getServiceImplConfig()
|
||||||
.setClassSuffix("ServiceImpl")
|
.setClassSuffix("ServiceImpl")
|
||||||
.setSuperClass(ServiceImpl.class);
|
.setSuperClass(ServiceImpl.class);
|
||||||
globalConfig.enableServiceImpl();
|
globalConfig.enableServiceImpl();
|
||||||
|
globalConfig.setServiceImplTemplatePath("templates/serviceImpl.tpl");
|
||||||
|
|
||||||
globalConfig.getMapperConfig()
|
globalConfig.getMapperConfig()
|
||||||
.setClassSuffix("Mapper");
|
.setClassSuffix("Mapper");
|
||||||
|
|
@ -106,7 +115,7 @@ public class Main {
|
||||||
//设置生成 entity 并启用 Lombok
|
//设置生成 entity 并启用 Lombok
|
||||||
globalConfig.enableEntity()
|
globalConfig.enableEntity()
|
||||||
.setWithLombok(true)
|
.setWithLombok(true)
|
||||||
.setJdkVersion(23);
|
.setJdkVersion(21);
|
||||||
|
|
||||||
//可以单独配置某个列
|
//可以单独配置某个列
|
||||||
ColumnConfig createTime = new ColumnConfig();
|
ColumnConfig createTime = new ColumnConfig();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,185 @@
|
||||||
|
#set(isCacheExample = serviceImplConfig.cacheExample)
|
||||||
|
#set(primaryKey = table.getPrimaryKey().getProperty())
|
||||||
|
#set(entityClassName = table.buildEntityClassName())
|
||||||
|
package #(packageConfig.serviceImplPackage);
|
||||||
|
|
||||||
|
import #(serviceImplConfig.buildSuperClassImport());
|
||||||
|
import #(packageConfig.entityPackage).#(table.buildEntityClassName());
|
||||||
|
import #(packageConfig.servicePackage).#(table.buildServiceClassName());
|
||||||
|
import #(packageConfig.mapperPackage).#(table.buildMapperClassName());
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
#if(isCacheExample)
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
#end
|
||||||
|
|
||||||
|
/**
|
||||||
|
* #(table.getComment()) 服务层实现。
|
||||||
|
*
|
||||||
|
* @author #(javadocConfig.getAuthor())
|
||||||
|
* @since #(javadocConfig.getSince())
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
#if(isCacheExample)
|
||||||
|
@CacheConfig(cacheNames = "#(firstCharToLowerCase(entityClassName))")
|
||||||
|
#end
|
||||||
|
public class #(table.buildServiceImplClassName()) extends #(serviceImplConfig.buildSuperClassName())<#(table.buildMapperClassName()), #(table.buildEntityClassName())> implements #(table.buildServiceClassName()){
|
||||||
|
|
||||||
|
#if(isCacheExample)
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@CacheEvict(allEntries = true)
|
||||||
|
public boolean remove(QueryWrapper query) {
|
||||||
|
return super.remove(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@CacheEvict(key = "#id")
|
||||||
|
public boolean removeById(Serializable id) {
|
||||||
|
return super.removeById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@CacheEvict(allEntries = true)
|
||||||
|
public boolean removeByIds(Collection<? extends Serializable> ids) {
|
||||||
|
return super.removeByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@CacheEvict(allEntries = true)
|
||||||
|
public boolean update(#(entityClassName) entity, QueryWrapper query) {
|
||||||
|
return super.update(entity, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@CacheEvict(key = "#entity.#(primaryKey)")
|
||||||
|
public boolean updateById(#(entityClassName) entity, boolean ignoreNulls) {
|
||||||
|
return super.updateById(entity, ignoreNulls);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@CacheEvict(allEntries = true)
|
||||||
|
public boolean updateBatch(Collection<#(entityClassName)> entities, int batchSize) {
|
||||||
|
return super.updateBatch(entities, batchSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@Cacheable(key = "#id")
|
||||||
|
public #(entityClassName) getById(Serializable id) {
|
||||||
|
return super.getById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@Cacheable(key = "#root.methodName + ':' + #query.toSQL()")
|
||||||
|
public #(entityClassName) getOne(QueryWrapper query) {
|
||||||
|
return super.getOne(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@Cacheable(key = "#root.methodName + ':' + #query.toSQL()")
|
||||||
|
public <R> R getOneAs(QueryWrapper query, Class<R> asType) {
|
||||||
|
return super.getOneAs(query, asType);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@Cacheable(key = "#root.methodName + ':' + #query.toSQL()")
|
||||||
|
public Object getObj(QueryWrapper query) {
|
||||||
|
return super.getObj(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@Cacheable(key = "#root.methodName + ':' + #query.toSQL()")
|
||||||
|
public <R> R getObjAs(QueryWrapper query, Class<R> asType) {
|
||||||
|
return super.getObjAs(query, asType);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@Cacheable(key = "#root.methodName + ':' + #query.toSQL()")
|
||||||
|
public List<Object> objList(QueryWrapper query) {
|
||||||
|
return super.objList(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@Cacheable(key = "#root.methodName + ':' + #query.toSQL()")
|
||||||
|
public <R> List<R> objListAs(QueryWrapper query, Class<R> asType) {
|
||||||
|
return super.objListAs(query, asType);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@Cacheable(key = "#root.methodName + ':' + #query.toSQL()")
|
||||||
|
public List<#(entityClassName)> list(QueryWrapper query) {
|
||||||
|
return super.list(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@Cacheable(key = "#root.methodName + ':' + #query.toSQL()")
|
||||||
|
public <R> List<R> listAs(QueryWrapper query, Class<R> asType) {
|
||||||
|
return super.listAs(query, asType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated 无法通过注解进行缓存操作。
|
||||||
|
*/
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@Deprecated
|
||||||
|
public List<#(entityClassName)> listByIds(Collection<? extends Serializable> ids) {
|
||||||
|
return super.listByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@Cacheable(key = "#root.methodName + ':' + #query.toSQL()")
|
||||||
|
public long count(QueryWrapper query) {
|
||||||
|
return super.count(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if(table.getGlobalConfig().isServiceGenerateEnable())
|
||||||
|
@Override
|
||||||
|
#end
|
||||||
|
@Cacheable(key = "#root.methodName + ':' + #page.getPageSize() + ':' + #page.getPageNumber() + ':' + #query.toSQL()")
|
||||||
|
public <R> Page<R> pageAs(Page<R> page, QueryWrapper query, Class<R> asType) {
|
||||||
|
return super.pageAs(page, query, asType);
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue