mybatis自动生成mapper.xml的方法

1. 首先添加maven插件

            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <configurationFile>src/test/resources/config/generatorConfig.xml</configurationFile>  //这是与数据库的配置地址
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>

2.其次填写与数据库连接配置文件<?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="/Users/seabook.liu/.m2/repository/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar" />  
  <context id="context1" >
    <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/test" userId="root" password="" />(数据库连接)
    <javaModelGenerator targetPackage="com.dianping.poi.updateflow.biz.model" targetProject="src/main/java">
        <property name="enableSubPackages" value="true" />
    </javaModelGenerator>
    <sqlMapGenerator targetPackage="config.sqlmap.updateflow"  targetProject="src/main/resources" >(生成的mapper文件)
        <property name="enableSubPackages" value="true" />
    </sqlMapGenerator>
    <javaClientGenerator targetPackage="com.dianping.poi.updateflow.biz.dao" targetProject="src/main/java" type="XMLMAPPER" >(生成的dao层接口)
        <property name="enableSubPackages" value="true" />
    </javaClientGenerator>
    <table schema="" tableName="POI_Shop"(数据库表名) domainObjectName="PoiShop"(生产的实体对象)
        enableCountByExample="true"
        enableUpdateByExample="true"  
        enableDeleteByExample="true"
        enableSelectByExample="true"
        selectByExampleQueryId="true"
        
        >
    </table>
  </context>
</generatorConfiguration>


3.利用maven命令自动生成

mybatis-generator:generate


4.最后能生成如下文件

只是实例一个

<?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.dianping.poi.updateflow.biz.dao.ProcInfoDao" >
  <resultMap id="BaseResultMap" type="com.dianping.poi.updateflow.biz.model.ProcInfo" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Jul 28 16:24:30 CST 2015.
    -->
    <id column="proc_id" property="procId" jdbcType="INTEGER" />
    <result column="flow_id" property="flowId" jdbcType="INTEGER" />
    <result column="entry_id" property="entryId" jdbcType="INTEGER" />
    <result column="proc_type" property="procType" jdbcType="VARCHAR" />
    <result column="proc_status" property="procStatus" jdbcType="TINYINT" />
    <result column="editer_id" property="editerId" jdbcType="VARCHAR" />
    <result column="result" property="result" jdbcType="VARCHAR" />
    <result column="explain" property="explain" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time&#

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值