Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
4237c56749
|
|
@ -1,19 +0,0 @@
|
||||||
# Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
# or more contributor license agreements. See the NOTICE file
|
|
||||||
# distributed with this work for additional information
|
|
||||||
# regarding copyright ownership. The ASF licenses this file
|
|
||||||
# to you under the Apache License, Version 2.0 (the
|
|
||||||
# "License"); you may not use this file except in compliance
|
|
||||||
# with the License. You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing,
|
|
||||||
# software distributed under the License is distributed on an
|
|
||||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
# KIND, either express or implied. See the License for the
|
|
||||||
# specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
wrapperVersion=3.3.2
|
|
||||||
distributionType=only-script
|
|
||||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
|
|
||||||
|
|
@ -3,22 +3,29 @@ package com.czg;
|
||||||
import com.mybatisflex.codegen.Generator;
|
import com.mybatisflex.codegen.Generator;
|
||||||
import com.mybatisflex.codegen.config.ColumnConfig;
|
import com.mybatisflex.codegen.config.ColumnConfig;
|
||||||
import com.mybatisflex.codegen.config.GlobalConfig;
|
import com.mybatisflex.codegen.config.GlobalConfig;
|
||||||
|
import com.mybatisflex.core.service.IService;
|
||||||
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ww
|
* @author ww
|
||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
|
private final static String BASE_URL = "rm-bp1kn7h89nz62cno1ro.mysql.rds.aliyuncs.com";
|
||||||
|
private final static String PORT = "3306";
|
||||||
|
private final static String USERNAME = "cashier";
|
||||||
|
private final static String PASSWORD = "Cashier@1@";
|
||||||
|
private final static String DATABASE = "czg_cashier";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//配置数据源
|
//配置数据源
|
||||||
HikariDataSource dataSource = new HikariDataSource();
|
HikariDataSource dataSource = new HikariDataSource();
|
||||||
dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/your-database?characterEncoding=utf-8");
|
dataSource.setJdbcUrl("jdbc:mysql://" + BASE_URL + ":" + PORT + "/" + DATABASE);
|
||||||
dataSource.setUsername("root");
|
dataSource.setUsername(USERNAME);
|
||||||
dataSource.setPassword("******");
|
dataSource.setPassword(PASSWORD);
|
||||||
|
|
||||||
//创建配置内容,两种风格都可以。
|
//创建配置内容,两种风格都可以。
|
||||||
GlobalConfig globalConfig = createGlobalConfigUseStyle1();
|
GlobalConfig globalConfig = createGlobalConfigUseStyle();
|
||||||
//GlobalConfig globalConfig = createGlobalConfigUseStyle2();
|
|
||||||
|
|
||||||
//通过 datasource 和 globalConfig 创建代码生成器
|
//通过 datasource 和 globalConfig 创建代码生成器
|
||||||
Generator generator = new Generator(dataSource, globalConfig);
|
Generator generator = new Generator(dataSource, globalConfig);
|
||||||
|
|
@ -27,64 +34,76 @@ public class Main {
|
||||||
generator.generate();
|
generator.generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GlobalConfig createGlobalConfigUseStyle1() {
|
public static GlobalConfig createGlobalConfigUseStyle() {
|
||||||
//创建配置内容
|
//创建配置内容
|
||||||
GlobalConfig globalConfig = new GlobalConfig();
|
GlobalConfig globalConfig = new GlobalConfig();
|
||||||
|
|
||||||
//设置根包
|
String currentWorkingDirectory = System.getProperty("user.dir");
|
||||||
globalConfig.setBasePackage("com.test");
|
String projectPath = currentWorkingDirectory + "/cash-service/system-service";
|
||||||
|
// String projectPath = currentWorkingDirectory + "/cash-service/account-service";
|
||||||
//设置表前缀和只生成哪些表
|
// String projectPath = currentWorkingDirectory + "/cash-service/product-service";
|
||||||
globalConfig.setTablePrefix("tb_");
|
// String projectPath = currentWorkingDirectory + "/cash-service/order-service";
|
||||||
globalConfig.setGenerateTable("tb_account", "tb_account_session");
|
|
||||||
|
|
||||||
//设置生成 entity 并启用 Lombok
|
|
||||||
globalConfig.setEntityGenerateEnable(true);
|
|
||||||
globalConfig.setEntityWithLombok(true);
|
|
||||||
//设置项目的JDK版本,项目的JDK为14及以上时建议设置该项,小于14则可以不设置
|
|
||||||
globalConfig.setEntityJdkVersion(17);
|
|
||||||
|
|
||||||
//设置生成 mapper
|
|
||||||
globalConfig.setMapperGenerateEnable(true);
|
|
||||||
|
|
||||||
//可以单独配置某个列
|
|
||||||
ColumnConfig columnConfig = new ColumnConfig();
|
|
||||||
columnConfig.setColumnName("tenant_id");
|
|
||||||
columnConfig.setLarge(true);
|
|
||||||
columnConfig.setVersion(true);
|
|
||||||
globalConfig.setColumnConfig("tb_account", columnConfig);
|
|
||||||
|
|
||||||
return globalConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GlobalConfig createGlobalConfigUseStyle2() {
|
|
||||||
//创建配置内容
|
|
||||||
GlobalConfig globalConfig = new GlobalConfig();
|
|
||||||
|
|
||||||
//设置根包
|
//设置根包
|
||||||
globalConfig.getPackageConfig()
|
globalConfig.getPackageConfig()
|
||||||
.setBasePackage("com.test");
|
.setSourceDir(projectPath + "/src/main/java")
|
||||||
|
.setBasePackage("com.czg.service.system");
|
||||||
|
|
||||||
|
globalConfig.getServiceConfig()
|
||||||
|
.setClassSuffix("Service")
|
||||||
|
.setSuperClass(IService.class);
|
||||||
|
globalConfig.enableService();
|
||||||
|
|
||||||
|
globalConfig.getServiceImplConfig()
|
||||||
|
.setClassSuffix("ServiceImpl")
|
||||||
|
.setSuperClass(ServiceImpl.class);
|
||||||
|
globalConfig.enableServiceImpl();
|
||||||
|
|
||||||
|
globalConfig.getMapperConfig()
|
||||||
|
.setClassSuffix("Mapper");
|
||||||
|
globalConfig.enableMapper();
|
||||||
|
|
||||||
|
globalConfig.setMapperXmlPath(projectPath + "/src/main/resources/mapper");
|
||||||
|
globalConfig.enableMapperXml();
|
||||||
|
|
||||||
//设置表前缀和只生成哪些表,setGenerateTable 未配置时,生成所有表
|
//设置表前缀和只生成哪些表,setGenerateTable 未配置时,生成所有表
|
||||||
globalConfig.getStrategyConfig()
|
globalConfig.getStrategyConfig()
|
||||||
.setTablePrefix("tb_")
|
.setTablePrefix("")
|
||||||
.setGenerateTable("tb_account", "tb_account_session");
|
.setGenerateTable("sys_params");
|
||||||
|
|
||||||
//设置生成 entity 并启用 Lombok
|
//设置生成 entity 并启用 Lombok
|
||||||
globalConfig.enableEntity()
|
globalConfig.enableEntity()
|
||||||
.setWithLombok(true)
|
.setWithLombok(true)
|
||||||
.setJdkVersion(17);
|
.setJdkVersion(23);
|
||||||
|
|
||||||
//设置生成 mapper
|
//设置生成 mapper
|
||||||
globalConfig.enableMapper();
|
globalConfig.enableMapper();
|
||||||
|
|
||||||
//可以单独配置某个列
|
//可以单独配置某个列
|
||||||
ColumnConfig columnConfig = new ColumnConfig();
|
ColumnConfig createTime = new ColumnConfig();
|
||||||
columnConfig.setColumnName("tenant_id");
|
createTime.setColumnName("create_time");
|
||||||
columnConfig.setLarge(true);
|
createTime.setOnInsertValue("now()");
|
||||||
columnConfig.setVersion(true);
|
|
||||||
globalConfig.getStrategyConfig()
|
globalConfig.getStrategyConfig()
|
||||||
.setColumnConfig("tb_account", columnConfig);
|
.setColumnConfig(createTime);
|
||||||
|
|
||||||
|
ColumnConfig updateTime = new ColumnConfig();
|
||||||
|
updateTime.setColumnName("update_time");
|
||||||
|
updateTime.setOnUpdateValue("now()");
|
||||||
|
updateTime.setOnInsertValue("now()");
|
||||||
|
globalConfig.getStrategyConfig()
|
||||||
|
.setColumnConfig(updateTime);
|
||||||
|
|
||||||
|
ColumnConfig deleted = new ColumnConfig();
|
||||||
|
deleted.setColumnName("is_del");
|
||||||
|
deleted.setLogicDelete(true);
|
||||||
|
globalConfig.getStrategyConfig()
|
||||||
|
.setColumnConfig(deleted);
|
||||||
|
|
||||||
|
// ColumnConfig version = new ColumnConfig();
|
||||||
|
// version.setColumnName("version");
|
||||||
|
// version.setVersion(true);
|
||||||
|
// globalConfig.getStrategyConfig()
|
||||||
|
// .setColumnConfig(version);
|
||||||
|
|
||||||
return globalConfig;
|
return globalConfig;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.czg.service.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-07
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Table("sys_params")
|
||||||
|
public class SysParams implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
@Id(keyType = KeyType.Auto)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数编码
|
||||||
|
*/
|
||||||
|
private String paramCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数值
|
||||||
|
*/
|
||||||
|
private String paramValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型 0:系统参数 1:非系统参数
|
||||||
|
*/
|
||||||
|
private Integer paramType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建者id
|
||||||
|
*/
|
||||||
|
private Long createUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@Column(onInsertValue = "now()")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新者id
|
||||||
|
*/
|
||||||
|
private Long updateUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.czg.service.system.mapper;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
import com.czg.service.system.entity.SysParams;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 映射层。
|
||||||
|
*
|
||||||
|
* @author mac
|
||||||
|
* @since 2025-02-07
|
||||||
|
*/
|
||||||
|
public interface SysParamsMapper extends BaseMapper<SysParams> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.czg.service.system.service;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.service.IService;
|
||||||
|
import com.czg.service.system.entity.SysParams;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务层。
|
||||||
|
*
|
||||||
|
* @author mac
|
||||||
|
* @since 2025-02-07
|
||||||
|
*/
|
||||||
|
public interface SysParamsService extends IService<SysParams> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.czg.service.system.service.impl;
|
||||||
|
|
||||||
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
|
import com.czg.service.system.entity.SysParams;
|
||||||
|
import com.czg.service.system.mapper.SysParamsMapper;
|
||||||
|
import com.czg.service.system.service.SysParamsService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务层实现。
|
||||||
|
*
|
||||||
|
* @author mac
|
||||||
|
* @since 2025-02-07
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class SysParamsServiceImpl extends ServiceImpl<SysParamsMapper, SysParams> implements SysParamsService{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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.SysParamsMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in New Issue