Myeclipse 10 使用mybatis-generator自动创建代码总结,附源码
来源:互联网 发布:足球首发阵容软件 编辑:程序博客网 时间:2024/06/08 09:49
最近在搭建公司系统框架,使用是ssm。mybatis虽然用着不错,但是要写大量的对象映射文件。这种体力活就没有必要花太多时间去做了,直接用mybatis-generator这个神器来快速生成,跟Hibernate快速生成映射一样。查了些mybatis-generator相关资料,不得不吐槽下国内的技术博客,简直就是各种抄啊,随便点开几个开一眼几乎一模一样的内容。看着简直要吐血,还是去墙外面看看,我已经下载了,等下就共享给大家,网址什么的就不贴了。mybatis-generator的使用方法常用的有两种,一种是直接在cmd命令行下面运行,运行完后把生成的文件再拷贝到项目对应的位置,我感觉这个太麻烦了,而且不便于修改,做成插件直接生成映射和实体类到项目里。插件集成方法:
参考附件文档,解压出来的两个文件夹和两个文件,拷贝到Myeclipse的安装路径下,不要放到common下了,可以参考一下我的路径 拷贝完成后重启下Myeclipse,
在项目里新建一个generatorConfig.xml文件,在xml文件上右键,看着这个没有
先不要着急点,你要修改下你这个xml里的内容
<!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:\caixudongSoft\store\WebRoot\WEB-INF\lib\mysql-connector-java-5.1.21.jar" /><context id="store" targetRuntime="MyBatis3"><commentGenerator><!-- 是否去除自动生成的注释 true:是 : false:否 --><property name="suppressAllComments" value="true" /><!-- 是否去除所有自动生成的文件的时间戳,默认为false --><!-- <property name="suppressDate" value="false"/> --></commentGenerator><!--数据库连接的信息:驱动类、连接地址、用户名、密码 --><jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://192.168.2.16:3306/cxd" userId="root" password="root"></jdbcConnection><javaModelGenerator targetPackage="com.cxd.model" targetProject="cxd\src"><!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> <!-- 从数据库返回的值被清理前后的空格 --> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 配置生成相应的实体Mapper.xml,对于Mapper3.X我们需要把type="XMLMAPPER" --> <sqlMapGenerator targetPackage="com.cxd.mapping" targetProject="cxd\src"><property name="enableSubPackages" value="false" /></sqlMapGenerator><!-- 配置生成相应的接口类,对应与Mapper.xml中的一系列CRUD方法SQL语句 --> <javaClientGenerator targetPackage="com.cxd.dao" targetProject="cxd\src" type="XMLMAPPER"> <property name="enableSubPackages" value="false" /> </javaClientGenerator><!-- 用户表 --><table schema="stone" tableName="user" domainObjectName="User" enableCountByExample="false"enableUpdateByExample="false"enableDeleteByExample="false"enableSelectByExample="false"selectByExampleQueryId="false" > </table> </context></generatorConfiguration>里面需要配置的地方我都写上了注释,如果需要批量生成,把最后那个table复制N个,里面依葫芦画瓢即可,填写好后,在文件上右键刚刚用红色标示出来的选项,再刷新下你的项目看看,可以看到所有的映射已经全部完成。
附件下载地址:http://download.csdn.net/detail/localhost_8080/8532889
0 0
- Myeclipse 10 使用mybatis-generator自动创建代码总结,附源码
- Myeclipse中Mybatis Generator自动创建代码总结
- Myeclipse中Mybatis Generator自动创建代码总结
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用mybatis generator自动创建代码
- [SSM]使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- Hduoj1712【分组背包】
- 数学之路-SPSS备忘(2)
- 锐谷科技智能交通城市无线智能停车诱导系统
- leetcode第2题-Add Two Numbers
- 黑马程序员--单例设计模式、抽象、继承
- Myeclipse 10 使用mybatis-generator自动创建代码总结,附源码
- cocos2dx 学习(-)内存管理机制
- HUD(3790)——最短路径问题
- 简单动态规划两题(思想一样)
- HDOJ 4500 小Q系列故事——屌丝的逆袭
- [Android Studio]AS的常用配置
- 数据库操作sql语句总结
- iOS 真机调试 Xcode 提示 Could not inspect the application package
- USACO Milking Cows