MyBatis plus generator自動生成Dao層
最近在搞生成包的問題,發現Mybatis plus不需要一張一張表的配置耶,所以就有了下文啦哈哈哈~
主要步驟:
1.新建基於SpringBoot的Maven項目,引入相關依賴
2.參考官方文檔配置生成包的信息,編寫生成generated包的主要類
3.新建模板信息(如果有自己特殊的要求的話,沒有使用默認的即可)
4.將生成包打包測試 然后就可以開始使用啦~
整體項目目錄結構如下(紅色標記的文件為手動新增的內容):

1.新建基於SpringBoot 的 Maven項目,pom.xml如下(我這里用的mysql8.x的,可根據實際情況更改數據庫驅動包哈)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.imodule.product</groupId>
<artifactId>product</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>product</name>
<description>Demo project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<imodule-nexus.version>0.0.1-SNAPSHOT</imodule-nexus.version>
<quartz.version>2.3.0</quartz.version>
<org.slf4j-version>1.6.4</org.slf4j-version>
</properties>
<dependencies>
<!-- spring-boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--mybatis-plus自動的維護了mybatis以及mybatis-spring的依賴,
在springboot中這三者不能同時的出現,避免版本的沖突,表示:跳進過這個坑-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2.主要配置類 CodeGenerator.java
整個生成過程中 最值得講的就是此類了,這里我連的TiDB數據庫(類似與MySQL,直接用mysql的驅動即可)
細節一:策略配置 StrategyConfig 指定數據庫中哪些表需要生成Dao
String[] tablename = {"PRD_BASE","PRD_PROPERTY"}; //多張表用數組表示
strategy.setInclude(tablename);// 包含那些表,excude排除哪些表 include與excude只能設置一個(如果不添加此項配置 默認生成數據庫中所有的表對應的Dao)
細節二:由於我們是用的TiDB數據庫,這不是我們原來的業務數據庫,所以需要從其它庫傳輸數據到TiDB,子啊通過DataPipeline傳輸的時候,發現DataPipeline有個自動的功能,當它發現同步的表沒有主鍵的時候會自動建立列 _id 作為這張表的主鍵,同步到TiDB指定庫中,這就給我們帶來了難題, _id 字段在通過mybatis plus generator生成后,屬性名為 id ,去掉了前綴 _ ,當我們執行查詢的時候就會找不到 id字段,手動注釋掉這個 id字段后,數據又正常啦。所以我們就更改了模板文件新增了 #if判斷,就是在字段迭代的時候先判斷當前字段是不是 _id,如果是就不做任何操作,也就是不將此屬性添加到對象總,如果不是就正常執行。
#if(${field.name.equals("_id")})
語句如下:
#foreach($field in ${table.fields})
#if(${field.name.equals("_id")})
#else
...中間省略原來的模板代碼信息...
private ${field.propertyType} ${field.propertyName};
#end
#end
細節三:模板配置 StrategyConfig的setTablePrefix方法,我原以為是可以手動添加表前綴,結果測試發現這是去掉前綴的意思。
示例:
數據庫表名稱為 PRD_USER
設置 StrategyConfig.setTablePrefix("PRD_");
最后生成的實體類: User ,去掉了 PRD_ 前綴 (除了實體類 Mapper Service Controller都會統一去掉 PRD_前綴)
如果不設置的話tablePrefix的話,生成的實體類為 PrdUser (Mapper Service Controller都類似)
細節四:模板配置 TemplateConfig 指定生成的結果文件模板信息 (結果文件中需要包含哪些 語法參考對應的引擎)
templateConfig.setEntity("templates/entity.java");
templateConfig.setMapper("templates/mapper.java"); templateConfig.setXml("templates/mapper.xml"); templateConfig.setService("templates/service.java"); templateConfig.setServiceImpl("templates/serviceImpl.java"); templateConfig.setController("templates/controller.java");
這里我們使用TiDB,打算用同一套數據源,里面包含多個數據庫(意思就是同一個數據庫服務器里面建立多個數據庫,類似與DBLINK),系統需要具備跨庫查詢的功能,直接生成的話是無法查詢其它數據庫的數據庫的
所以我們在模板上做了一些小改造:在表名前增加了庫名(目前沒有參數可以設置,所以我們就直接在entity.java.vm模版文件中更改了,文章最后會提供更改之后的Entity模板文件)
原來是: @TableName("${table.name}")
更改后: @TableName("prd_demo.${table.name}") //在這里把庫名固定了 (如果有多個庫需要分別生成,每次生成前需要先更改這個schema name 數據庫名稱)
package cozhelim.imodule.product;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
@Slf4j
public class CodeGenerator {
public static void main(String[] args) {
// 代碼生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
String projectPath = System.getProperty("user.dir");
gc.setOutputDir(projectPath + "/src/main/java");
gc.setAuthor("jobob");
gc.setOpen(false);
// gc.setIdType(null);
// gc.setSwagger2(true); 實體屬性 Swagger2 注解
mpg.setGlobalConfig(gc);
// 數據源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://10.11.22.33:4000/prd_demo?characterEncoding=utf8");
// dsc.setSchemaName("public");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("123456");
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName("product");//scanner("模塊名")
pc.setParent("com.imodule.product");
mpg.setPackageInfo(pc);
// 自定義配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
}
};
// 如果模板引擎是 freemarker
//String templatePath = "/templates/mapper.xml.ftl";
// 如果模板引擎是 velocity
String templatePath = "/templates/mapper.xml.vm";
// 自定義輸出配置
List<FileOutConfig> focList = new ArrayList<>();
// 自定義配置會被優先輸出
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定義輸出文件名 , 如果你 Entity 設置了前后綴、此處注意 xml 的名稱會跟着發生變化!!
return projectPath + "/src/main/resources/mapper/" + pc.getModuleName()
+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
/*
cfg.setFileCreate(new IFileCreate() {
@Override
public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) {
// 判斷自定義文件夾是否需要創建
checkDir("調用默認方法創建的目錄,自定義目錄用");
if (fileType == FileType.MAPPER) {
// 已經生成 mapper 文件判斷存在,不想重新生成返回 false
return !new File(filePath).exists();
}
// 允許生成模板文件
return true;
}
});
*/
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
// 配置模板
TemplateConfig templateConfig = new TemplateConfig();
// 配置自定義輸出模板
//指定自定義模板路徑,注意不要帶上.ftl/.vm, 會根據使用的模板引擎自動識別
templateConfig.setEntity("templates/entity.java");
templateConfig.setMapper("templates/mapper.java");
templateConfig.setXml("templates/mapper.xml");
templateConfig.setService("templates/service.java");
templateConfig.setServiceImpl("templates/serviceImpl.java");
templateConfig.setController("templates/controller.java");
templateConfig.setXml(null);
mpg.setTemplate(templateConfig);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
/* strategy.setSuperEntityClass("你自己的父類實體,沒有就不用設置!");
strategy.setSuperMapperClass("");
strategy.setSuperServiceClass("");
strategy.setSuperControllerClass("你自己的父類控制器,沒有就不用設置!");*/
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
// 公共父類
// 寫於父類中的公共字段
String[] tablename = {"PRD_BASE","PRD_PROPERTY"};
strategy.setInclude(tablename);// 包含那些表,excude排除哪些表,多張表用數組表示
strategy.setControllerMappingHyphenStyle(true);
//eg: tablename: PRD_USER,StrategyConfig.setTablePrefix("PRD"); 生成的實體類: User
// strategy.setTablePrefix(new String[]{"PRD","demo_"});//去掉生成的實體類的前綴
// strategy.setTablePrefix(pc.getModuleName() + "_");
mpg.setStrategy(strategy);
// mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.setTemplateEngine(new VelocityTemplateEngine());//更改模板引擎
/**
* 這一段是為了測試看看里面包含些啥 可以忽略
*/
ConfigBuilder configBuilder = new ConfigBuilder( pc, dsc, strategy, templateConfig, gc);
MySqlQuery mySqlQuery =new MySqlQuery();
String sql = mySqlQuery.tablesSql();
log.info("tidb sql:"+sql);// show table status
List<TableInfo> tableinfo = configBuilder.getTableInfoList();
for(TableInfo table:tableinfo){
log.info("tidb tableinfo:"+table.getEntityName());
log.info("tidb tableinfo:"+table.getXmlName());
}
mpg.execute();
}
}
3. 這里用的是 VM模板,模板文件分別如下(解壓官方mybatis-plus-generator-3.0.5.jar,在mybatis-plus-generator-3.0.5\templates目錄下 獲取的)

