generator自动生成mybatis的xml配置、model、map等信息: 

1、下载mybatis-generator-core-1.3.2.jar包。 

       网址:​​http://code.google.com/p/mybatis/downloads/list?can=3&q=Product%3DGenerator​​,下载mybatis-generator-core-1.3.2-bundle.zip,解压 

       找到lib下的需要jar包。 2、新建工程项目

Ibatis自动生成dao sqlmapper文件和domain文件过程_mysql 

3、编写genertor的xml文件,名下:generator.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:\apache-tomcat-7.0.52\webapps\traceSys\WEB-INF\lib\mysql-connector-java-5.1.29.jar" />
<context id="context1">
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/trace_sys" userId="root" password="" />
<javaModelGenerator targetPackage="com.trace.domain"
targetProject="D:\cpn-work\traceSys\src\main\java" />
<sqlMapGenerator targetPackage="com.trace.dao" targetProject="D:\cpn-work\traceSys\src\main\java"></sqlMapGenerator>
<javaClientGenerator targetPackage="com.trace.dao"
targetProject="D:\cpn-work\traceSys\src\main\java" type="XMLMAPPER" />
<table tableName="company" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="goods" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="goods_discuss" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="goods_production" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="goods_profile" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="goods_record" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="type" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
</context>
</generatorConfiguration>

table其他属性: 

enableCountByExample="false" 

enableUpdateByExample="false" 

enableDeleteByExample="false" 

enableSelectByExample="false" 

selectByExampleQueryId="false" 

schema即为数据库名, tableName为对应的数据库表, domainObjectName是要生成的实体类, 

如果想要mapper配置文件加入sql的where条件查询, 可以将enableCountByExample等设为true, 

这样就会生成一个对应domainObjectName的Example类, enableCountByExample等设为false时, 

就不会生成对应的Example类了. 



 4、命令行方式生成

java -jar E:\Websoft\mybaits\mybatis-generator-core-1.3.2\lib\mybatis-generator-core-1.3.2.jar -configfile E:\WebWorkSpace\workspace_js\downAttachdemo\src\com\mochasoft\down\generator.xml -overwrite

成功时输出:MyBatis Generator finished successfully. 




作者:少帅

您的支持是对博主最大的鼓励,感谢您的认真阅读。

本文版权归作者所有,欢迎转载,但请保留该声明。