使用generator自动生成Mybatis映射配置文件
在使用mybatis时,映射文件的配置非常麻烦,对于做逻辑不是很复杂,功能不是特别关键的模块的时候,我们没有必要手动书写,可以使用generator工具生成。
generator工具实际上就是根据数据库建好的数据结构,通过自定义的类名,生成对应的实体和映射文件。
下载相关的资源
资源下载地址:csdn资源下载
配置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/springdemo" userId="root" password="">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 生成模型的包名和位置-->
<javaModelGenerator targetPackage="com.aheizi.domain" targetProject="src">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- 生成映射文件的包名和位置-->
<sqlMapGenerator targetPackage="com.aheizi.mapping" targetProject="src">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 生成DAO的包名和位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.aheizi.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>
生成属于自己的配置文件,需要根据自己的数据库改动connectionURL和tableName,根据自己的工程需要的目录改动targetPackage,设置自己的domainObjectName。
生成配置文件
在此目录打开CMD(shift+鼠标右键,如果安装了Git,直接git Bash here),执行命令
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite
执行完后src目录下就已经自动生成dao,mapping,model文件内容了。
使用generator自动生成Mybatis映射配置文件的更多相关文章
- 使用Mybatis Generator自动生成Mybatis相关代码
本文将简要介绍怎样利用Mybatis Generator自动生成Mybatis的相关代码: 一.构建一个环境: 1. 首先创建一个表: CREATE TABLE pet (name VARCHAR(2 ...
- generator自动生成mybatis配置和类信息
generator自动生成mybatis的xml配置.model.map等信息: 1.下载mybatis-generator-core-1.3.2.jar包. 网址:http://cod ...
- generator自动生成mybatis的xml配置
generator自动生成mybatis的xml配置.model.map等信息:1.下载mybatis-generator-core-1.3.2.jar包. 网址:http://code. ...
- Mybatis generator自动生成mybatis配置和类信息
自动生成代码方式两种: 1.命令形式生成代码,详细讲解每一个配置参数. 2.Eclipse利用插件形式生成代码. 安装插件方式: eclipse插件安装地址:http://mybatis.google ...
- MyBatis Generator自动生成MyBatis的映射代码
MyBatis Generator大大简化了MyBatis的数据库的代码编写,有了一个配置文件,就可以直接根据表映射成实体类.Dao类和xml映射.资源地址:MyBatis项目地址:http://my ...
- 使用generator自动生成mybatis model、mapper.xml、mapper等(转)
原文链接:http://www.cnblogs.com/lichenwei/p/4145696.html Mybatis属于半自动ORM,在使用这个框架中,工作量最大的就是书写Mapping的映射文件 ...
- 使用MyBatis Generator自动生成MyBatis的代码
这两天需要用到MyBatis的代码自动生成的功能,由于MyBatis属于一种半自动的ORM框架,所以主要的工作就是配置Mapping映射文件,但是由于手写映射文件很容易出错,所以可利用MyBatis生 ...
- ator自动生成mybatis配置和类信息
generator自动生成mybatis的xml配置.model.map等信息: 1.下载mybatis-generator-core-1.3.2.jar包. 网址:http://cod ...
- MyBatis使用Generator自动生成代码
MyBatis中,可以使用Generator自动生成代码,包括DAO层. MODEL层 .MAPPING SQL映射文件. 第一步: 配置好自动生成代码所需的XML配置文件,例如(generator. ...
随机推荐
- Research on Unsupervised Word Alignment Based on Inversion Transduction Grammar
1.提出了一种基于特征函数和反向转录文法(ITG)的无监督词对齐模型,使用对数线性模型对文法规则的概率建模,先验知识可以通过特征函数的形式加入到模型里面,而模型仍然可以进行无监督训练.2. 在模型的参 ...
- ubuntu 错误 & 解决
1.ssh时出现“段错误(核心已转储)” 原因:说明与ssh有关的内核代码被修改过并且部分代码访问内存过界 解决:1.将内核代码被修改过的部分修改回来 2.sudo apt-get re ...
- CUDA ---- 简介
CUDA简介 CUDA是并行计算的平台和类C编程模型,我们能很容易的实现并行算法,就像写C代码一样.只要配备的NVIDIA GPU,就可以在许多设备上运行你的并行程序,无论是台式机.笔记本抑或平板电脑 ...
- asp web api 怎么使用put和delete。
Method Overriding RESTful services allow the clients to act on the resources through methods such as ...
- 纯JS Web在线可拖拽的流程设计器
F2工作流引擎之-纯JS Web在线可拖拽的流程设计器 Web纯JS流程设计器无需编程,完全是通过鼠标拖.拉.拽的方式来完成,支持串行.并行.分支.异或分支.M取N路分支.会签.聚合.多重聚合.退回. ...
- 转】Linux下安装Tomcat服务器和部署Web应用
原博文出自于: http://www.cnblogs.com/xdp-gacl/p/4097608.html 感谢! 一.上传Tomcat服务器
- C++ __int64用法(转)
在做ACM题时,经常都会遇到一些比较大的整数.而常用的内置整数类型常常显得太小了:其中long 和 int 范围是[-2^31,2^31),即-2147483648~2147483647.而unsig ...
- [原创]Devexpress XtraReports 系列 10 创建标签报表
今天这篇是Dx Reports 基础初级系列的最后一篇了.以后如果有什么高级的应用,应该另开一个中级使用系列. 昨天发表了Devexpress XtraReports系列第九篇[原创]Devexpre ...
- JQery icheck 插件
<script type="text/javascript"> $(document).ready(function(){ var callbacks_list = $ ...
- Label & TextBlock
I always thought it was odd that WPF has both TextBlock and Label. They both are responsible for di ...