mybatis-generator
来源:互联网 发布:cloud9 ide java 编辑:程序博客网 时间:2024/04/28 19:06
generator自动生成mybatis的xml配置
标签: generator自动生成mybatis
2016-03-07 13:58 132人阅读 评论(0)收藏举报
版权声明:本文为博主原创文章,未经博主允许不得转载。
1、首先下载好mybatis-generator-core-1.3.2.jar包。
2、编辑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:数据库的JDBC驱动的jar包地址-->
- <classPathEntry location="mysql-connector-java-5.1.25-bin.jar" />
- <context id="DB2Tables" targetRuntime="MyBatis3">
- <commentGenerator>
- <!-- 是否去除自动生成的注释 true:是 : false:否 -->
- <property name="suppressAllComments" value="true" />
- <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
- </commentGenerator>
- <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
- connectionURL="jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8"
- userId="unuser"
- password="password">
- </jdbcConnection>
- <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer
- true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal
- -->
- <javaTypeResolver >
- <property name="forceBigDecimals" value="false" />
- </javaTypeResolver>
- <!-- targetProject:自动生成代码的位置 -->
- <javaModelGenerator targetPackage="com.soft.model" targetProject="E:\downAttachdemo\src">
- <!-- enableSubPackages:是否让schema作为包的后缀 -->
- <property name="enableSubPackages" value="true" />
- <!-- 从数据库返回的值被清理前后的空格 -->
- <property name="trimStrings" value="true" />
- </javaModelGenerator>
- <sqlMapGenerator targetPackage="sqlmap" targetProject="E:\downAttachdemo\conf">
- <property name="enableSubPackages" value="false" />
- </sqlMapGenerator>
- <javaClientGenerator type="XMLMAPPER" targetPackage="com.soft.mapping" targetProject="E:\downAttachdemo\src">
- <property name="enableSubPackages" value="true" />
- </javaClientGenerator>
- <!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->
- <table tableName="%" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">
- </table>
- </context>
- </generatorConfiguration>
able其他属性:
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"
schema即为数据库名, tableName为对应的数据库表, domainObjectName是要生成的实体类,
如果想要mapper配置文件加入sql的where条件查询, 可以将enableCountByExample等设为true,
这样就会生成一个对应domainObjectName的Example类, enableCountByExample等设为false时,
就不会生成对应的Example类了.
3、配置好后就可以运行它了。(cmd到jar所在的目录)
java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite
0 0
- Mybatis generator
- Mybatis generator
- mybatis generator
- mybatis-generator
- MYBATIS Generator
- MyBatis Generator
- Mybatis-Generator
- mybatis generator
- Mybatis-Generator
- mybatis generator
- mybatis-generator
- mybatis-generator
- MyBatis Generator
- mybatis-generator
- mybatis-generator
- mybatis generator
- Mybatis Generator
- Mybatis Generator
- WDM与NDIS中的同步机制
- jQuery EasyUI详解-EasyUI下拉框combobox
- 如何获取手机的ip地址
- 使用ionic2接入百度地图
- linux静态库与共享库
- mybatis-generator
- 用java实现对数据库的增删改查
- 剑指Offer_3_二维数组中的查找
- 3月1日 日常填坑(二)
- Poj 3273 Monthly Expense(二分)
- 剑指Offer_4_替换空格
- 初谈Java集合
- XML序列化与反序列化
- HTML5五子棋游戏 画面超酷 可设置难度