MyBatis逆向工程自定义输出xml文件和实体类工具

MyBatis逆向工程自定义输出xml文件和实体类工具

下载地址:https://download.csdn.net/download/tjmxyz/12614306

1、背景:springboot+mybaits框架经常需要配置xml文件和生成实体类,用mybatis官方给出的逆向工程生成的xml映射文件和我用的mcms框架不一致,每次都需要修改。所以就需要一种一键导出实体类和xml文件的工具。

2、工具介绍:此工具为eclipse开发的,直接在eclipse导入即可。项目结构如下图所示:

其中generator源码包为mybatis官方发布的逆向工程源代码。resource文件夹为配置文件,支持MySQL和postgresql数据库,因为我用到的数据库是postgresql,所以在lib文件夹中就没有放MySQL的数据库驱动。如果需要,自行添加。

config.properties——配置数据库连接参数及逆向工程生成的包名称

generatorConfiguration.xml——配置数据库表和主键ID

GeneratorMapper——主函数

CustomPlugin——插件配置

 

3、插件配置,参考官方提供的文档,在cn.ahsrxx.erp.generator.element包中有写好的插件,用于生成指定的数据库查询语句。然后在CustomPlugin中简单配置就可以了。这里定义的都是我需要的查询语句,可以根据需求修改或者添加cn.ahsrxx.erp.generator.element包中的插件。如下图:

4、生成的实体类和xml文件在项目中的result文件夹中,记得要刷新项目。

5、生成后的xml文件预览,有问题请留言。

