IDEA 插件 - EasyCode,MyBatis 代码生成器最优配置!

具体安装步骤,不再赘述,仅附上个人工作、学习中的对 EasyCode 的详细配置。
插件链接地址:https://gitee.com/makejava/EasyCode

Type Mapper

varchar(\(\d+\))?										java.lang.String
char(\(\d+\))?											java.lang.String
text													java.lang.String
decimal(\(\d+\))?										java.lang.Double
decimal(\(\d+,\d+\))?									java.lang.Double
integer													java.lang.Integer
int(\(\d+\))?											java.lang.Integer
int4													java.lang.Integer
int8													java.lang.Long
bigint(\(\d+\))?										java.lang.Long
datetime(\(\d+\))?										java.time.LocalDateTime
timestamp												java.time.LocalDateTime
boolean													java.lang.Boolean
tinyint(\(\d+\))?										java.lang.Integer
smallint(\(\d+\))?										java.lang.Integer
double(\(\d+\))?										java.lang.Double
double(\(\d+,\d+\))?									java.lang.Double

Template Setting

entity.java

##初始化定义
$!init
##引入宏定义
$!define

##使用宏定义设置回调(保存位置与文件后缀)
#save("/entity", ".java")

##使用宏定义设置包后缀
#setPackageSuffix("entity")

##使用全局变量实现默认包导入
$!autoImport
import java.io.Serializable;

##使用宏定义实现类注释信息
#tableComment("实体类")
public class $!{tableInfo.name} implements Serializable {

    private static final long serialVersionUID = $!tool.serial();
    #foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})/**
     * ${column.comment}
     */#end

    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    #end
    
    public $!{tableInfo.name}() {
    }
    
    public $!{tableInfo.name}(#foreach($column in $tableInfo.fullColumn)$!{tool.getClsNameByFullName($column.type)} $!column.name #if($velocityCount != $tableInfo.fullColumn.size()), #end#end) {
        #foreach($column in $tableInfo.fullColumn)  this.$!column.name = $!column.name;#end
        
    }
#foreach($column in $tableInfo.fullColumn)
##使用宏定义实现get,set方法
    #getSetMethod($column)
#end

    @Override
    public String toString() { 
        StringBuilder str = new StringBuilder();
        str.append("$!{tableInfo.name}{");       
    #foreach( $column in $tableInfo.fullColumn )
    str.append("$!column.name=").append(this.$!column.name)#if( $foreach.hasNext ).append(", ")#end;
    #end
    str.append('}');       
        return str.toString();
    }

}

DTO.java

##导入宏定义
$!define

##保存文件(宏定义)
#save("/dto", "DTO.java")

##包路径(宏定义)
#setPackageSuffix("dto")

##自动导入包(全局变量)
$!autoImport
##import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.io.Serializable;
import lombok.Data;
##import com.baomidou.mybatisplus.annotation.IdType;
##import com.baomidou.mybatisplus.annotation.TableId;

##表注释(宏定义)
#tableComment("DTO")
@Data
public class $!{tableInfo.name}DTO implements Serializable {

    private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})/**${column.comment}*/#end

    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end

}

mapper.java

##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Mapper"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/mapper"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mapper;

import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;

#set($time=$!time.currTime())
#set($time=$time.substring(0,11))
#set($time=$time.replace("-","/"))
/**
 * $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层
 * 
 * @author:$!author
 * @date:$!time
 */
@Mapper
public interface $!{tableName} {

    /**
     * 通过ID查询单条数据
     *
     * @param $!pk.name 主键
     * @return 实例对象
     */
    $!{tableInfo.name} queryById($!pk.shortType $!pk.name);

    /**
     * 通过实体作为筛选条件查询
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 对象列表
     */
    List<$!{tableInfo.name}> queryAll($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
    
    /**
     * 通过实体作为筛选条件查询条数
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 条数
     */
    int queryAllCount($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    /**
     * 新增数据
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 影响行数
     */
    int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    /**
     * 新增选择列
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 影响行数
     */
    int insertSelective($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
    
    /**
     * 修改数据
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 影响行数
     */
    int update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    /**
     * 通过主键删除数据
     *
     * @param $!pk.name 主键
     * @return 影响行数
     */
    int deleteById($!pk.shortType $!pk.name);
    
    /**
     * 批量新增
     * @param recordList
     * @return 影响行数
     */
    int batchInsert(@Param("recordList") List<$!{tableInfo.name}> recordList);
    
    /**
     * 批量修改
     * @param recordList 
     * @return 影响行数
     */
    int batchUpdate(@Param("recordList") List<$!{tableInfo.name}> recordList);
    
    /**
     * 根据主键批量删除
     * @param ids 主键s
     * @return 影响行数
     */
    int batchDelete(@Param("ids") String[] ids);
    
}

serviceImpl.java

##初始化定义
$!init
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;

import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

#set($time=$!time.currTime())
#set($time=$time.substring(0,11))
#set($time=$time.replace("-","/"))
/**
 * $!{tableInfo.comment}($!{tableInfo.name})表服务实现类
 * 
 * @author:$!author
 * @date:$!time
 */
@Service("/$!tool.firstLowerCase($!{tableInfo.name})Service")
public class $!{tableName} implements $!{tableInfo.name}Service {

    @Autowired
    private $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper;

}

service.java

##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Service"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service;

#set($time=$!time.currTime())
#set($time=$time.substring(0,11))
#set($time=$time.replace("-","/"))
/**
 * $!{tableInfo.comment}($!{tableInfo.name})表服务接口
 * 
 * @author:$!author
 * @date:$!time
 */
public interface $!{tableName} {

}

controller.java

##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Controller"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/controller"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;

import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

#set($time=$!time.currTime())
#set($time=$time.substring(0,11))
#set($time=$time.replace("-","/"))
/**
 * $!{tableInfo.comment}($!{tableInfo.name})表控制层
 * 
 * @author:$!author
 * @date:$!time
 */
@RestController
@RequestMapping("/$!tool.firstLowerCase($tableInfo.name)")
public class $!{tableName} {

    @Autowired
    private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;

}

mysql-mapper.xml

##引入mybatis支持
$!mybatisSupport

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

<?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="$!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper">

    <resultMap type="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}" id="$!{tableInfo.name}Map">
#foreach($column in $tableInfo.fullColumn)
        <result property="$!column.name" column="$!column.name" jdbcType="$!column.ext.jdbcType"/>
#end
    </resultMap>
	
	<!-- 伪列 -->
	<sql id="columns">
#foreach($column in $tableInfo.fullColumn)
        a.$!column.obj.name AS $!column.name #if($velocityCount != $tableInfo.fullColumn.size()),#end

#end
    </sql>
    <!-- 查询条件 -->
	<sql id="whereSql">
        <where>
#foreach($column in $tableInfo.fullColumn)
            <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                and a.$!column.obj.name = #{$!column.name}
            </if>
#end
        </where>
    </sql>
	
    <!-- 通过ID查询单条数据 -->
    <select id="queryById" resultType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
        select
          <include refid="columns"/>
        from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name a
        where a.$!pk.obj.name = #{$!pk.name}
    </select>
    
    <!-- 通过实体作为筛选条件查询 -->
    <select id="queryAll" resultType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
        select
          <include refid="columns"/>
        from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name a
        <include refid="whereSql" />
    </select>
    
    <!-- 通过实体作为筛选条件查询条数 -->
    <select id="queryAllCount" resultType="java.lang.Integer">
        select
          count(1)
        from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name a
        <include refid="whereSql" />
    </select>

    <!-- 新增数据 -->
    <insert id="insert" keyProperty="$!pk.name" useGeneratedKeys="true">
        insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($column in $tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext), #end#end)
        values (#foreach($column in $tableInfo.fullColumn)#{$!{column.name}}#if($velocityHasNext), #end#end)
    </insert>
    
    <!-- 新增选择列 -->
    <insert id="insertSelective" keyProperty="$!pk.name" useGeneratedKeys="true">
        insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
        <trim prefix="(" suffix=")" suffixOverrides="," >
#foreach($column in $tableInfo.fullColumn)
            <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                $!column.obj.name,
            </if>
#end
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
#foreach($column in $tableInfo.fullColumn)
            <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                #{$!column.name,jdbcType=$!column.ext.jdbcType},
            </if>
#end
        </trim>
    </insert>
  
    <!-- 修改数据 -->
    <update id="update">
        update $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
        <set>
#foreach($column in $tableInfo.otherColumn)
            <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                $!column.obj.name = #{$!column.name},
            </if>
#end
        </set>
        where $!pk.obj.name = #{$!pk.name}
    </update>

    <!-- 通过主键删除数据 -->
    <delete id="deleteById">
        delete from $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
    </delete>
    
  <!-- 批量新增 -->
  <insert id="batchInsert" parameterType="java.util.List">
        insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} (
        #foreach($column in $tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext), #end#end
        
        )
    values
    <foreach collection="recordList" index="index" item="item" separator=",">
      (
      #foreach($column in $tableInfo.fullColumn)#{item.$!{column.name}}#if($velocityHasNext), #end#end
      
      )
    </foreach>
  </insert>
  
  <!-- 批量修改 -->
  <update id="batchUpdate" parameterType="java.util.List">
    update $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} 
    <trim prefix="set" suffixOverrides=",">
#foreach($column in $tableInfo.otherColumn)
      <trim prefix="$!column.obj.name =case $!pk.obj.name" suffix="end,">
        <foreach collection="recordList" index="index" item="item">
          <if test="item.$!column.name !=null ">
            when #{item.$!pk.name} then #{item.$!column.name}
          </if>
          <if test="item.$!column.name ==null ">
            when #{item.$!pk.name} then $!{tableInfo.obj.name}.$!column.obj.name
          </if>
        </foreach>
      </trim>
#end
    </trim>
    where $!pk.obj.name in(
    <foreach collection="recordList" index="index" item="item" separator=",">
      #{item.$!pk.name}
    </foreach>
    )
  </update>
  
    <!-- 根据主键批量删除 -->
    <delete id="batchDelete" parameterType="java.lang.String">
        delete from $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} where $!pk.obj.name in (
        <foreach collection="ids" index="index" item="item" separator=",">
          #{item}
        </foreach>
        )
  </delete>
  
</mapper>

oracle-mapper.xml

##引入mybatis支持
$!mybatisSupport

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/src/main/resources/mapper"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

<?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="$!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper">

