欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

IDEA插件EasyCode及MyBatis最优配置步骤详解

程序员文章站 2022-03-03 12:05:24
具体安装步骤,不再赘述,仅附上个人工作、学习中的对 easycode 的详细配置。插件链接地址:https://gitee.com/makejava/easycodetype mappervarcha...

具体安装步骤,不再赘述,仅附上个人工作、学习中的对 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("-","/"))
/**
 * <p>
 * $!{tableinfo.comment}($!{tableinfo.name})表数据库访问层
 * </p>
 * 
 * @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("-","/"))
/**
 * <p>
 * $!{tableinfo.comment}($!{tableinfo.name})表服务实现类
 * </p>
 * 
 * @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("-","/"))
/**
 * <p>
 * $!{tableinfo.comment}($!{tableinfo.name})表服务接口
 * </p>
 * 
 * @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("-","/"))
/**
 * <p>
 * $!{tableinfo.comment}($!{tableinfo.name})表控制层
 * </p>
 * 
 * @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("-","/"))
/**
 * <p>
 * $!{tableinfo.comment}($!{tableinfo.name})$desc
 * </p>
 * 
 * @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

到此这篇关于idea插件easycode mybatis最优配置步骤详解的文章就介绍到这了,更多相关idea 插件easycode 内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!