<?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="cn.ahsrxx.business.procure.dao.IProcureInfoDao">
  <resultMap id="resultMap" type="cn.ahsrxx.business.procure.entity.ProcureInfoEntity">
    <id column="procure_id" jdbcType="INTEGER" property="procureId" />
    <result column="procure_name" jdbcType="VARCHAR" property="procureName" />
    <result column="procure_position" jdbcType="VARCHAR" property="procurePosition" />
    <result column="procure_control_price" jdbcType="NUMERIC" property="procureControlPrice" />
    <result column="procure_date" jdbcType="DATE" property="procureDate" />
    <result column="procure_url" jdbcType="VARCHAR" property="procureUrl" />
    <result column="procure_type" jdbcType="VARCHAR" property="procureType" />
    <result column="procure_open_date" jdbcType="DATE" property="procureOpenDate" />
    <result column="procure_open_url" jdbcType="VARCHAR" property="procureOpenUrl" />
    <result column="procure_open_result" jdbcType="VARCHAR" property="procureOpenResult" />
    <result column="procure_remark" jdbcType="VARCHAR" property="procureRemark" />
  </resultMap>
  <insert id="saveEntity" keyColumn="procure_id" keyProperty="procureId" parameterType="cn.ahsrxx.business.procure.entity.ProcureInfoEntity" useGeneratedKeys="true">
    insert into procure_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="procureName != null">
        procure_name,
      </if>
      <if test="procurePosition != null">
        procure_position,
      </if>
      <if test="procureControlPrice != null">
        procure_control_price,
      </if>
      <if test="procureDate != null">
        procure_date,
      </if>
      <if test="procureUrl != null">
        procure_url,
      </if>
      <if test="procureType != null">
        procure_type,
      </if>
      <if test="procureOpenDate != null">
        procure_open_date,
      </if>
      <if test="procureOpenUrl != null">
        procure_open_url,
      </if>
      <if test="procureOpenResult != null">
        procure_open_result,
      </if>
      <if test="procureRemark != null">
        procure_remark,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="procureName != null">
        #{procureName,jdbcType=VARCHAR},
      </if>
      <if test="procurePosition != null">
        #{procurePosition,jdbcType=VARCHAR},
      </if>
      <if test="procureControlPrice != null">
        #{procureControlPrice,jdbcType=NUMERIC},
      </if>
      <if test="procureDate != null">
        #{procureDate,jdbcType=DATE},
      </if>
      <if test="procureUrl != null">
        #{procureUrl,jdbcType=VARCHAR},
      </if>
      <if test="procureType != null">
        #{procureType,jdbcType=VARCHAR},
      </if>
      <if test="procureOpenDate != null">
        #{procureOpenDate,jdbcType=DATE},
      </if>
      <if test="procureOpenUrl != null">
        #{procureOpenUrl,jdbcType=VARCHAR},
      </if>
      <if test="procureOpenResult != null">
        #{procureOpenResult,jdbcType=VARCHAR},
      </if>
      <if test="procureRemark != null">
        #{procureRemark,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateEntity" parameterType="cn.ahsrxx.business.procure.entity.ProcureInfoEntity">
    update procure_info
    <set>
      <if test="procureName != null">
        procure_name = #{procureName,jdbcType=VARCHAR},
      </if>
      <if test="procurePosition != null">
        procure_position = #{procurePosition,jdbcType=VARCHAR},
      </if>
      <if test="procureControlPrice != null">
        procure_control_price = #{procureControlPrice,jdbcType=NUMERIC},
      </if>
      <if test="procureDate != null">
        procure_date = #{procureDate,jdbcType=DATE},
      </if>
      <if test="procureUrl != null">
        procure_url = #{procureUrl,jdbcType=VARCHAR},
      </if>
      <if test="procureType != null">
        procure_type = #{procureType,jdbcType=VARCHAR},
      </if>
      <if test="procureOpenDate != null">
        procure_open_date = #{procureOpenDate,jdbcType=DATE},
      </if>
      <if test="procureOpenUrl != null">
        procure_open_url = #{procureOpenUrl,jdbcType=VARCHAR},
      </if>
      <if test="procureOpenResult != null">
        procure_open_result = #{procureOpenResult,jdbcType=VARCHAR},
      </if>
      <if test="procureRemark != null">
        procure_remark = #{procureRemark,jdbcType=VARCHAR},
      </if>
    </set>
    where procure_id = #{procureId,jdbcType=INTEGER}
  </update>
  <select id="getEntity" parameterType="java.lang.Integer" resultMap="resultMap">
    select * from procure_info
    where procure_id = #{procureId,jdbcType=INTEGER}
  </select>
  <select id="getByEntity" parameterType="cn.ahsrxx.business.procure.entity.ProcureInfoEntity" resultMap="resultMap">
    select * from procure_info
    <where>
      <if test="procureId != null">
         and procure_id = #{procureId,jdbcType=INTEGER} 
      </if>
      <if test="procureName != null">
         and procure_name = #{procureName,jdbcType=VARCHAR} 
      </if>
      <if test="procurePosition != null">
         and procure_position = #{procurePosition,jdbcType=VARCHAR} 
      </if>
      <if test="procureControlPrice != null">
         and procure_control_price = #{procureControlPrice,jdbcType=NUMERIC} 
      </if>
      <if test="procureDate != null">
         and procure_date = #{procureDate,jdbcType=DATE} 
      </if>
      <if test="procureUrl != null">
         and procure_url = #{procureUrl,jdbcType=VARCHAR} 
      </if>
      <if test="procureType != null">
         and procure_type = #{procureType,jdbcType=VARCHAR} 
      </if>
      <if test="procureOpenDate != null">
         and procure_open_date = #{procureOpenDate,jdbcType=DATE} 
      </if>
      <if test="procureOpenUrl != null">
         and procure_open_url = #{procureOpenUrl,jdbcType=VARCHAR} 
      </if>
      <if test="procureOpenResult != null">
         and procure_open_result = #{procureOpenResult,jdbcType=VARCHAR} 
      </if>
      <if test="procureRemark != null">
         and procure_remark = #{procureRemark,jdbcType=VARCHAR} 
      </if>
    </where>
     limit 1 offset 0 
  </select>
  <delete id="deleteEntity" parameterType="java.lang.Integer">
    delete from procure_info
    where procure_id = #{procureId,jdbcType=INTEGER}
  </delete>
  <delete id="delete">
    delete from procure_info
    <where>
      procure_id in 
      <foreach close=")" collection="ids" index="index" item="item" open="(" separator=",">
         #{item} 
      </foreach>
    </where>
  </delete>
  <select id="queryAll" resultMap="resultMap">
    select * from procure_info
     order by procure_id
  </select>
  <select id="query" parameterType="cn.ahsrxx.business.procure.entity.ProcureInfoEntity" resultMap="resultMap">
    select * from procure_info
    <where>
      <if test="procureId != null">
         and procure_id = #{procureId,jdbcType=INTEGER} 
      </if>
      <if test="procureName != null">
         and procure_name = #{procureName,jdbcType=VARCHAR} 
      </if>
      <if test="procurePosition != null">
         and procure_position = #{procurePosition,jdbcType=VARCHAR} 
      </if>
      <if test="procureControlPrice != null">
         and procure_control_price = #{procureControlPrice,jdbcType=NUMERIC} 
      </if>
      <if test="procureDate != null">
         and procure_date = #{procureDate,jdbcType=DATE} 
      </if>
      <if test="procureUrl != null">
         and procure_url = #{procureUrl,jdbcType=VARCHAR} 
      </if>
      <if test="procureType != null">
         and procure_type = #{procureType,jdbcType=VARCHAR} 
      </if>
      <if test="procureOpenDate != null">
         and procure_open_date = #{procureOpenDate,jdbcType=DATE} 
      </if>
      <if test="procureOpenUrl != null">
         and procure_open_url = #{procureOpenUrl,jdbcType=VARCHAR} 
      </if>
      <if test="procureOpenResult != null">
         and procure_open_result = #{procureOpenResult,jdbcType=VARCHAR} 
      </if>
      <if test="procureRemark != null">
         and procure_remark = #{procureRemark,jdbcType=VARCHAR} 
      </if>
    </where>
     order by procure_id
  </select>
</mapper>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值