Commit 68312e4c authored by zhoushiguang's avatar zhoushiguang

代码生成模板

parent 658cc7cd
package test;
package generator.code;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
......@@ -15,20 +15,21 @@ import java.util.List;
/**
* @ClassName:Generator
* @Description:代码自动生成器
* @Description:代码自动生成器
*/
public class CodeGenerator {
static String baseOutputDir = "D:\\workspace\\flink-traffic-indicators-compute";
public class CodeGeneratorMYSQLPlus {
static String baseOutputDir = "./wj-realtime-computing";
public static void main(String[] args) {
// 生成地址 : // System.getProperty("user.dir") == 得到当前项目的实际地址
// String outputDir = System.getProperty("user.dir") + "/src/main/java";
String outputDir = System.getProperty("user.dir") + "/src/main/java";
String outputDir = baseOutputDir + "/src/main/java";
outputDir = baseOutputDir + "/src/main/java";
System.out.println(outputDir);
// 表名, 注意大小写
String[] tableNames = new String[] {"t_base_lane_info"};
String[] tableNames = new String[]{"t_congestion_area"};
// 数据库地址
String url = "jdbc:mysql://10.102.1.182:3306/t_roadnetwork_changsha?userUnicode=true&characterEncoding=utf-8";
String url = "jdbc:mysql://37.12.182.29:3306/holo_roadnet?&serverTimezone=GMT%2B8";
// 用户名
String userName = "root";
// 密码
......@@ -39,7 +40,7 @@ public class CodeGenerator {
String prefixTable = "t_";
generate(outputDir, tableNames, url, userName, password, parentPackage, prefixTable);
}
/**
* @param outputDir 生成地址
* @param tableNames 表名
......@@ -54,73 +55,72 @@ public class CodeGenerator {
// =============== 全局配置 ==================
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir(outputDir)
.setActiveRecord(true) // 是否支持 AR, 实体类只需继承 Model 类即可进行强大的 CRUD 操作
.setAuthor("fengyi") // 设置作者名字
.setFileOverride(true) // 文件覆盖(全新文件)
.setIdType(IdType.AUTO) // 主键策略
.setBaseResultMap(true) // SQL 映射文件
.setBaseColumnList(true) // SQL 片段
.setServiceName("%sService") // service的名字
.setMapperName("%sMapper")
.setOpen(false)
;
.setActiveRecord(false) // 是否支持 AR, 实体类只需继承 Model 类即可进行强大的 CRUD 操作
.setAuthor("fengyi") // 设置作者名字
.setFileOverride(true) // 文件覆盖(全新文件)
.setIdType(IdType.AUTO) // 主键策略
.setBaseResultMap(true) // SQL 映射文件
.setBaseColumnList(true) // SQL 片段
.setServiceName("%sService") // service的名字
.setMapperName("%sMapper")
.setOpen(false);
// ================= 数据源配置 ===============
DataSourceConfig dsc = new DataSourceConfig();
dsc.setDbType(DbType.MYSQL)
.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setDbType(DbType.MYSQL)
.setDriverName("com.mysql.jdbc.Driver");
dsc.setUrl(url)
.setUsername(userName)
.setPassword(password);
.setUsername(userName)
.setPassword(password);
// ================= 包配置 ===================
PackageConfig pc = new PackageConfig();
pc.setParent(parentPackage) // 配置父包路径
PackageConfig pc = new PackageConfig();
pc.setParent(parentPackage) // 配置父包路径
// .setModuleName("base") // 配置业务包路径
.setMapper("mapper")
.setEntity("entity")
.setMapper("mapper")
.setEntity("entity")
// .setEntity("entity")
.setService("service")
//.setServiceImpl("service.impl"); // 会自动生成 impl,可以不设定
//.setController("web.controller")
;
.setService("service")
.setServiceImpl("service.impl") // 会自动生成 impl,可以不设定
//.setController("restful")
;
// ================== 自定义配置 =================
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
}
};
List<FileOutConfig> focList = new ArrayList<>();
// 调整 xml 生成目录演示
focList.add(new FileOutConfig("/templates/mapper.xml.ftl") {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定义输入文件名称
return baseOutputDir + "/src/main/resources/mapper/"
+ tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
cfg.setFileOutConfigList(focList);
// ================== 自定义配置 =================
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
}
};
List<FileOutConfig> focList = new ArrayList<>();
// 调整 xml 生成目录演示
focList.add(new FileOutConfig("/templates/mybatisplus/mapper.xml.ftl") {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定义输入文件名称
return baseOutputDir + "/src/main/resources/mapper/"
+ tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
cfg.setFileOutConfigList(focList);
// =================== 策略配置 ==================
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel) // 表名命名: underline_to_camel 底线变驼峰
.setColumnNaming(NamingStrategy.underline_to_camel) // 字段命名: underline_to_camel 底线变驼峰
.setInclude(tableNames) // 需要生成的 表名
.setCapitalMode(true) // 全局大写命名 ORACLE 注意
.setTablePrefix(prefixTable) // 去掉 表的前缀
// =================== 策略配置 ==================
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel) // 表名命名: underline_to_camel 底线变驼峰
.setColumnNaming(NamingStrategy.underline_to_camel) // 字段命名: underline_to_camel 底线变驼峰
.setInclude(tableNames) // 需要生成的 表名
.setCapitalMode(true) // 全局大写命名 ORACLE 注意
.setTablePrefix(prefixTable) // 去掉 表的前缀
// .setFieldPrefix(pc.getModuleName() + "_") // 去掉字段前缀
// .setSuperEntityClass("com.maoxs.pojo") // 继承类
// .setSuperControllerClass("com.maoxs.controller") // 继承类
// .setSuperEntityColumns("id") // 设置超级超级列
.setEntityLombokModel(true) // 是否加入lombok
.setControllerMappingHyphenStyle(true) // 设置controller映射联字符
.setRestControllerStyle(true)
;
//自动填充字段,在项目开发过程中,例如创建时间,修改时间,每次,都需要我们来指定,太麻烦了,设置为自动填充规则,就不需要我们赋值咯
.setEntityLombokModel(true) // 是否加入lombok
.setControllerMappingHyphenStyle(false) // 设置controller映射联字符
.setRestControllerStyle(false)
;
//自动填充字段,在项目开发过程中,例如创建时间,修改时间,每次,都需要我们来指定,太麻烦了,设置为自动填充规则,就不需要我们赋值咯
// List<TableFill> list = new ArrayList<TableFill>();
// TableFill tableFill1 = new TableFill("register_date",FieldFill.INSERT);
// TableFill tableFill2 = new TableFill("update_time",FieldFill.INSERT_UPDATE);
......@@ -128,27 +128,27 @@ public class CodeGenerator {
// list.add(tableFill2);
// strategy.setTableFillList(list);
// ================== 自定义模板配置: 默认配置位置 mybatis-plus/src/main/resources/templates ======================
// 放置自己项目的 src/main/resources/templates 目录下, 默认名称一下可以不配置,也可以自定义模板名称
TemplateConfig tc = new TemplateConfig();
tc.setXml(null) // 设置生成xml的模板
.setEntity("/templates/entity.java") // 设置生成entity的模板
.setMapper("/templates/mapper.java") // 设置生成mapper的模板
.setController(null) // 设置生成controller的模板
.setService("/templates/service.java") // 设置生成service的模板
.setServiceImpl("/templates/serviceImpl.java"); // 设置生成serviceImpl的模板
// ================== 自定义模板配置: 默认配置位置 mybatis-plus/src/main/resources/templates ======================
// 放置自己项目的 src/main/resources/templates 目录下, 默认名称一下可以不配置,也可以自定义模板名称
TemplateConfig tc = new TemplateConfig();
tc.setXml(null) // 设置生成xml的模板
.setEntity("/templates/mybatisplus/entity.java") // 设置生成entity的模板
.setMapper("/templates/mybatisplus/mapper.java") // 设置生成mapper的模板
//.setController("/templates/mybatisplus/controller.java") // 设置生成controller的模板
.setService("/templates/mybatisplus/service.java") // 设置生成service的模板
.setServiceImpl("/templates/mybatisplus/serviceImpl.java"); // 设置生成serviceImpl的模板
// ==================== 生成配置 ===================
AutoGenerator mpg = new AutoGenerator();
mpg.setCfg(cfg)
.setTemplate(tc)
.setGlobalConfig(gc)
.setDataSource(dsc)
.setPackageInfo(pc)
.setStrategy(strategy)
.setTemplateEngine(new FreemarkerTemplateEngine()); // 选择 freemarker引擎,注意 pom 依赖必须有!
mpg.execute();
System.out.println("MyBatis Plus Code Generator Finished!!");
// ==================== 生成配置 ===================
AutoGenerator mpg = new AutoGenerator();
mpg.setCfg(cfg)
.setTemplate(tc)
.setGlobalConfig(gc)
.setDataSource(dsc)
.setPackageInfo(pc)
.setStrategy(strategy)
.setTemplateEngine(new FreemarkerTemplateEngine()); // 选择 freemarker引擎,注意 pom 依赖必须有!
mpg.execute();
System.out.println("MyBatis Plus Code Generator Finished!!");
}
}
package generator.code;//
//
//import com.baomidou.mybatisplus.core.mapper.BaseMapper;
//import com.baomidou.mybatisplus.generator.FastAutoGenerator;
//import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
//
//import java.util.ArrayList;
//import java.util.List;
//
//public class Generator {
//
// public static void main(String[] args) {
// /*
// 特别注意:生成的时间类型均为:“LocalDateTime”格式,需要假如以下注解方可正常使用
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
// @JsonDeserialize(using = LocalDateTimeDeserializer.class)
// @JsonSerialize(using = LocalDateTimeSerializer.class)
// */
//
// //数据库连接
// String url = "jdbc:mysql://10.102.1.182:3306/holo_roadnet?&serverTimezone=GMT%2B8";//数据库url
// String username = "root";//账号
// String password = "Wanji300552";//密码
// String module = "hologram-road-section";//模块名
// //全局配置参数
// String author = "fengyi";//作者
// String outputDir = System.getProperty("user.dir")+"\\"+module+"\\src\\main\\java";//指定输出目录
// //包配置参数
// String parent = "com.wanji";//父包名
// String moduleName = "holo";//父包模块名
// String entity = "entity";//Entity 实体类包名
// String mapper = "mapper";//Mapper 包名
// String mapperXml = "mapper";//Mapper XML 包名
// String service = "provider.service";//Service 包名
// String serviceImpl = "provider.service.impl";//Service Impl 包名
// /*String controller = "controller";//Controller 包名*/
// //要生成的数据库表
// List<String> tables = new ArrayList<>();
// tables.add("t_base_menus");
// //开始生成
// FastAutoGenerator.create(url,username,password)
// //全局配置
// .globalConfig(builder -> {
// builder.author(author)
// .outputDir(outputDir)
// /*.enableSwagger()//开启swagger*/
// .commentDate("yyyy-MM-dd");//注释日期
// })
// //包配置
// .packageConfig(builder -> {
// builder.parent(parent)
// .moduleName(moduleName)
// .entity(entity)
// .mapper(mapper)
// .xml(mapperXml)
// .service(service)
// .serviceImpl(serviceImpl)
// /*.controller(controller)*/;
// })
// //策略配置
// .strategyConfig(builder -> {
// builder.addInclude(tables)
// //开启生成实体类
// .entityBuilder()
// .enableLombok()//开启 lombok 模型
// .enableTableFieldAnnotation()//开启生成实体时生成字段注解
// //开启生成mapper
// .mapperBuilder()
// .enableBaseResultMap()//启用 BaseResultMap 生成
// .superClass(BaseMapper.class)//设置父类
// .enableMapperAnnotation()//开启 @Mapper 注解
// .formatMapperFileName("%sMapper")//格式化 mapper 文件名称
// .formatXmlFileName("%sMapper")//格式化 xml 实现类文件名称
// //开启生成service及impl
// .serviceBuilder()
// .formatServiceFileName("%sService")//格式化 service 接口文件名称
// .formatServiceImplFileName("%sServiceImpl");//格式化 service 实现类文件名称
// /*//开启生成controller
// .controllerBuilder()
// // 映射路径使用连字符格式,而不是驼峰
// .enableHyphenStyle()
// .formatFileName("%sController")//格式化文件名称
// .enableRestStyle();*/
// })
// .templateEngine(new VelocityTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
// .templateConfig(builder -> builder.controller(""))//关闭生成controller
// .execute();
// }
//}
//
//
//
package generator.code;
/**
* 项目常量
*/
public final class ProjectConstant {
public static final String BASE_PACKAGE = "com.wanji.holo";//项目基础包名称,根据自己公司的项目修改
public static final String MYSQL_MODEL_PACKAGE = BASE_PACKAGE + ".entity";//Model所在包
public static final String MYSQL_MAPPER_PACKAGE = BASE_PACKAGE + ".mapper";//Mapper所在包
public static final String MYSQL_SERVICE_PACKAGE = BASE_PACKAGE + ".provider.service";//Service所在包
public static final String MYSQL_SERVICE_IMPL_PACKAGE = MYSQL_SERVICE_PACKAGE + ".impl";//ServiceImpl所在包
public static final String CONTROLLER_PACKAGE = BASE_PACKAGE + ".restful";//Controller所在包
public static final String MAPPER_INTERFACE_REFERENCE = BASE_PACKAGE + ".core.Mapper";//Mapper插件基础接口的完全限定名
}
package test;
public class ApplicationContextTest {
public static void main(String[] args) {
// ApplicationContext beanConf = new ClassPathXmlApplicationContext("spring-container.xml");
// FlowService flowService = beanConf.getBean(FlowServiceImpl.class);
// List<FlowData> users = flowService.findAll();
// System.out.println(users);
}
}
\ No newline at end of file
package ${package.Controller};
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import com.wanji.holo.core.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
<#if restControllerStyle>
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import javax.validation.Valid;
import java.util.List;
/**
* <p>
* ${table.comment!} 前端控制器
* </p>
*
* @author ${author}
* @since ${date}
*/
@Api(tags = "${table.comment!}")
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
@Autowired
private ${table.serviceName} ${table.serviceName?uncap_first};
@ApiOperation(value = "${table.comment!}详情", response = ${entity}.class)
@GetMapping(value = "/info/{id}")
public Object info(@PathVariable Long id) {
Object data = ${table.serviceName?uncap_first}.info(id);
return ResultGenerator.genSuccessResult(data);
}
@ApiOperation(value = "${table.comment!}新增")
@PostMapping(value = "/add")
public Object add(@Valid @RequestBody ${entity} param) {
${table.serviceName?uncap_first}.add(param);
return ResultGenerator.genSuccessResult();
}
@ApiOperation(value = "${table.comment!}修改")
@PostMapping(value = "/modify")
public Object modify(@Valid @RequestBody ${entity} param) {
${table.serviceName?uncap_first}.modify(param);
return ResultGenerator.genSuccessResult();
}
@ApiOperation(value = "${table.comment!}删除(单个条目)")
@GetMapping(value = "/remove/{id}")
public Object remove(@PathVariable Long id) {
${table.serviceName?uncap_first}.remove(id);
return ResultGenerator.genSuccessResult();
}
@ApiOperation(value = "${table.comment!}删除(多个条目)")
@PostMapping(value = "/removes")
public Object removes(@Valid @RequestBody List<Long> ids) {
${table.serviceName?uncap_first}.removes(ids);
return ResultGenerator.genSuccessResult();
}
}
</#if>
\ No newline at end of file
package ${package.Entity};
<#list table.importPackages as pkg>
import ${pkg};
</#list>
<#if swagger2>
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
</#if>
<#if entityLombokModel>
import lombok.Data;
import lombok.EqualsAndHashCode;
</#if>
import com.baomidou.mybatisplus.annotation.TableName;
<#if entityLombokModel>
@Data
@EqualsAndHashCode(callSuper=false)
</#if>
<#if !swagger2>
@TableName("${table.name}")
</#if>
<#if swagger2>
@ApiModel(value="${entity}", description="${table.comment!}")
</#if>
<#if superEntityClass??>
public class ${entity} extends ${superEntityClass}<#if activeRecord><${entity}></#if> {
<#elseif activeRecord>
public class ${entity} extends Model<${entity}> {
<#else>
public class ${entity} implements Serializable {
</#if>
private static final long serialVersionUID = 1L;
<#-- ---------- BEGIN 字段循环遍历 ---------->
<#list table.fields as field>
<#if field.keyFlag>
<#assign keyPropertyName="${field.propertyName}"/>
</#if>
<#if field.comment!?length gt 0>
<#if swagger2>
@ApiModelProperty(value = "${field.comment}")
<#else>
/**
* ${field.comment}
*/
</#if>
</#if>
<#if !swagger2>
<#if field.keyFlag>
<#-- 主键 -->
<#if field.keyIdentityFlag>
@TableId(value = "${field.name}", type = IdType.AUTO)
<#elseif idType??>
@TableId(value = "${field.name}", type = IdType.${idType})
<#elseif field.convert>
@TableId("${field.name}")
</#if>
<#-- 普通字段 -->
<#elseif field.fill??>
<#-- ----- 存在字段填充设置 ----->
<#if field.convert>
@TableField(value = "${field.name}", fill = FieldFill.${field.fill})
<#else>
@TableField(fill = FieldFill.${field.fill})
</#if>
<#elseif field.convert>
@TableField("${field.name}")
</#if>
</#if>
<#-- 乐观锁注解 -->
<#if (versionFieldName!"") == field.name>
@Version
</#if>
<#-- 逻辑删除注解 -->
<#if (logicDeleteFieldName!"") == field.name>
@TableLogic
</#if>
private ${field.propertyType} ${field.propertyName};
</#list>
<#------------ END 字段循环遍历 ---------->
<#if !entityLombokModel>
<#list table.fields as field>
<#if field.propertyType == "boolean">
<#assign getprefix="is"/>
<#else>
<#assign getprefix="get"/>
</#if>
public ${field.propertyType} ${getprefix}${field.capitalName}() {
return ${field.propertyName};
}
<#if entityBuilderModel>
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
<#else>
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
</#if>
this.${field.propertyName} = ${field.propertyName};
<#if entityBuilderModel>
return this;
</#if>
}
</#list>
</#if>
<#if entityColumnConstant>
<#list table.fields as field>
public static final String ${field.name?upper_case} = "${field.name}";
</#list>
</#if>
<#if activeRecord>
@Override
protected Serializable pkVal() {
<#if keyPropertyName??>
return this.${keyPropertyName};
<#else>
return null;
</#if>
}
</#if>
<#if !entityLombokModel>
@Override
public String toString() {
return "${entity}{" +
<#list table.fields as field>
<#if field_index==0>
"${field.propertyName}=" + ${field.propertyName} +
<#else>
", ${field.propertyName}=" + ${field.propertyName} +
</#if>
</#list>
"}";
}
</#if>
}
package ${package.Entity};
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.Table;
<#list table.importPackages as pkg>
<#if pkg == "java.util.Date">
import ${pkg};
</#if>
</#list>
/**
* ${table.name} : ${table.comment!}
*/
@Data
@Entity
@Table(name = "${table.name}")
@ApiModel("${table.comment!}")
@JsonIgnoreProperties(value = {"hibernateLazyInitializer"})
public class ${entity} implements Serializable {
private static final long serialVersionUID = 1L;
<#-- ---------- 属性私有化 ---------->
<#list table.fields as field>
<#if field.keyFlag>
<#assign keyPropertyName="${field.propertyName}"/>
</#if>
<#if field.keyFlag>
<#-- 主键 -->
/**
* 主键 : ${field.name}, ${field.comment!}
*/
<#-- 乐观锁注解 -->
<#if (versionFieldName!"") == field.name>
@Version
</#if>
<#-- 逻辑删除注解 -->
<#if (logicDeleteFieldName!"") == field.name>
@TableLogic
</#if>
<#if field.propertyType == "LocalDateTime" || field.propertyType == "LocalDate">
@Column(name = "${field.name}")
@ApiModelProperty("${field.comment!}")
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
private Date ${field.propertyName};
</#if>
<#if field.propertyType != "LocalDateTime" && field.propertyType != "LocalDate">
@Id
@Column(name = "${field.name}")
@ApiModelProperty("${field.comment!}")
private ${field.propertyType} ${field.propertyName};
</#if>
<#-- 普通字段 -->
<#elseif !field.keyFlag>
/**
* ${field.name}, ${field.comment!}
*/
<#-- 乐观锁注解 -->
<#if (versionFieldName!"") == field.name>
@Version
</#if>
<#-- 逻辑删除注解 -->
<#if (logicDeleteFieldName!"") == field.name>
@TableLogic
</#if>
<#if field.propertyType == "LocalDateTime" || field.propertyType == "LocalDate">
@Column(name = "${field.name}")
@ApiModelProperty("${field.comment!}")
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
private Date ${field.propertyName};
</#if>
<#if field.propertyType != "LocalDateTime" && field.propertyType != "LocalDate">
@Column(name = "${field.name}")
@ApiModelProperty("${field.comment!}")
private ${field.propertyType} ${field.propertyName};
</#if>
</#if>
<#--&lt;#&ndash; 乐观锁注解 &ndash;&gt;-->
<#-- <#if (versionFieldName!"") == field.name>-->
<#-- @Version-->
<#-- </#if>-->
<#--&lt;#&ndash; 逻辑删除注解 &ndash;&gt;-->
<#-- <#if (logicDeleteFieldName!"") == field.name>-->
<#-- @TableLogic-->
<#-- </#if>-->
<#-- <#if field.propertyType == "LocalDateTime" || field.propertyType == "LocalDate">-->
<#-- @Column(name = "${field.name}")-->
<#-- @ApiModelProperty("${field.comment!}")-->
<#-- @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")-->
<#-- private Date ${field.propertyName};-->
<#-- </#if>-->
<#-- <#if field.propertyType != "LocalDateTime" && field.propertyType != "LocalDate">-->
<#-- @Column(name = "${field.name}")-->
<#-- @ApiModelProperty("${field.comment!}")-->
<#-- private ${field.propertyType} ${field.propertyName};-->
<#-- </#if>-->
</#list>
<#------------ 构造函数 ----------- -->
<#-- public ${entity}(<#list table.fields as field><#if field.propertyType == "LocalDateTime" || field.propertyType == "LocalDate">Date ${field.propertyName}</#if><#if field.propertyType != "LocalDateTime" && field.propertyType != "LocalDate">${field.propertyType} ${field.propertyName}</#if><#sep>,</#list>){-->
<#-- <#list table.fields as field>-->
<#-- this.${field.propertyName} = ${field.propertyName};-->
<#-- </#list>-->
<#-- }-->
<#-- -->
<#-- public ${entity}(){-->
<#-- }-->
<#------------ getter.setter封装 ---------->
<#--<#if !entityLombokModel>-->
<#-- <#list table.fields as field>-->
<#-- <#if field.propertyType == "boolean">-->
<#-- <#assign getprefix="is"/>-->
<#-- <#else>-->
<#-- <#assign getprefix="get"/>-->
<#-- </#if>-->
<#-- public <#if field.propertyType == "LocalDateTime" || field.propertyType == "LocalDate">Date</#if><#if field.propertyType != "LocalDateTime" && field.propertyType != "LocalDate">${field.propertyType}</#if> ${getprefix}${field.capitalName}() {-->
<#-- return ${field.propertyName};-->
<#-- }-->
<#-- <#if entityBuilderModel>-->
<#-- public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {-->
<#-- <#else>-->
<#-- public void set${field.capitalName}(<#if field.propertyType == "LocalDateTime" || field.propertyType == "LocalDate">Date</#if><#if field.propertyType != "LocalDateTime" && field.propertyType != "LocalDate">${field.propertyType}</#if> ${field.propertyName}) {-->
<#-- </#if>-->
<#-- this.${field.propertyName} = ${field.propertyName};-->
<#-- <#if entityBuilderModel>-->
<#-- return this;-->
<#-- </#if>-->
<#-- }-->
<#-- </#list>-->
<#--</#if>-->
<#------------- 重写toString() ----------------->
<#--<#if !entityLombokModel>-->
<#-- @Override-->
<#-- public String toString() {-->
<#-- return "${entity}{" +-->
<#-- <#list table.fields as field>-->
<#-- <#if field_index==0>-->
<#-- "${field.propertyName}=" + ${field.propertyName} +-->
<#-- <#else>-->
<#-- ", ${field.propertyName}=" + ${field.propertyName} +-->
<#-- </#if>-->
<#-- </#list>-->
<#-- "}";-->
<#-- }-->
<#--</#if>-->
}
package ${package.Entity};
import java.io.Serializable;
import java.util.Date;
<#list table.importPackages as pkg>
<#if pkg == "java.util.Date">
import ${pkg};
</#if>
</#list>
/**
* ${table.name} : ${table.comment!}
*/
@TableName("${table.name}")
@ApiModel("${table.comment!}")
public class ${entity} implements Serializable {
private static final long serialVersionUID = 1L;
<#-- ---------- 属性私有化 ---------->
<#list table.fields as field>
<#if field.keyFlag>
<#assign keyPropertyName="${field.propertyName}"/>
</#if>
<#if field.keyFlag>
<#-- 主键 -->
/**
* 主键 : ${field.name}, ${field.comment!}
*/
<#-- 普通字段 -->
<#elseif !field.keyFlag>
/**
* ${field.name}, ${field.comment!}
*/
</#if>
<#-- 乐观锁注解 -->
<#if (versionFieldName!"") == field.name>
@Version
</#if>
<#-- 逻辑删除注解 -->
<#if (logicDeleteFieldName!"") == field.name>
@TableLogic
</#if>
<#if field.propertyType == "LocalDateTime">
@TableField("${field.name}")
@ApiModelProperty("${field.comment!}")
private Date ${field.propertyName};
</#if>
<#if field.propertyType != "LocalDateTime">
@TableField("${field.name}")
@ApiModelProperty("${field.comment!}")
private ${field.propertyType} ${field.propertyName};
</#if>
</#list>
<#------------ 构造函数 ----------- -->
public ${entity}(<#list table.fields as field><#if field.propertyType == "LocalDateTime">Date ${field.propertyName}</#if><#if field.propertyType != "LocalDateTime">${field.propertyType} ${field.propertyName}</#if><#sep>,</#list>){
<#list table.fields as field>
this.${field.propertyName} = ${field.propertyName};
</#list>
}
public ${entity}(){
}
<#------------ getter.setter封装 ---------->
<#if !entityLombokModel>
<#list table.fields as field>
<#if field.propertyType == "boolean">
<#assign getprefix="is"/>
<#else>
<#assign getprefix="get"/>
</#if>
public <#if field.propertyType == "LocalDateTime">Date</#if><#if field.propertyType != "LocalDateTime">${field.propertyType}</#if> ${getprefix}${field.capitalName}() {
return ${field.propertyName};
}
<#if entityBuilderModel>
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
<#else>
public void set${field.capitalName}(<#if field.propertyType == "LocalDateTime">Date</#if><#if field.propertyType != "LocalDateTime">${field.propertyType}</#if> ${field.propertyName}) {
</#if>
this.${field.propertyName} = ${field.propertyName};
<#if entityBuilderModel>
return this;
</#if>
}
</#list>
</#if>
<#------------- 重写toString() ----------------->
<#if !entityLombokModel>
@Override
public String toString() {
return "${entity}{" +
<#list table.fields as field>
<#if field_index==0>
"${field.propertyName}=" + ${field.propertyName} +
<#else>
", ${field.propertyName}=" + ${field.propertyName} +
</#if>
</#list>
"}";
}
</#if>
}
package ${package.Mapper};
import ${package.Entity}.${entity};
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface ${table.mapperName} extends BaseMapper<${entity}>{
/**
* 查询表${table.name}所有信息
*/
List<${entity}> findAll${entity}();
<#list table.fields as field>
<#if field.keyFlag>
/**
* 根据主键${field.propertyName}查询表${table.name}信息
* @param ${field.propertyName}
*/
${entity} find${entity}By${field.propertyName}(@Param("${field.propertyName}") ${field.propertyType} ${field.propertyName});
</#if>
</#list>
/**
* 根据条件查询表${table.name}信息
* @param ${table.entityPath}
*/
List<${entity}> find${entity}ByCondition(${entity} ${table.entityPath});
<#list table.fields as field>
<#if field.keyFlag>
/**
* 根据主键${field.propertyName}查询表${table.name}信息
* @param ${field.propertyName}
*/
Integer delete${entity}By${field.propertyName}(@Param("${field.propertyName}") ${field.propertyType} ${field.propertyName});
</#if>
</#list>
<#list table.fields as field>
<#if field.keyFlag>
/**
* 根据主键${field.propertyName}更新表${table.name}信息
* @param ${table.entityPath}
*/
Integer update${entity}By${field.propertyName}(${entity} ${table.entityPath});
</#if>
</#list>
<#list table.fields as field>
<#if field.keyFlag>
/**
* 新增表${table.name}信息
* @param ${table.entityPath}
*/
Integer add${entity}(${entity} ${table.entityPath});
</#if>
</#list>
}
<?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="${package.Mapper}.${table.mapperName}">
<!-- 通用设置 -->
<#if baseColumnList>
<!-- 通用查询列 -->
<sql id="Base_Column_List">
<#list table.commonFields as field>
${field.name},
</#list>
${table.fieldNames}
</sql>
<!-- 通用条件列 -->
<sql id="${entity}ByCondition">
<#list table.fields as field>
<#if field.propertyType == "LocalDateTime" || field.propertyType == "LocalDate"><#--生成普通字段 -->
<if test="${field.propertyName}!=null">
AND ${field.name} = ${r"#{"}${field.propertyName}${r"}"}
</if>
</#if>
<#if field.propertyType != "LocalDateTime" && field.propertyType != "LocalDate"><#--生成普通字段 -->
<if test="${field.propertyName}!=null and ${field.propertyName}!=''">
AND ${field.name} = ${r"#{"}${field.propertyName}${r"}"}
</if>
</#if>
</#list>
</sql>
<!-- 通用设置列 -->
<sql id="${entity}SetColumns">
<#list table.fields as field>
<#if !field.keyFlag><#--生成普通字段 -->
<#if field.propertyType == "LocalDateTime" || field.propertyType == "LocalDate">
<if test="${field.propertyName}!=null">
${field.name} = ${r"#{"}${field.propertyName}${r"}"},
</if>
</#if>
<#if field.propertyType != "LocalDateTime" && field.propertyType != "LocalDate">
<if test="${field.propertyName}!=null and ${field.propertyName}!=''">
${field.name} = ${r"#{"}${field.propertyName}${r"}"},
</if>
</#if>
</#if>
</#list>
</sql>
</#if>
<#if baseResultMap>
<!-- 通用查询映射结果 -->
<resultMap id="${entity}Map" type="${package.Entity}.${entity}">
<#list table.fields as field>
<#if field.keyFlag><#--生成主键排在第一位-->
<id column="${field.name}" property="${field.propertyName}"/>
</#if>
</#list>
<#list table.commonFields as field><#--生成公共字段 -->
<result column="${field.name}" property="${field.propertyName}"/>
</#list>
<#list table.fields as field>
<#if !field.keyFlag><#--生成普通字段 -->
<result column="${field.name}" property="${field.propertyName}"/>
</#if>
</#list>
</resultMap>
</#if>
<!-- 查询表${table.name}所有信息 -->
<select id="findAll${entity}" resultMap="${entity}Map">
SELECT
<include refid="Base_Column_List"/>
FROM ${table.name}
</select>
<#list table.fields as field>
<#if field.keyFlag>
<!-- 根据主键${field.propertyName}查询表${table.name}信息 -->
<select id="find${entity}By${field.propertyName}" resultMap="${entity}Map">
SELECT
<include refid="Base_Column_List"/>
FROM ${table.name}
WHERE ${field.name}=${r"#{"}${field.propertyName}${r"}"}
</select>
</#if>
</#list>
<!-- 根据条件查询表${table.name}信息 -->
<select id="find${entity}ByCondition" resultMap="${entity}Map">
SELECT
<include refid="Base_Column_List"/>
FROM ${table.name}
WHERE 1=1
<include refid="${entity}ByCondition" />
</select>
<#list table.fields as field>
<#if field.keyFlag>
<!-- 根据主键${field.propertyName}删除表${table.name}信息 -->
<delete id="delete${entity}By${field.propertyName}">
DELETE FROM
${table.name}
WHERE ${field.name}=${r"#{"}${field.propertyName}${r"}"}
</delete>
</#if>
</#list>
<#list table.fields as field>
<#if field.keyFlag>
<!-- 根据主键${field.propertyName}更新表${table.name}信息 -->
<update id="update${entity}By${field.propertyName}" parameterType="${package.Entity}.${entity}">
UPDATE ${table.name}
<set>
<include refid="${entity}SetColumns"/>
</set>
WHERE
<#list table.fields as field><#if field.keyFlag>${field.name}=${r"#{"}${field.propertyName}${r"}"}</#if></#list>
</update>
</#if>
</#list>
<#list table.fields as field>
<#if field.keyFlag>
<!-- 新增表${table.name}信息 -->
<insert id="add${entity}">
INSERT INTO ${table.name} (
<#list table.fields as field>
<#if field_index gt 0>,</#if>${field.name}
</#list>
) VALUES (
<#list table.fields as field>
<#if field_index gt 0>,</#if>${r"#{"}${field.propertyName}${r"}"}
</#list>
)
</insert>
</#if>
</#list>
</mapper>
package ${package.Service};
import ${package.Entity}.${entity};
import ${superServiceClassPackage};
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List;
/**
* <p>
* ${table.comment!} 服务类
* </p>
*
* @author ${author}
* @since ${date}
*/
<#if kotlin>
interface ${table.serviceName} : ${superServiceClass}<${entity}>
<#else>
public interface ${table.serviceName} extends ${superServiceClass}<${entity}> {
/**
* ${table.comment!}详情
* @param id
* @return
*/
${entity} info(Long id);
/**
* ${table.comment!}新增
* @param param 根据需要进行传值
* @return
*/
void add(${entity} param);
/**
* ${table.comment!}修改
* @param param 根据需要进行传值
* @return
*/
void modify(${entity} param);
/**
* ${table.comment!}删除(单个条目)
* @param id
* @return
*/
void remove(Long id);
/**
* 删除(多个条目)
* @param ids
* @return
*/
void removes(List<Long> ids);
}
</#if>
\ No newline at end of file
package ${package.ServiceImpl};
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.List;
/**
* <p>
* ${table.comment!} 服务实现类
* </p>
*
* @author ${author}
* @since ${date}
*/
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {
}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
@Resource
private ${table.mapperName} ${table.entityPath}Mapper;
/**
* ${table.comment!}详情
* @param id
* @return
*/
@Override
public ${entity} info(Long id) {
return getById(id);
}
/**
* ${table.comment!}新增
* @param param 根据需要进行传值
* @return
*/
@Override
public void add(${entity} param) {
save(param);
}
/**
* ${table.comment!}修改
* @param param 根据需要进行传值
* @return
*/
@Override
public void modify(${entity} param) {
updateById(param);
}
/**
* ${table.comment!}删除(单个条目)
* @param id
* @return
*/
@Override
public void remove(Long id) {
removeById(id);
}
/**
* ${table.comment!}删除(多个条目)
* @param ids
* @return
*/
@Override
public void removes(List<Long> ids) {
removeByIds(ids);
}
}
</#if>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment