您的位置:首页 > 其它

自动生成mybatis映射文件的方法

2014-09-03 14:18 501 查看
1,下载mybatis-generator-core-1.3.2.jar包

2,在当前界面打开cmd窗口

3,生成语句:java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite

4,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:数据库的JDBC驱动的jar包地址-->
<classPathEntry location="F:\API\jar包\mysql\mysql-connector-java-5.1.7-bin.jar" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/ndy"
userId="root"
password="123456">
</jdbcConnection>
<!--  默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer
true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal
-->
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- targetProject:自动生成代码的位置 -->
<!--生成的模型的包名和位置-->
<javaModelGenerator targetPackage="ndy.model" targetProject="G:\test_mybatis\src">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="true" />
<!-- 从数据库返回的值被清理前后的空格  -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!--生成的映射文件的包名和位置-->
<sqlMapGenerator targetPackage="ndy.mapping"  targetProject="G:\test_mybatis\src">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!--生成DAO的包名和位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="ndy.dao"  targetProject="G:\test_mybatis\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->
<table tableName="trole" domainObjectName="Role" enableCountByExample="false" enableDeleteByExample="false"       enableSelectByExample="false" enableUpdateByExample="false"></table>
<table tableName="tuser" domainObjectName="User" enableCountByExample="false" enableDeleteByExample="false"       enableSelectByExample="false" enableUpdateByExample="false"></table>
<table tableName="tuser_trole" domainObjectName="UserRole" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"></table>

</context>

</generatorConfiguration>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: