自动生成 mybatis代码,特别是sqlmap文件,可以有效的减少dao等代码的重复劳动。
eclipse中添加插件: mybatis Generator - http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite/
添加生成代码的配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE ibatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Apache iBATIS Ibator Configuration 1.0//EN" "http://ibatis.apache.org/dtd/ibator-config_1_0.dtd" >
<ibatorConfiguration>
<classPathEntry
location="/home/xxx/xxx.war/WEB-INF/lib/mysql-connector-java-5.1.6.jar" />
<ibatorContext id="DB2Tables" targetRuntime="Ibatis2Java5">
<!-- 去除自动生成的注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
<!-- 是否生成注释代时间戳
<property name="suppressDate" value="true" />
-->
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost/test" userId="test"
password="123456">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<javaModelGenerator targetPackage="test.model"
targetProject="Test-web">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="test.dao"
targetProject="Test-web">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO的类文件以及配置文件 -->
<daoGenerator targetPackage="test.dao" targetProject="Test-web"
type="GENERIC-CI" />
<!-- 避免生成一大堆Example方法,代码看去清晰一些 -->
<table tableName="user" domainObjectName="User"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
<!-- 去除一列,这样 PASSWORD这列就不会生成
<ignoreColumn column="PASSWORD"/>
-->
<!-- columnOverride 将数据库字段对应成javabean里面的字段 -->
<columnOverride column="USERID" property="userid" />
<columnOverride column="USERNAME" property="username" />
<columnOverride column="PASSWORD" property="password" />
</table>
</ibatorContext>
</ibatorConfiguration>
在文件上点击鼠标右键,可以看到插件生成的选项,选择即可生成代码
daoGenerator 标签的类型,见如下链接.
http://ibatis.apache.org/docs/tools/abator/configreference/daoGenerator.html
IBATIS The generated DAO objects will conform to the iBATIS DAO framework.
GENERIC-CI The generated DAO objects will rely only on the SqlMapClient. The SqlMapClient will be supplied by constructor dependency injection.
GENERIC-SI The generated DAO objects will rely only on the SqlMapClient. The SqlMapClient will be supplied by setter dependency injection.
SPRING The generated DAO objects will conform to the Spring DAO framework.
分享到:
相关推荐
mybatis代码生成插件,配置下就可以生成任意表的mybatis配置了
MyBatis代码生成工具,内含mybatis-generator-core-1.4.0-SNAPSHOT.jar,mysql-connector-java-5.1.47.jar
可自动生成代码 oracle mysql都可以使用 告别重复劳动,提高代码效率。
Mybatis MySql 代码生成工具,内有jar包,配置说明。自动生成 model xml 。
mybatis代码生成器,可以在项目外生成对应的model类,方便
Mybatis 代码生成工具,非常强大,值得推荐
Mybatis代码生成器生成通用mybatis的增删改查,简单易用!本项目为springboot web项目,页面配置参数一键生成,分两个子项目,满足不同项目实际情况和个人喜好,其中:code-generator1为通用mybatis配置生成最基础的...
实用mybatis代码生成器Demo, Maven Plugin 生成 和java程序生成两种方式
mybatis代码生成器,Java实体类xml 文件生成器,MySQL数据库字段映射工具
界面版MyBatis代码生成器,运行要求安装jdk1.8,自动生成entity、dao、service、serviceImpl、Mapper、Assist等。包含工具、文档、源码。
好用mybatis代码生成器,配置xml的信息,点run.bat运行
mybatis 代码生成工具 ,可以自动生成 dao service domain control
基于mybatis generator开发一款界面工具, 本工具可以使你非常容易及快速生成Mybatis的Java POJO文件及数据库Mapping文件。
mybatis 逆向工程,下载即运行,易看易懂,同时支持oracle,sql server ,mysql 等数据库
mybatis 代码生成器 扩展版本,可以自动生成分页查询