Easy Code仿若依配置

1,309 阅读1分钟

主题列表:idea插件

结合若依的MVC方法结构,生成了一套自己的模板

Mapper:

<?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}Result">
    #foreach($column in $tableInfo.fullColumn)
            <result property="$!column.name" column="$!column.obj.name"/>
    #end
</resultMap>

<sql id="select$!{tableInfo.name}Vo">
    select #allSqlColumn() from $!{tableInfo.obj.name}
</sql>

<select id="select$!{tableInfo.name}ById" resultMap="$!{tableInfo.name}Result">
    <include refid="select$!{tableInfo.name}Vo"/>
        where $!pk.obj.name = #{$!pk.name}
</select>

<select id="select$!{tableInfo.name}List" resultMap="$!{tableInfo.name}Result" parameterType="$!{tableInfo.name}">
    <include refid="select$!{tableInfo.name}Vo"/>
        <where>
        #foreach($column in $tableInfo.fullColumn)
        <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end"> and $!column.obj.name = #{$!column.name}</if>
         #end
        </where>
</select>

<insert id="insert$!{tableInfo.name}" parameterType="$!{tableInfo.name}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end>
    insert into $!{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.obj.name = #{$!column.name},</if>
    #end
    </trim>
</insert>

<update id="update$!{tableInfo.name}">
    update $!{tableInfo.obj.name}
    <trim prefix="SET" 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 = #{$!column.name},</if>
    #end
    </trim>
    where $!pk.obj.name = #{$!pk.name}
</update>

<delete id="delete$!{tableInfo.name}ById">
    delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
</delete>
</mapper>

dao:

/**
 * $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层
 *
 * @author $!author
 * @since $!time.currTime()
 */
   @Mapper
   @Repository
   public interface $!{tableInfo.name}Mapper {

    /**
    * 查询$!{tableInfo.comment}
    *
    * @param id $!{tableInfo.comment}ID
    * @return $!{tableInfo.comment}
    */
      public $!{tableInfo.name} select$!{tableInfo.name}ById($!pk.shortType $!pk.name);

    /**
    * 查询$!{tableInfo.comment}列表
    *
    * @param $!{tableInfo.name} $!{tableInfo.comment}
    * @return $!{tableInfo.comment}
    */
      public List<$!{tableInfo.name}> select$!{tableInfo.name}List($!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name}));

    /**
    * 新增$!{tableInfo.comment}
    *
    * @param $!{tableInfo.name} $!{tableInfo.comment}
    * @return 结果
    */
      public int insert$!{tableInfo.name}($!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name}));

   /**
    * 修改$!{tableInfo.comment}
    *
    * @param $!{tableInfo.name} $!{tableInfo.comment}
    * @return 影响行数
      */
      public int update$!{tableInfo.name}($!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name}));

   /**
    * 通过主键删除数据
    *
    * @param $!pk.name 主键
    * @return 影响行数
    */
      public int delete$!{tableInfo.name}ById($!pk.shortType $!pk.name);

}

service:

/**
 * $!{tableInfo.comment}($!{tableInfo.name})表服务接口
 *
 * @author $!author
 * @since $!time.currTime()
 */
   public interface I$!{tableName} {

   /**
    * 查询$!{tableInfo.comment}
    *
    * @param id $!{tableInfo.comment}ID
    * @return $!{tableInfo.comment}
    */
      public $!{tableInfo.name} select$!{tableInfo.name}ById($!pk.shortType $!pk.name);

    /**
    * 查询$!{tableInfo.comment}列表
    *
    * @param $!{tableInfo.name} $!{tableInfo.comment}
    * @return $!{tableInfo.comment}
    */
      public List<$!{tableInfo.name}> select$!{tableInfo.name}List($!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name}));

    /**
    * 新增$!{tableInfo.comment}
    *
    * @param $!{tableInfo.name} $!{tableInfo.comment}
    * @return 结果
    */
      public int insert$!{tableInfo.name}($!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name}));

   /**
    * 修改$!{tableInfo.comment}
    *
    * @param $!{tableInfo.name} $!{tableInfo.comment}
    * @return 影响行数
    */
      public int update$!{tableInfo.name}($!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name}));

   /**
    * 通过主键删除数据
    *
    * @param $!pk.name 主键
    * @return 影响行数
    */
      public int delete$!{tableInfo.name}ById($!pk.shortType $!pk.name);
      }

serviceImpl:

 /**
   * $!{tableInfo.comment}($!{tableInfo.name})表服务实现类
   *
   * @author $!author
   * @since $!time.currTime()
   */
   @Service
   public class $!{tableName} implements I$!{tableInfo.name}Service {
   @Autowired
   private $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper;

   /**
   * 查询$!{tableInfo.comment}
   *
   * @param id $!{tableInfo.comment}ID
   * @return $!{tableInfo.comment}
   */
     @Override     
     public $!{tableInfo.name} select$!{tableInfo.name}ById($!pk.shortType $!pk.name) {
       return this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.select$!{tableInfo.name}ById($!pk.name);
     }

   /**
   * 查询$!{tableInfo.comment}列表
   *
   * @param $!{tableInfo.name} $!{tableInfo.comment}
   * @return $!{tableInfo.comment}
   */
     @Override
     public List<$!{tableInfo.name}> select$!{tableInfo.name}List($!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name})){
       return this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.select$!{tableInfo.name}List($tool.firstLowerCase($!{tableInfo.name}));
     }

   /**
   * 新增$!{tableInfo.comment}
   *
   * @param $!{tableInfo.name} $!{tableInfo.comment}
   * @return 结果
   */
     @Override
     public int insert$!{tableInfo.name}($!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name})){
       return this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insert$!{tableInfo.name}($tool.firstLowerCase($!{tableInfo.name}));

   }

   /**
   * 修改$!{tableInfo.comment}
   *
   * @param $!{tableInfo.name} $!{tableInfo.comment}
   * @return 影响行数
   */
     @Override
     public int update$!{tableInfo.name}($!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name})) {
       return this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.update$!{tableInfo.name}($!tool.firstLowerCase($!{tableInfo.name}));
     }

   /**
   * 通过主键删除数据
   *
   * @param $!pk.name 主键
   * @return 影响行数
   */
     @Override
     public int delete$!{tableInfo.name}ById($!pk.shortType $!pk.name){
       return this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.delete$!{tableInfo.name}ById($!pk.name);
     }
     }

entity:

* #tableComment("实体类")
  @Data
  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
}