1 Star 0 Fork 0

米酒 / mybatis生成工具的改进

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README

mybatis生成器的改进

介绍

在mybatis-generator-core基础上作了改进,更符合自己的实际需求

增加了对Lombok插件的支持

取消了生成的实体类中属性的get/set方法,增加了Lombok插件的@Data注解;

<!-- 增加对Lombok插件的支持   -->
<plugin type="org.mybatis.generator.plugins.LombokPlugin">
</plugin>

对tables标签进行了扩展,可根据查询字段生成查询条件,同时生成查询实体form和select相关的statement;

<table tableName="tb_user" domainObjectName="User" enableInsertSelective="false" enableUpdateByPrimaryKey="false">
    <!-- 增加对查询条件的支持  -->
    <conditionColumn columns="username,name,age"/>
</table>

Mapper.xml文件中生成where条件的statement

<sql id="queryConditions">
    <where>
      <if test="username != null and username != ''">
        and username = #{username,jdbcType=VARCHAR}
      </if>
      <if test="name != null and name != ''">
        and name = #{name,jdbcType=VARCHAR}
      </if>
      <if test="age != null ">
        and age = #{age,jdbcType=INTEGER}
      </if>
    </where>
  </sql>

生成的2组查询片段

<select id="selectListByForm" parameterType="cn.fetosoft.test.form.UserForm" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from tb_user
    <include refid="queryConditions"></include>
    <!-- 此处增加的是对分页的支持,可根据需要自行处理   -->
    <include refid="base.orderAndPage"></include>
  </select>

  <select id="selectCountByForm" parameterType="cn.fetosoft.test.form.UserForm" resultType="java.lang.Integer">
    select count(id) as c
    from tb_user
    <include refid="queryConditions"></include>
  </select>

生成form查询实体

<!-- 配置生成查询类Form   -->
<javaFormGenerator targetPackage="cn.fetosoft.test.form"
         targetProject="D:/git/mybatis-generator/src/main/java" />

对生成的mapper.xml文件进行了精简,只保留了基础的查增改删的操作

selectByPrimaryKey
selectListByForm
selectCountByForm
deleteByPrimaryKey
insert
updateByPrimaryKeySelective

Empty file

About

在mybatis-generator-core基础上作了一些改进,更符合自己的实际需求。 expand collapse
Java and 2 more languages
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/gbinb/mybatis-generator.git
git@gitee.com:gbinb/mybatis-generator.git
gbinb
mybatis-generator
mybatis生成工具的改进
master

Search

344bd9b3 5694891 D2dac590 5694891