    <resultMap type="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}" id="$!{tableInfo.name}Map">
#foreach($column in $tableInfo.fullColumn)
        <result property="$!column.name" column="$!column.name" jdbcType="$!column.ext.jdbcType"/>
#end
    </resultMap>
	
	<!-- 伪列 -->
	<sql id="columns">
#foreach($column in $tableInfo.fullColumn)
        a.$!column.obj.name AS $!column.name #if($velocityCount != $tableInfo.fullColumn.size()),#end

#end
    </sql>
    <!-- 查询条件 -->
	<sql id="whereSql">
        <where>
#foreach($column in $tableInfo.fullColumn)
            <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                and a.$!column.obj.name = #{$!column.name}
            </if>
#end
        </where>
    </sql>
  
    <!-- 通过ID查询单条数据 -->
    <select id="queryById" resultType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
        select
          <include refid="columns"/>
        from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name a
        where a.$!pk.obj.name = #{$!pk.name}
    </select>
    
    <!-- 通过实体作为筛选条件查询 -->
    <select id="queryAll" resultType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
        select
          <include refid="columns"/>
        from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name a
        <include refid="whereSql" />
    </select>
    
    <!-- 通过实体作为筛选条件查询条数 -->
    <select id="queryAllCount" resultType="java.lang.Integer">
        select
          count(1)
        from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name a
        <include refid="whereSql" />
    </select>

