1 Star 0 Fork 0

米酒/mybatis生成工具的改进

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
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

空文件

简介

在mybatis-generator-core基础上作了一些改进,更符合自己的实际需求。 展开 收起
Java 等 2 种语言
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/gbinb/mybatis-generator.git
git@gitee.com:gbinb/mybatis-generator.git
gbinb
mybatis-generator
mybatis生成工具的改进
master

搜索帮助

Cb406eda 1850385 E526c682 1850385