Commit 68312e4c authored by zhoushiguang's avatar zhoushiguang

代码生成模板

parent 658cc7cd
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