【提供源码下载】使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件

来源:互联网 发布:淘宝国际网店 编辑:程序博客网 时间:2024/05/22 11:37

其实这个没什么,但是能大大加快我们的开发速度。

只需要把一个配置文件配置好就行,

<?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包地址 --><classPathEntrylocation="E:\work\workspace\2016\MybatisGenerator\mybatis\lib\mysql-connector-java-5.1.18.jar" /><context id="DB2Tables" targetRuntime="MyBatis3"><!-- 生成的Java文件的编码 -->    <property name="javaFileEncoding" value="UTF-8"/>     <!-- 格式化java代码 -->    <property name="javaFormatter" value="org.mybatis.generator.api.dom.DefaultJavaFormatter"/>    <!-- 格式化XML代码 -->    <property name="xmlFormatter" value="org.mybatis.generator.api.dom.DefaultXmlFormatter"/>    <commentGenerator><!-- 是否去除自动生成的注释 true:是 : false:否 --><property name="suppressAllComments" value="true" /><!--数据库连接的信息:驱动类、连接地址、用户名、密码 --></commentGenerator><jdbcConnection driverClass="com.mysql.jdbc.Driver"connectionURL="jdbc:mysql://114.242.9.32:3311/robo620" userId="root"password="root"></jdbcConnection><!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal --><javaTypeResolver><!--             true:使用BigDecimal对应DECIMAL和 NUMERIC数据类型            false:默认,                scale>0;length>18:使用BigDecimal;                scale=0;length[10,18]:使用Long;                scale=0;length[5,9]:使用Integer;                scale=0;length<5:使用Short;         --><property name="forceBigDecimals" value="false" /></javaTypeResolver><!-- java模型创建器,是必须要的元素           负责:1,key类(见context的defaultModelType);2,java类;3,查询类         targetPackage:生成的类要放的包,真实的包受enableSubPackages属性控制;         targetProject:目标项目,指定一个存在的目录下,生成的内容会放到指定目录中,如果目录不存在,MBG不会自动建目录        --><javaModelGenerator targetPackage="com.mybatisgenerator.model"targetProject="src"> <!--for MyBatis3/MyBatis3Simple            自动为每一个生成的类创建一个构造方法,构造方法包含了所有的field;而不是使用setter;        -->        <property name="constructorBased" value="false"/> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="true" /> <!-- 从数据库返回的值被清理前后的空格 --> <property name="trimStrings" value="true" /></javaModelGenerator><sqlMapGenerator targetPackage="com.mybatisgenerator.mapper"targetProject="src"><property name="enableSubPackages" value="false" /></sqlMapGenerator><javaClientGenerator type="XMLMAPPER"targetPackage="com.mybatisgenerator.mapper" targetProject="src"><property name="enableSubPackages" value="false" /></javaClientGenerator><!-- schema:即为数据库名;tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 //忽略字段<ignoreColumn column="FRED" /> --><table schema="robo620" tableName="t_account" domainObjectName="User"enableCountByExample="true" enableUpdateByExample="false"enableDeleteByExample="false" enableSelectByExample="false"selectByExampleQueryId="false"></table></context></generatorConfiguration>

不会的可以下载我的源码。直接运行

http://download.csdn.net/detail/xiangtianzaijie500/9581751

0 0