首页 技术 正文
技术 2022年11月22日
0 收藏 383 点赞 2,604 浏览 1973 个字

由于Mybatis是一种半自动的ORM框架,它的工作主要是配置mapping映射文件,为了减少手动书写映射文件,可以利用mybatis生成器,自动生成实体类、dao接口以及它的映射文件,然后直接拷贝到工程中稍微修改就可以直接使用了。

生成器目录如下:

Mybatis自动生成实体类、dao接口和mapping映射文件

首先进入lib文件夹中,该目录如下:

Mybatis自动生成实体类、dao接口和mapping映射文件

(图上文件下载地址:http://download.csdn.net/detail/qiwei31229/9790909

主要修改generatorConfig.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="mysql-connector-java-5.1.25-bin.jar"/>
<context id="DB2Tables" 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://127.0.0.1/test" userId="root" password="123456">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
   <!-- 生成模型的包名和位置-->    
<javaModelGenerator targetPackage="com.shaw.cn.domain" targetProject="src">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
  <!-- 生成映射文件的包名和位置-->    
<sqlMapGenerator targetPackage="com.shaw.cn.mapping" targetProject="src">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
     <!-- 生成DAO的包名和位置-->    
<javaClientGenerator type="XMLMAPPER" targetPackage="com.shaw.cn.IDao" 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>

注意表要现在具体的数据库里头创建好,然后在lib文件夹中shift+鼠标右键打开控制台命令输入:

Mybatis自动生成实体类、dao接口和mapping映射文件

Java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite

这样就可以在src看到制定的目录的代码了。

Mybatis自动生成实体类、dao接口和mapping映射文件

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,029
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,367
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,147
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,859