一双跑鞋的mybatis(六)---使用generator自动生成mybatis映射代码
2014-05-13 11:07
363 查看
首先下载对应的genrator包和所需的包:https://code.google.com/p/mybatis/downloads/list?can=1&q=Product%3DGenerator
然后将数据库驱动和mybatis等包放到同一目录下如下图:
然后创建generator的配置文件(GeneratorConfig.xml)如下:
最后打开控制台命令cd到刚才目录下输入:
java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite
来运行generator使之生成对应的映射文件和代码
快打开src目录看看吧,对应的映射文件和dao都生成了
然后将数据库驱动和mybatis等包放到同一目录下如下图:
然后创建generator的配置文件(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="mysql-connector-java-3.1.13-bin.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://127.0.0.1:3306/senssic" userId="root" password="qiyu0126"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!-- 生成模型的包名和位置--> <javaModelGenerator targetPackage="org.senssic.domain" targetProject="src"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- 生成映射文件的包名和位置--> <sqlMapGenerator targetPackage="org.senssic.mapping" targetProject="src"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- 生成DAO的包名和位置--> <javaClientGenerator type="XMLMAPPER" targetPackage="org.senssic.IDao" targetProject="src"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!-- 要生成的表有多少要映射多少, tableName是数据库中的表名或视图名 domainObjectName是实体类名--> <table tableName="person" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> <table tableName="address" domainObjectName="Address" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> </context> </generatorConfiguration>
最后打开控制台命令cd到刚才目录下输入:
java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite
来运行generator使之生成对应的映射文件和代码
快打开src目录看看吧,对应的映射文件和dao都生成了
相关文章推荐
- mybatis-generator自动生成代码插件使用详解
- IDEA使用mybatisgenerator自动生成代码
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- Mybatis代码自动生成-mybatis-generator的使用
- eclipse使用mybatis generator自动生成代码报错Generation Warnings Occured Project E: does
- eclipse中 使用mybatis generator自动生成代码 错误
- 使用MyBatisGenerator自动生成Mybatis的相关代码
- 使用MyBatis-Generator自动生成映射文件
- Intellij IDEA 中使用 MyBatis-generator 自动生成 MyBatis 代码
- 使用MyBatis-generator 自动生成MyBatis mapper代码
- Mybatis Generator Configuration Eclipse自动生成代码工具使用及实现基本crud
- Mybatis使用generator自动生成映射配置文件信息
- [置顶] SpringBoot 使用Mybatis-Generator自动生成代码
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- Mybatis使用generator自动生成映射配置文件信息
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- 使用Eclipse的Generator MyBatis/iBatis Artifacts插件自动生成代码,与spring集成
- Intellij IDEA中使用Mybatis-generator自动生成Mtbatis代码
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- maven项目使用mybatis-generator自动生成代码