entity.java.vm(默認的)
package ${package.Entity};
#foreach($pkg in ${table.importPackages})
import ${pkg};
#end
#if(${swagger2})
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
#end
#if(${entityLombokModel})
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
#end
/**
* <p>
* $!{table.comment}
* </p>
*
* @author ${author}
* @since ${date}
*/
#if(${entityLombokModel})
@Data
#if(${superEntityClass})
@EqualsAndHashCode(callSuper = true)
#else
@EqualsAndHashCode(callSuper = false)
#end
@Accessors(chain = true)
#end
#if(${table.convert})
@TableName("${table.name}")
#end
#if(${swagger2})
@ApiModel(value="${entity}對象", description="$!{table.comment}")
#end
#if(${superEntityClass})
public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
#elseif(${activeRecord})
public class ${entity} extends Model<${entity}> {
#else
public class ${entity} implements Serializable {
#end
private static final long serialVersionUID = 1L;
## ---------- BEGIN 字段循環遍歷 ----------
#foreach($field in ${table.fields})
#if(${field.keyFlag})
#set($keyPropertyName=${field.propertyName})
#end
#if("$!field.comment" != "")
#if(${swagger2})
@ApiModelProperty(value = "${field.comment}")
#else
/**
* ${field.comment}
*/
#end
#end
#if(${field.keyFlag})
## 主鍵
#if(${field.keyIdentityFlag})
@TableId(value = "${field.name}", type = IdType.AUTO)
#elseif(!$null.isNull(${idType}) && "$!idType" != "")
@TableId(value = "${field.name}", type = IdType.${idType})
#elseif(${field.convert})
@TableId("${field.name}")
#end
## 普通字段
#elseif(${field.fill})
## ----- 存在字段填充設置 -----
#if(${field.convert})
@TableField(value = "${field.name}", fill = FieldFill.${field.fill})
#else
@TableField(fill = FieldFill.${field.fill})
#end
#elseif(${field.convert})
@TableField("${field.name}")
#end
## 樂觀鎖注解
#if(${versionFieldName}==${field.name})
@Version
#end
## 邏輯刪除注解
#if(${logicDeleteFieldName}==${field.name})
@TableLogic
#end
private ${field.propertyType} ${field.propertyName};
#end
## ---------- END 字段循環遍歷 ----------
#if(!${entityLombokModel})
#foreach($field in ${table.fields})
#if(${field.propertyType.equals("boolean")})
#set($getprefix="is")
#else
#set($getprefix="get")
#end
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}) {
#end
this.${field.propertyName} = ${field.propertyName};
#if(${entityBuilderModel})
return this;
#end
}
#end
#end
#if(${entityColumnConstant})
#foreach($field in ${table.fields})
public static final String ${field.name.toUpperCase()} = "${field.name}";
#end
#end
#if(${activeRecord})
@Override
protected Serializable pkVal() {
#if(${keyPropertyName})
return this.${keyPropertyName};
#else
return null;
#end
}
#end
#if(!${entityLombokModel})
@Override
public String toString() {
return "${entity}{" +
#foreach($field in ${table.fields})
#if($!{foreach.index}==0)
"${field.propertyName}=" + ${field.propertyName} +
#else
", ${field.propertyName}=" + ${field.propertyName} +
#end
#end
"}";
}
#end
}
mapper.xml.vm(默認的)
<?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(${enableCache})
<!-- 開啟二級緩存 -->
<cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
#end
#if(${baseResultMap})
<!-- 通用查詢映射結果 -->
<resultMap id="BaseResultMap" type="${package.Entity}.${entity}">
#foreach($field in ${table.fields})
#if(${field.keyFlag})##生成主鍵排在第一位
<id column="${field.name}" property="${field.propertyName}" />
#end
#end
#foreach($field in ${table.commonFields})##生成公共字段
<result column="${field.name}" property="${field.propertyName}" />
#end
#foreach($field in ${table.fields})
#if(!${field.keyFlag})##生成普通字段
<result column="${field.name}" property="${field.propertyName}" />
#end
#end
</resultMap>
#end
#if(${baseColumnList})
<!-- 通用查詢結果列 -->
<sql id="Base_Column_List">
#foreach($field in ${table.commonFields})
${field.name},
#end
${table.fieldNames}
</sql>
#end
</mapper>
mapper.java.vm(默認的)
package ${package.Mapper};
import ${package.Entity}.${entity};
import ${superMapperClassPackage};
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* $!{table.comment} Mapper 接口
* </p>
*
* @author ${author}
* @since ${date}
*/
#if(${kotlin})
interface ${table.mapperName} : ${superMapperClass}<${entity}>
#else
@Mapper
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
}
#end
service.java.vm(默認的)
package ${package.Service};
import ${package.Entity}.${entity};
import ${superServiceClassPackage};
/**
* <p>
* $!{table.comment} 服務類
* </p>
*
* @author ${author}
* @since ${date}
*/
#if(${kotlin})
interface ${table.serviceName} : ${superServiceClass}<${entity}>
#else
public interface ${table.serviceName} extends ${superServiceClass}<${entity}> {
}
#end
seviceimpl.java.vm(默認的)
package ${package.ServiceImpl};
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;
/**
* <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} {
}
#end
controller.java.vm(默認的)
package ${package.Controller};
import org.springframework.web.bind.annotation.RequestMapping;
#if(${restControllerStyle})
import org.springframework.web.bind.annotation.RestController;
#else
import org.springframework.stereotype.Controller;
#end
#if(${superControllerClassPackage})
import ${superControllerClassPackage};
#end
/**
* <p>
* $!{table.comment} 前端控制器
* </p>
*
* @author ${author}
* @since ${date}
*/
#if(${restControllerStyle})
@RestController
#else
@Controller
#end
@RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end")
#if(${kotlin})
class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end
#else
#if(${superControllerClass})
public class ${table.controllerName} extends ${superControllerClass} {
#else
public class ${table.controllerName} {
#end
}
#end
4.主類設計 ProductApplication.java
package com.imodule.product;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ProductApplication {
/**
* springboot 項目主啟動類
* @param args main 函數入參
*/
public static void main(String[] args) {
SpringApplication.run(ProductApplication.class, args);
}
}
執行步驟: 直接執行 CodeGenerator.java的main方法就可以了啦
執行結果: (紅色框框標記的文件均為自動生成的)

5.做個測試吧,我們可以就在這個項目里面添加數據源配置信息 寫測試類開始測試啦
添加數據源配置:

測試類編寫:PrdBaseMapperTest.java
package com.imodule.product.mapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.imodule.product.product.entity.PrdBase;
import com.imodule.product.product.mapper.PrdBaseMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import java.util.Arrays;
import java.util.List;
//@RunWith(SpringRunner.class)
@ContextConfiguration
@SpringBootTest
class PrdBaseMapperTest {
@Autowired
private PrdBaseMapper prdBaseMapper;
@Test
public void testPrdBaseMapper(){
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("columnname","columnvalue");//這里寫對應的列名與列值即可
List<PrdBase> prdbase = prdBaseMapper.selectList(queryWrapper);
System.out.println("testPrdBaseMapper result:"+prdbase);
}
}
測試結果 歐克啦啦啦啦~

完整的生成流程就如上所述啦~
最后提供一下更改之后的entity模板文件(基於VM)
package ${package.Entity};
#foreach($pkg in ${table.importPackages})
import ${pkg};
#end
#if(${swagger2})
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
#end
#if(${entityLombokModel})
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
#end
/**
* <p>
* $!{table.comment}
* </p>
*
* @author ${author}
* @since ${date}
*/
#if(${entityLombokModel})
@Data
#if(${superEntityClass})
@EqualsAndHashCode(callSuper = true)
#else
@EqualsAndHashCode(callSuper = false)
#end
@Accessors(chain = true)
#end
#if(${table.convert})
@TableName("prd_prd.${table.name}")
#end
#if(${swagger2})
@ApiModel(value="${entity}對象", description="$!{table.comment}")
#end
#if(${superEntityClass})
public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
#elseif(${activeRecord})
public class ${entity} extends Model<${entity}> {
#else
public class ${entity} implements Serializable {
#end
private static final long serialVersionUID = 1L;
## ---------- BEGIN 字段循環遍歷 ----------
#foreach($field in ${table.fields})
#if(${field.name.equals("_id")})
#else
#if(${field.keyFlag})
#set($keyPropertyName=${field.propertyName})
#end
#if("$!field.comment" != "")
#if(${swagger2})
@ApiModelProperty(value = "${field.comment}")
#else
/**
* ${field.comment}
*/
#end
#end
#if(${field.keyFlag})
## 主鍵
#if(${field.keyIdentityFlag})
@TableId(value = "${field.name}", type = IdType.AUTO)
#elseif(!$null.isNull(${idType}) && "$!idType" != "")
@TableId(value = "${field.name}", type = IdType.${idType})
#elseif(${field.convert})
@TableId("${field.name}")
#end
## 普通字段
#elseif(${field.fill})
## ----- 存在字段填充設置 -----
#if(${field.convert})
@TableField(value = "${field.name}", fill = FieldFill.${field.fill})
#else
@TableField(fill = FieldFill.${field.fill})
#end
#elseif(${field.convert})
@TableField("${field.name}")
#end
## 樂觀鎖注解
#if(${versionFieldName}==${field.name})
@Version
#end
## 邏輯刪除注解
#if(${logicDeleteFieldName}==${field.name})
@TableLogic
#end
private ${field.propertyType} ${field.propertyName};
#end
#end
## ---------- END 字段循環遍歷 ----------
#if(!${entityLombokModel})
#foreach($field in ${table.fields})
#if(${field.propertyType.equals("boolean")})
#set($getprefix="is")
#else
#set($getprefix="get")
#end
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}) {
#end
this.${field.propertyName} = ${field.propertyName};
#if(${entityBuilderModel})
return this;
#end
}
#end
#end
#if(${entityColumnConstant})
#foreach($field in ${table.fields})
public static final String ${field.name.toUpperCase()} = "${field.name}";
#end
#end
#if(${activeRecord})
@Override
protected Serializable pkVal() {
#if(${keyPropertyName})
return this.${keyPropertyName};
#else
return null;
#end
}
#end
#if(!${entityLombokModel})
@Override
public String toString() {
return "${entity}{" +
#foreach($field in ${table.fields})
#if($!{foreach.index}==0)
"${field.propertyName}=" + ${field.propertyName} +
#else
", ${field.propertyName}=" + ${field.propertyName} +
#end
#end
"}";
}
#end
}
