Ibatis自动生成dao sqlmapper文件和domain文件过程
2024-10-01 11:42:47
generator自动生成mybatis的xml配置、model、map等信息:
1、下载mybatis-generator-core-1.3.2.jar包。
网址:http://code.google.com/p/mybatis/downloads/list?can=3&q=Product%3DGenerator,下载mybatis-generator-core-1.3.2-bundle.zip,解压
找到lib下的需要jar包。
2、新建工程项目
3、编写genertor的xml文件,名下:generator.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="D:\apache-tomcat-7.0.52\webapps\traceSys\WEB-INF\lib\mysql-connector-java-5.1.29.jar" />
<context id="context1">
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/trace_sys" userId="root" password="" />
<javaModelGenerator targetPackage="com.trace.domain"
targetProject="D:\cpn-work\traceSys\src\main\java" />
<sqlMapGenerator targetPackage="com.trace.dao" targetProject="D:\cpn-work\traceSys\src\main\java"></sqlMapGenerator>
<javaClientGenerator targetPackage="com.trace.dao"
targetProject="D:\cpn-work\traceSys\src\main\java" type="XMLMAPPER" />
<table tableName="company" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="goods" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="goods_discuss" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="goods_production" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="goods_profile" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="goods_record" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="type" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
</context>
</generatorConfiguration>
table其他属性:
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"
schema即为数据库名, tableName为对应的数据库表, domainObjectName是要生成的实体类,
如果想要mapper配置文件加入sql的where条件查询, 可以将enableCountByExample等设为true,
这样就会生成一个对应domainObjectName的Example类, enableCountByExample等设为false时,
就不会生成对应的Example类了.
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"
schema即为数据库名, tableName为对应的数据库表, domainObjectName是要生成的实体类,
如果想要mapper配置文件加入sql的where条件查询, 可以将enableCountByExample等设为true,
这样就会生成一个对应domainObjectName的Example类, enableCountByExample等设为false时,
就不会生成对应的Example类了.
4、命令行方式生成
java -jar E:\Websoft\mybaits\mybatis-generator-core-1.3.2\lib\mybatis-generator-core-1.3.2.jar -configfile E:\WebWorkSpace\workspace_js\downAttachdemo\src\com\mochasoft\down\generator.xml -overwrite
成功时输出:MyBatis Generator finished successfully.
最新文章
- Python 之 装饰器的写法
- 使用yum安装应用程序时候,报错:[Errno 14] PYCURL ERROR 7 - ";Failed to connect to 2001:da8:8000:6023::230: 网络不可达";
- Hibernate检索策略之延迟加载和立即加载
- java中getBytes方法可能使图片文件产生的问题
- 浅谈HTTP响应拆分攻击
- [DP] LCS小结
- iOS UIKit:animation
- VSFTP被动模式
- 使用Xshell生成key,避免password登录linux
- Linux内核和根文件系统引导加载程序
- AngularJS最理想开发工具WebStorm
- MyEclipse 10 报错记录
- 前端(各种demo)一:css实现三角形,css实现梯形,pop弹层,css伪类before,after使用,svg使用(持续更新中)
- 王之泰《面向对象程序设计(java)》课程学习总结
- angularJS 路由加载js controller 未定义 解决方案
- 2018-7-17-随笔-params和ref、out用法、事件访问器
- 个人对vuex的表象理解(笔记)
- HanLP分词命名实体提取详解
- Delphi Language Overview
- Servlet的复习