    <!-- 新增数据 -->
    <insert id="insert" keyProperty="$!pk.name" useGeneratedKeys="true">
        insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($column in $tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext), #end#end)
        values (#foreach($column in $tableInfo.fullColumn)#{$!{column.name}}#if($velocityHasNext), #end#end)
    </insert>
    
    <!-- 新增选择列 -->
    <insert id="insertSelective" keyProperty="$!pk.name" useGeneratedKeys="true">
        insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
        <trim prefix="(" suffix=")" suffixOverrides="," >
#foreach($column in $tableInfo.fullColumn)
            <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                $!column.obj.name,
            </if>
#end
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
#foreach($column in $tableInfo.fullColumn)
            <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                #{$!column.name,jdbcType=$!column.ext.jdbcType},
            </if>
#end
        </trim>
    </insert>
    
    <!-- 修改数据 -->
    <update id="update">
        update $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
        <set>
#foreach($column in $tableInfo.otherColumn)
            <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
                $!column.obj.name = #{$!column.name},
            </if>
#end
        </set>
        where $!pk.obj.name = #{$!pk.name}
    </update>
    
    <!-- 通过主键删除数据 -->
    <delete id="deleteById">
        delete from $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
    </delete>
    
  <!-- 批量新增 -->
    <insert id="batchInsert" parameterType="java.util.List">
        insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} (
        #foreach($column in $tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext), #end#end
        
        )
        (
        <foreach collection="recordList" index="index" item="item" separator=",">
          (
          select
          #foreach($column in $tableInfo.fullColumn)#{item.$!{column.name}}#if($velocityHasNext), #end#end
          
          from dual
          )
        </foreach>
        )
    </insert>
    
  <!-- 批量修改 -->
    <update id="batchUpdate" parameterType="java.util.List">
    begin
    <foreach collection="recordList" index="index" item="item" separator=";">
      update $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} 
      <set>
#foreach($column in $tableInfo.otherColumn)
    $!column.obj.name = #{item.$!column.name}
#end
      </set>
      where ID = #{item.$!pk.obj.name}
    </foreach>
    ;end;
  </update>
  
    <!-- 根据主键批量删除 -->
      <delete id="batchDelete" parameterType="java.lang.String">
        delete from $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} where $!pk.obj.name in (
        <foreach collection="ids" index="index" item="item" separator=",">
          #{item}
        </foreach>
        )
  </delete>
  
</mapper>

Global Config

init

##初始化区域

##去掉表的t_前缀
#if($tableInfo.obj.name.startsWith("t_"))
    $!tableInfo.setName($tool.getClassName($tableInfo.obj.name.substring(2)))
#end

##参考阿里巴巴开发手册,POJO 类中布尔类型的变量,都不要加 is 前缀,否则部分框架解析会引起序列化错误
#foreach($column in $tableInfo.fullColumn)
    #if($column.name.startsWith("is") && $column.type.equals("java.lang.Boolean"))
        $!column.setName($tool.firstLowerCase($column.name.substring(2)))
    #end
#end

##实现动态排除列
#set($temp = $tool.newHashSet("testCreateTime", "otherColumn"))
#foreach($item in $temp)
    #set($newList = $tool.newArrayList())
    #foreach($column in $tableInfo.fullColumn)
        #if($column.name!=$item)
        ##带有反回值的方法调用时使用$tool.call来消除返回值
            $tool.call($newList.add($column))
        #end
    #end
##重新保存
    $tableInfo.setFullColumn($newList)
#end

##对importList进行篡改
#set($temp = $tool.newHashSet())
#foreach($column in $tableInfo.fullColumn)
    #if(!$column.type.startsWith("java.lang."))
    ##带有反回值的方法调用时使用$tool.call来消除返回值
        $tool.call($temp.add($column.type))
    #end
