Easy Code IDEA plug-in plantilla personalizada

Una, plantilla DAO

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

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

#if ($ tableInfo.savePackageName) paquete $ {} # tableInfo.savePackageName {end} dao!. ;

importación $ {} tableInfo.savePackageName .entity $ {} tableInfo.name!.! ;
org.apache.ibatis.annotations.Param importación ;
java.util.List importación ;

/ **
 * $ {} TableInfo.comment ($ {} TableInfo.name) base de datos de tabla de la capa de acceso 
 * 
 * @author xiaoG 
 * @since $! Time.currTime () 
 * / 
público interfaz de $ {{NombreTabla} 

    / ** 
     * por un solo ID datos de la consulta 
     * 
     ! * @ param $ pk.name clave primaria 
     * @return instancia de objeto 
     * / 
    $ {} tableInfo.name la findById (!! $ $ pk.shortType pk.name)! ;
 
    / ** 
     * entidad no vacío atributo de consulta como una condición de filtro 
     * 
     * @param $! tool.firstLowerCase ($!} {tableInfo.name) objeto de instancia 
     * @return lista de objetos 
     * / 
    list <$!} {tableInfo.name> findBy $ {TableInfo } .name ($ {} $ tableInfo.name tool.firstLowerCase (tableInfo.name $ {}) !!!) ;
 
    / **
     * Propiedad nueva entidad no es nulo columnas 
     * 
     * @param $! Tool.firstLowerCase ($!} {TableInfo.name) objeto de instancia 
     * @return línea número impacto 
     * / 
    int INSERT ($!} {TableInfo.name $! tool.firstLowerCase (tableInfo.name} $ {!)) ;
 
    / ** 
     * lote añadir todas las columnas, la longitud de la lista no puede ser 0, y la lista es nulo o la identificación uniforme uniforme no es nulo 
     * 
     * lista de lista de objetos instancia @param conjunto 
     * @return afectar el número de filas 
     * / 
    int insertList (List <tableInfo.name} $ {!> Lista) ;
 
    / ** 
     * modificados por atributo de clave primaria de la entidad no es nulo columnas 
     * 
     * @ param tool.firstLowerCase $ ($ !! {tableInfo.name}) objeto de instancia 
     * @return afecta al número de filas 
     * /
    Actualización int ($ {} $ tableInfo.name tool.firstLowerCase (tableInfo.name $ {}) !!!) ;
 
    / ** 
     * Lista entidad modificado a través de la clave principal, la longitud de la lista no puede ser 0 
     * Nota: cuando un atributo de entidad es nula respectivamente la columna correspondiente se actualizará para nula 
     * 
     objeto de instancia de lista @ param * 
     número de impacto @return filas * 
     * / 
    int UpdateBatch (List <tableInfo.name} $ {!> Lista) ;
 
    / ** 
     * Eliminar datos de clave primaria 
     * 
     * @param $ pk.name clave primaria! 
     * @return afectar el número de filas 
     * / 
    int deleteById ($ $ pk.shortType pk.name !!) ;
 
    / ** 
     * Eliminar lote propiedad vacía por una no entidad 
     * 
     * @param $ herramienta! .firstLowerCase ($ {} tableInfo.name) entidad 
     * @return afecta al número de filas 
     * /
    tableInfo.name deleteBatchBy $ {} int ($ {} $ tableInfo.name tool.firstLowerCase (tableInfo.name $ {}) !!!)! ;
   
    / ** 
     * lista de eliminación de la clave principal, la longitud de la lista no puede ser 0 
     * 
     * @ lista parámetro lista de clave primaria 
     * @return línea número impacto 
     * / 
    int deleteBatchByIds (lista <$ pk.shortType!> lista) ;
     
}

 

Dos, mapper.xml plantilla

##引入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}.dao.$!{tableInfo.name}Dao">

    <resultMap type="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}" id="$!{tableInfo.name}ResultMap">
#foreach($column in $tableInfo.fullColumn)
        <result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>
#end
    </resultMap>

    <sql id="table_field">
      #allSqlColumn()
      
    </sql>
       
    <!--通过Id查询单个-->
    <select id="findById" resultMap="$!{tableInfo.name}ResultMap">
        select
          <include refid="table_field" />
        from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name
        where $!pk.obj.name = #{$!pk.name}
    </select>


    <!--通过实体不为空的属性作为筛选条件查询-->
    <select id="findBy$!{tableInfo.name}" resultMap="$!{tableInfo.name}ResultMap">
        select
          <include refid="table_field" />
        from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name
        <where>
#foreach($column in $tableInfo.fullColumn)
            <if test="$!column.name != null">
                and $!column.obj.name = #{$!column.name}
            </if>
#end
        </where>
    </select>

    <!--新增实体属性不为null的列-->
    <insert id="insert" 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">
             $!column.obj.name,
          </if>
#end          
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
#foreach($column in  $tableInfo.fullColumn)
          <if test="$!column.name != null">
             #{$!column.name},
          </if>
#end
        </trim>
    </insert>

    <!--批量新增所有列,列表长度不能为0,且列表id统一为null或者统一不为null-->
    <insert id="insertList" keyProperty="$!pk.name" useGeneratedKeys="true" parameterType="list">
        insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
         (<if test="$!pk.name != null">$!pk.obj.name,</if>#foreach($column in $tableInfo.otherColumn)$!{column.obj.name}#if($velocityHasNext), #end#end)
        values
        <foreach item="item" collection="list" separator="," open="" close="" index="index">
         (<if test="$!pk.name != null">#{$!pk.name},</if>#foreach($column in $tableInfo.otherColumn)#{$!{column.name}}#if($velocityHasNext), #end#end)
        </foreach>
    </insert>

    <!--通过主键修改实体属性不为null的列-->
    <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>

    <!--通过主键修改实体列表,列表长度不能为0,注意:当实体属性为null时,对应的列也会别更新为null-->
    <update id="updateBatch" parameterType="list">
        update $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} set
#foreach($column in $tableInfo.otherColumn)
        <foreach item="item" collection="list" separator="," open="" close="" index="index">
            $!column.obj.name = CASE
              WHEN #{item.$!pk.name} THEN #{item.$!column.name}
            END
        </foreach>
#end
        where $!pk.obj.name in
        <foreach item="item" collection="list" separator="," open="(" close=")" index="index">
            #{item.$!pk.name}
        </foreach>
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
    </delete>

    <!--通过实体非空属性删除-->
    <delete id="deleteBatchBy$!{tableInfo.name}">
        delete from $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
        <where>
#foreach($column in $tableInfo.otherColumn)
            <if test="$!column.name != null">
                and $!column.obj.name = #{$!column.name}
            </if>
#end
        </where>
    </delete>
    
    <!--通过主键列表删除,列表长度不能为0-->
    <delete id="deleteBatchByIds" parameterType="list">
        delete from $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} where $!pk.obj.name in
        <foreach item="item" collection="list" separator="," open="(" close=")" index="index">
            #{item}
        </foreach>
    </delete>
</mapper>

 

Supongo que te gusta

Origin www.cnblogs.com/xiaogblog/p/12571654.html
Recomendado
Clasificación