您的位置:首页 > 编程语言 > Java开发

Java MyBatis自动生成映射文件

2017-06-29 16:36 405 查看
参考:http://blog.csdn.net/tolcf/article/details/50835165 文章中提供了jar包下载地址

generatorConfig.xml 如下,mybatis自动化工具会根据该文件来查找数据源,生成对应的VO对象,mapper文件,example对象

<?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:\generator\mysql-connector-java-5.1.34.jar" />
<!-- <classPathEntry location="C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar" />-->
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="true" /> <!--生成注释-->
<property name="suppressDate" value="true" /> <!--生成注释包含时间戳-->
</commentGenerator>
<!-- 数据库链接URL、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/vpush_dev?characterEncoding=utf8" userId="yq" password="123456">
<!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa">-->
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="yq.model" targetProject="D:\generator\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成的映射文件包名和位置 -->
<sqlMapGenerator targetPackage="yq.mapping" targetProject="D:\generator\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="yq.dao" targetProject="D:\generator\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
<table schema="test" tableName="device">
<generatedKey column="ID" sqlStatement="Mysql" identity="true"/>
</table>
<table schema="test" tableName="device_push">
<generatedKey column="ID" sqlStatement="Mysql" identity="true"/>
</table>
<table schema="test" tableName="model_info">
<generatedKey column="ID" sqlStatement="Mysql" identity="true"/>
</table>
<table schema="test" tableName="os_version">
<generatedKey column="ID" sqlStatement="Mysql" identity="true"/>
</table>
<table schema="test" tableName="push_task">
<generatedKey column="ID" sqlStatement="Mysql" identity="true"/>
</table>
<table schema="test" tableName="test_process">
<generatedKey column="ID" sqlStatement="Mysql" identity="true"/>
</table>
<table schema="test" tableName="test_tool">
<generatedKey column="ID" sqlStatement="Mysql" identity="true"/>
</table>
<table schema="test" tableName="tool_version">
<generatedKey column="ID" sqlStatement="Mysql" identity="true"/>
</table>
<table schema="test" tableName="dic_config">
<generatedKey column="ID" sqlStatement="Mysql" identity="true"/>
</table>
<table schema="test" tableName="server_node">
<generatedKey column="ID" sqlStatement="Mysql" identity="true"/>
</table>
<table schema="test" tableName="test_item">
<generatedKey column="ID" sqlStatement="Mysql" identity="true"/>
</table>
<table schema="test" tableName="test_report">
<generatedKey column="ID" sqlStatement="Mysql" identity="true"/>
</table>
<table schema="test" tableName="user_info">
<generatedKey column="ID" sqlStatement="Mysql" identity="true"/>
</table>
</context>
</generatorConfiguration>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java mybatis