使用MyBatis-Generator自动创建代码(参考+修改)
来源:互联网 发布:龙誉移动大数据平台 编辑:程序博客网 时间:2024/05/29 16:50
刚开始接触Mybatis,有需要将一些学习过程记录下来,这篇文章参考了别人的文章,同时加上自己的注解和笔记,以方便日后自己回头参考和学习。
首先下载mybatis的jar包,目前我用最新版本包括mybatis-3.4.1.jar,mybatis-generator-core-1.3.3.jar,以及数据库驱动jar包:mysql-connector-java-5.1.38-bin.jar,将这三个jar包放到同一文件夹下(如E:\mybatis-generator-core-1.3.3\lib),目录结构如下:
在该文件夹下再新建文件夹命名为src,同时新建generatorConfig.xml文件,用记事本或UE打开写下如下代码:
<?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="mysql-connector-java-5.1.38-bin.jar"/> <context id="user_t" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressDate" value="true"/> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name="suppressAllComments" value="true"/> </commentGenerator> <!--数据库链接URL,用户名、密码 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/mybatis" userId="root" password="123456"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!-- 生成模型的包名和位置--> <javaModelGenerator targetPackage="com.vincentpp.pojo" targetProject="src"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- 生成映射文件的包名和位置--> <sqlMapGenerator targetPackage="com.vincentpp.mapping" targetProject="src"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- 生成DAO的包名和位置--> <javaClientGenerator type="XMLMAPPER" targetPackage="com.vincentpp.dao" targetProject="src"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名--> <table tableName="user_t" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> </context> </generatorConfiguration>
以上代码如数据库驱动jar包版本、链接的数据库名字、用户名、密码,及生成dao、映射文件的包名和位置等部分,需针对自己情况作出相应修改。文件保存时记得要保存为utf-8无bom,否则后面命令运行符解析xml文件会出错。
完成以上步骤后,运行cmd,输入cd命令进入E:\mybatis-generator-core-1.3.3\lib路径,再执行以下命令:java-jar mybatis-generator-core-1.3.3.jar-configfile generatorConfig.xml -overwrite
再回头打开src目录,就可以得到对应的包和代码文件(实体类、接口以及配置文件),再将这些文件复制到对应的web项目就可以了。
0 0
- 使用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自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 统计学习方法第4,5章笔记
- Android ImageView的scaleType属性解释
- 关于bootstrap中tab的使用
- nyoj 97 兄弟旅游问题
- GridView ScrollView ViewPager
- 使用MyBatis-Generator自动创建代码(参考+修改)
- 实验八:VLAN的配置和单臂路由
- Visual Studio 2012 - Visual C++ MFC 类
- linux查看网卡速度和模式调整
- Oracle基本的SQL语句
- playframework1.2.x博客教程(一)-创建项目
- SDUT2140图结构练习——判断给定图是否存在合法拓扑序列
- 程序人生之一:一个四年 JAVA 程序员的工作经历
- iOS 蓝牙打印