#end
##覆盖
#set($importList = $temp)

define

##(Velocity宏定义)

##定义设置表名后缀的宏定义,调用方式:#setTableSuffix("Test")
#macro(setTableSuffix $suffix)
    #set($tableName = $!tool.append($tableInfo.name, $suffix))
#end

##定义设置包名后缀的宏定义,调用方式:#setPackageSuffix("Test")
#macro(setPackageSuffix $suffix)
    #if($suffix!="")package #end#if($tableInfo.savePackageName!="")$!{tableInfo.savePackageName}.#{end}$!suffix;
#end

##定义直接保存路径与文件名简化的宏定义,调用方式:#save("/entity", ".java")
#macro(save $path $fileName)
    $!callback.setSavePath($tool.append($tableInfo.savePath, $path))
    $!callback.setFileName($tool.append($tableInfo.name, $fileName))
#end

##定义表注释的宏定义,调用方式:#tableComment("注释信息")
#macro(tableComment $desc)
#set($time=$!time.currTime())
#set($time=$time.substring(0,11))
#set($time=$time.replace("-","/"))
/**
 * $!{tableInfo.comment}($!{tableInfo.name})$desc
 * 
 * @author:$!author
 * @date:$!time
 */
#end

##定义GET,SET方法的宏定义,调用方式:#getSetMethod($column)
#macro(getSetMethod $column)

    public $!{tool.getClsNameByFullName($column.type)} get$!{tool.firstUpperCase($column.name)}() {
        return $!{column.name};
    }

    public void set$!{tool.firstUpperCase($column.name)}($!{tool.getClsNameByFullName($column.type)} $!{column.name}) {
        #if(${column.type.equals("java.lang.String")})this.$!{column.name} = $!{column.name}== null ? null : $!{column.name}.trim();
    #else this.$!{column.name} = $!{column.name};#end} 
#end

mybatisSupport

##针对Mybatis 进行支持,主要用于生成xml文件
#foreach($column in $tableInfo.fullColumn)
    ##储存列类型
    $tool.call($column.ext.put("sqlType", $tool.getField($column.obj.dataType, "typeName")))
    #if($tool.newHashSet("java.lang.String").contains($column.type))
        #set($jdbcType="VARCHAR")
    #elseif($tool.newHashSet("java.lang.Boolean", "boolean").contains($column.type))
        #set($jdbcType="BOOLEAN")
    #elseif($tool.newHashSet("java.lang.Byte", "byte").contains($column.type))
        #set($jdbcType="BYTE")
    #elseif($tool.newHashSet("java.lang.Integer", "int", "java.lang.Short", "short").contains($column.type))
        #set($jdbcType="INTEGER")
    #elseif($tool.newHashSet("java.lang.Long", "long").contains($column.type))
        #set($jdbcType="INTEGER")
    #elseif($tool.newHashSet("java.lang.Float", "float", "java.lang.Double", "double").contains($column.type))
        #set($jdbcType="NUMERIC")
    #elseif($tool.newHashSet("java.util.Date", "java.sql.Timestamp", "java.time.Instant", "java.time.LocalDateTime", "java.time.OffsetDateTime", "	java.time.ZonedDateTime").contains($column.type))
        #set($jdbcType="TIMESTAMP")
    #elseif($tool.newHashSet("java.sql.Date", "java.time.LocalDate").contains($column.type))
        #set($jdbcType="TIMESTAMP")
    #else
        ##其他类型
        #set($jdbcType="OTHER")
    #end
    $tool.call($column.ext.put("jdbcType", $jdbcType))
#end

##定义宏,查询所有列
#macro(allSqlColumn)#foreach($column in $tableInfo.fullColumn)$column.obj.name#if($velocityHasNext), #end#end#end

你可能感兴趣的:(效率)