idea——生成mybatis-xml文件

idea自动生成mybatis文件

1、在pom.xml中添加org.mybatis.generator插件

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <version>1.3.2</version>

        </plugin>
    </plugins>
</build>

这里写图片描述
2、添加generator运行选项

这里写图片描述

在Command line中添加如下代码

mybatis-generator:generate -e

3、在resources下建立generatorConfig.xml 内容如下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration>
    <!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包-->
    <classPathEntry  location="D:\a_javaConfiig\maven\Maven_Repository\mysql\mysql-connector-java\5.1.29\mysql-connector-java-5.1.29.jar"/>
    <context id="DB2Tables"  targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!--数据库链接URL,用户名、密码 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/jazkwl?useUnicode=true"
                        userId="root" password="root">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!-- 生成模型的包名和位置-->
        <javaModelGenerator targetPackage="com.zzbeilei.dsly.pojo" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!-- 生成映射文件的包名和位置-->
        <sqlMapGenerator targetPackage="com.zzbeilei.dsly.dao" targetProject="src/main/resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>

        <!-- 生成DAO的包名和位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.zzbeilei.dsly.dao" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
        <table tableName="gs_aboutu" domainObjectName="GsAboutu" enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="gs_account" domainObjectName="GsAccount" enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="gs_yundlb" domainObjectName="GsYundlb" enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
    </context>
</generatorConfiguration>

4 自动生成的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="com.zzbeilei.dsly.dao.GsAccountMapper" >
  <resultMap id="BaseResultMap" type="com.zzbeilei.dsly.pojo.GsAccount" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="user_id" property="userId" jdbcType="INTEGER" />
    <result column="desc" property="desc" jdbcType="VARCHAR" />
    <result column="status" property="status" jdbcType="INTEGER" />
    <result column="chakan" property="chakan" jdbcType="INTEGER" />
    <result column="add_time" property="addTime" jdbcType="VARCHAR" />
    <result column="add_id" property="addId" jdbcType="INTEGER" />
    <result column="yund_id" property="yundId" jdbcType="INTEGER" />
    <result column="xing" property="xing" jdbcType="INTEGER" />
    <result column="tit" property="tit" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, user_id, desc, status, chakan, add_time, add_id, yund_id, xing, tit
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from gs_account
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from gs_account
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.zzbeilei.dsly.pojo.GsAccount" >
    insert into gs_account (id, user_id, desc, 
      status, chakan, add_time, 
      add_id, yund_id, xing, 
      tit)
    values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{desc,jdbcType=VARCHAR}, 
      #{status,jdbcType=INTEGER}, #{chakan,jdbcType=INTEGER}, #{addTime,jdbcType=VARCHAR}, 
      #{addId,jdbcType=INTEGER}, #{yundId,jdbcType=INTEGER}, #{xing,jdbcType=INTEGER}, 
      #{tit,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.zzbeilei.dsly.pojo.GsAccount" >
    insert into gs_account
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="userId != null" >
        user_id,
      </if>
      <if test="desc != null" >
        desc,
      </if>
      <if test="status != null" >
        status,
      </if>
      <if test="chakan != null" >
        chakan,
      </if>
      <if test="addTime != null" >
        add_time,
      </if>
      <if test="addId != null" >
        add_id,
      </if>
      <if test="yundId != null" >
        yund_id,
      </if>
      <if test="xing != null" >
        xing,
      </if>
      <if test="tit != null" >
        tit,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="userId != null" >
        #{userId,jdbcType=INTEGER},
      </if>
      <if test="desc != null" >
        #{desc,jdbcType=VARCHAR},
      </if>
      <if test="status != null" >
        #{status,jdbcType=INTEGER},
      </if>
      <if test="chakan != null" >
        #{chakan,jdbcType=INTEGER},
      </if>
      <if test="addTime != null" >
        #{addTime,jdbcType=VARCHAR},
      </if>
      <if test="addId != null" >
        #{addId,jdbcType=INTEGER},
      </if>
      <if test="yundId != null" >
        #{yundId,jdbcType=INTEGER},
      </if>
      <if test="xing != null" >
        #{xing,jdbcType=INTEGER},
      </if>
      <if test="tit != null" >
        #{tit,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.zzbeilei.dsly.pojo.GsAccount" >
    update gs_account
    <set >
      <if test="userId != null" >
        user_id = #{userId,jdbcType=INTEGER},
      </if>
      <if test="desc != null" >
        desc = #{desc,jdbcType=VARCHAR},
      </if>
      <if test="status != null" >
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="chakan != null" >
        chakan = #{chakan,jdbcType=INTEGER},
      </if>
      <if test="addTime != null" >
        add_time = #{addTime,jdbcType=VARCHAR},
      </if>
      <if test="addId != null" >
        add_id = #{addId,jdbcType=INTEGER},
      </if>
      <if test="yundId != null" >
        yund_id = #{yundId,jdbcType=INTEGER},
      </if>
      <if test="xing != null" >
        xing = #{xing,jdbcType=INTEGER},
      </if>
      <if test="tit != null" >
        tit = #{tit,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.zzbeilei.dsly.pojo.GsAccount" >
    update gs_account
    set user_id = #{userId,jdbcType=INTEGER},
      desc = #{desc,jdbcType=VARCHAR},
      status = #{status,jdbcType=INTEGER},
      chakan = #{chakan,jdbcType=INTEGER},
      add_time = #{addTime,jdbcType=VARCHAR},
      add_id = #{addId,jdbcType=INTEGER},
      yund_id = #{yundId,jdbcType=INTEGER},
      xing = #{xing,jdbcType=INTEGER},
      tit = #{tit,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>
posted @   渝思  阅读(4769)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示