- 浏览: 513571 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (563)
- 工作经验 (12)
- 数据库 (13)
- Servlet (10)
- Struts2 (1)
- Spring (25)
- Eclipse (5)
- Hibernate (5)
- Eclips (8)
- HTTP (7)
- J2EE (21)
- EHcache (1)
- HTML (11)
- 工具插件使用 (20)
- JPA (2)
- 杂谈 (17)
- 数据结构与算法 (3)
- Cloud Foundry (1)
- 安全 (10)
- J2SE (57)
- SQL (9)
- DB2 (6)
- 操作系统 (2)
- 设计模式 (1)
- 版本代码管理工具 (13)
- 面试 (10)
- 代码规范 (3)
- Tomcat (12)
- Ajax (5)
- 异常总结 (11)
- REST (2)
- 云 (2)
- RMI (3)
- SOA (1)
- Oracle (12)
- Javascript (20)
- jquery (7)
- JSP自定义标签 (2)
- 电脑知识 (5)
- 浏览器 (3)
- 正则表达式 (3)
- 建站解决问题 (38)
- 数据库设计 (3)
- git (16)
- log4j (1)
- 每天100行代码 (1)
- socket (0)
- java设计模式 耿祥义著 (0)
- Maven (14)
- ibatis (7)
- bug整理 (2)
- 邮件服务器 (8)
- Linux (32)
- TCP/IP协议 (5)
- java多线程并发 (7)
- IO (1)
- 网页小工具 (2)
- Flash (2)
- 爬虫 (1)
- CSS (6)
- JSON (1)
- 触发器 (1)
- java并发 (12)
- ajaxfileupload (1)
- js验证 (1)
- discuz (2)
- Mysql (14)
- jvm (2)
- MyBatis (10)
- POI (1)
- 金融 (1)
- VMWare (0)
- Redis (4)
- 性能测试 (2)
- PostgreSQL (1)
- 分布式 (2)
- Easy UI (1)
- C (1)
- 加密 (6)
- Node.js (1)
- 事务 (2)
- zookeeper (3)
- Spring MVC (2)
- 动态代理 (3)
- 日志 (2)
- 微信公众号 (2)
- IDEA (1)
- 保存他人遇到的问题 (1)
- webservice (11)
- memcached (3)
- nginx (6)
- 抓包 (1)
- java规范 (1)
- dubbo (3)
- xwiki (1)
- quartz (2)
- 数字证书 (1)
- spi (1)
- 学习编程 (6)
- dom4j (1)
- 计算机系统知识 (2)
- JAVA系统知识 (1)
- rpcf (1)
- 单元测试 (2)
- php (1)
- 内存泄漏cpu100%outofmemery (5)
- zero_copy (2)
- mac (3)
- hive (3)
- 分享资料整理 (0)
- 计算机网络 (1)
- 编写操作系统 (1)
- springboot (1)
最新评论
-
masuweng:
亦论一次OutOfMemoryError的定位与解错 -
变脸小伙:
引用[color=red][/color]百度推广中运用的技术 ...
Spring 3 mvc中返回pdf,json,xml等不同的view -
Vanillva:
不同之处是什么??
Mybatis中的like查询 -
thrillerzw:
转了。做个有理想的程序员
有理想的程序员必须知道的15件事 -
liujunhui1988:
觉得很有概括力
15 个必须知道的 Java 面试问题(2年工作经验)
源:https://code.google.com/p/mybatis/wiki/DocUpgrade3
http://www.cnblogs.com/suyuan/archive/2009/11/09/1598892.html
评:
Conversion Tool
There is a tool available in the downloads section that will help you to convert your iBATIS 2.x sqlmap files into MyBatis 3.x xml mapper files.
Get it from http://mybatis.googlecode.com/files/ibatis2mybatis.zip
The tool is designed around an xslt transformation and some text replacements packaged in an ant task and tries to deliver a good starting point before the more complex work begins.
New DTDs
New sqlMapConfig.xml DTD:
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
New sqlMap (*.map.xml) DTD:
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
Configuration
Root configuration tag <sqlMapConfig> is now <configuration>
Settings
Within the root configuration tag:
<settings x="y" foo="bar"/>
is now:
<settings>
<setting name="x" value="y"/>
<setting name="foo" value="bar"/>
</settings>
and
<settings useStatementNamespaces="true"/>
can be removed, since the use of namespaces has become mandatory.
<typeAlias>
<typeAlias> must be moved out of the <sqlMap> element to <configuration><typeAliases></typeAliases></configuration>
<configuration>
<settings>
...
</settings>
<typeAliases>
<typeAlias ... />
</typeAliases>
</configuration>
<transactionManager> and <dataSource>
<transactionManager type="JDBC" commitRequired="false">
<dataSource type="your.package.CustomDataSourceFactory" />
</transactionManager>
is now:
<environments default="env">
<environment id="env">
<transactionManager type="JDBC">
<property name="commitRequired" value="false"/>
</transactionManager>
<dataSource type="your.package.CustomDataSourceFactory" />
</environment>
</environments>
<sqlMap>
<sqlMap resource=... />
<sqlMap resource=... />
<sqlMap resource=... />
is now:
<mappers>
<mapper resource=... />
</mappers>
Mapping
The root element <sqlMap> is now <mapper>
The attribute parameterClass should be changed to parameterType
The attribute resultClass should be changed to resultType
The attribute class should be changed to type
the columnIndex attribute does not exist anymore for the <result> tag
The groupBy attribute has been eliminated. Here is an example of groupBy from a 2.x sqlMap:
<resultMap id="productRM" class="product" groupBy="id">
<result property="id" column="product_id"/>
<result property="name" column="product_name"/>
<result property="category" column="product_category"/>
<result property="subProducts" resultMap="Products.subProductsRM"/>
</resultMap>
New:
<resultMap id="productRM" type="product" >
<id property="id" column="product "/>
<result property="name " column="product_name "/>
<result property="category " column="product_category "/>
<collection property="subProducts" resultMap="Products.subProductsRM"/>
</resultMap>
Nested resultMaps
These should now be specified using the <association> tag.
<resultMap ...>
<result property="client" resultMap="Client.clientRM"/>
...
</resultMap>
is now:
<resultMap ...>
<association property="client" resultMap="Client.clientRM"/>
...
</resultMap>
<parameterMap>
Although this tag is deprecated, it can be used as in iBatis 2. However for versions up to 3.0.3 there is a bug when using type="map" and not specifying javaType for a parameter. This will result in
There is no getter for property named '...' in 'interface java.util.Map'
This should be solved in MyBatis 3.0.4. For versions 3.0.3 and earlier the workaround is to explicitly specify javaType.
Inline parameters
#value#
is now:
#{value}
jdbcType changes
jdbcType="ORACLECURSOR"
is now:
jdbcType="CURSOR"
and
jdbcType="NUMBER"
is now:
jdbcType="NUMERIC"
Stored procedures
the <procedure> tag doesn't exist anymore. Use <select>, <insert> or <update>.
<procedure id="getValues" parameterMap="getValuesPM">
{ ? = call pkgExample.getValues(p_id => ?) }
</procedure>
is now:
<select id="getValues" parameterMap="getValuesPM" statementType="CALLABLE">
{ ? = call pkgExample.getValues(p_id => ?)}
</select>
If you're calling an insert procedure that returns a value, you can use <select> instead of <insert>, but make sure to specify useCache="false" and flushCache="true". You'll also have to force a commit.
for stored procedures that return a cursor, there is a bug (see issue 30 ) when using nested result maps (i.e. the output parameter's resultMap contains an <association> tag with the resultMap attribute). As long as the issue is not fixed, you have to specify the resultMap of the output parameter on the statement itself as well, or the nested resultMap will not be populated.
Caching
<cacheModel id="myCache" type="LRU">
<flushInterval hours="24"/>
<property name="size" value="100" />
</cacheModel>
is now:
<cache flushInterval="86400000" eviction="LRU"/>
Note: you can omit eviction="LRU" since it is the default.
the <flushOnExecute> tag is replaced by the flushCache attribute for the statements and the cache will be used by all select statements by default.
Dynamic SQL
The most common dynamic SQL in my project is isNotNull. Here is an example replacement regex:
Pattern:
<isNotNull.*?property=\"(.*?)\">
</isNotNull>
Replacement:
<if test="$1 != null">
</if>
Also common is the use of isEqual, you can replace this by a similar <if> tag.
http://www.cnblogs.com/suyuan/archive/2009/11/09/1598892.html
评:
Conversion Tool
There is a tool available in the downloads section that will help you to convert your iBATIS 2.x sqlmap files into MyBatis 3.x xml mapper files.
Get it from http://mybatis.googlecode.com/files/ibatis2mybatis.zip
The tool is designed around an xslt transformation and some text replacements packaged in an ant task and tries to deliver a good starting point before the more complex work begins.
New DTDs
New sqlMapConfig.xml DTD:
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
New sqlMap (*.map.xml) DTD:
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
Configuration
Root configuration tag <sqlMapConfig> is now <configuration>
Settings
Within the root configuration tag:
<settings x="y" foo="bar"/>
is now:
<settings>
<setting name="x" value="y"/>
<setting name="foo" value="bar"/>
</settings>
and
<settings useStatementNamespaces="true"/>
can be removed, since the use of namespaces has become mandatory.
<typeAlias>
<typeAlias> must be moved out of the <sqlMap> element to <configuration><typeAliases></typeAliases></configuration>
<configuration>
<settings>
...
</settings>
<typeAliases>
<typeAlias ... />
</typeAliases>
</configuration>
<transactionManager> and <dataSource>
<transactionManager type="JDBC" commitRequired="false">
<dataSource type="your.package.CustomDataSourceFactory" />
</transactionManager>
is now:
<environments default="env">
<environment id="env">
<transactionManager type="JDBC">
<property name="commitRequired" value="false"/>
</transactionManager>
<dataSource type="your.package.CustomDataSourceFactory" />
</environment>
</environments>
<sqlMap>
<sqlMap resource=... />
<sqlMap resource=... />
<sqlMap resource=... />
is now:
<mappers>
<mapper resource=... />
</mappers>
Mapping
The root element <sqlMap> is now <mapper>
The attribute parameterClass should be changed to parameterType
The attribute resultClass should be changed to resultType
The attribute class should be changed to type
the columnIndex attribute does not exist anymore for the <result> tag
The groupBy attribute has been eliminated. Here is an example of groupBy from a 2.x sqlMap:
<resultMap id="productRM" class="product" groupBy="id">
<result property="id" column="product_id"/>
<result property="name" column="product_name"/>
<result property="category" column="product_category"/>
<result property="subProducts" resultMap="Products.subProductsRM"/>
</resultMap>
New:
<resultMap id="productRM" type="product" >
<id property="id" column="product "/>
<result property="name " column="product_name "/>
<result property="category " column="product_category "/>
<collection property="subProducts" resultMap="Products.subProductsRM"/>
</resultMap>
Nested resultMaps
These should now be specified using the <association> tag.
<resultMap ...>
<result property="client" resultMap="Client.clientRM"/>
...
</resultMap>
is now:
<resultMap ...>
<association property="client" resultMap="Client.clientRM"/>
...
</resultMap>
<parameterMap>
Although this tag is deprecated, it can be used as in iBatis 2. However for versions up to 3.0.3 there is a bug when using type="map" and not specifying javaType for a parameter. This will result in
There is no getter for property named '...' in 'interface java.util.Map'
This should be solved in MyBatis 3.0.4. For versions 3.0.3 and earlier the workaround is to explicitly specify javaType.
Inline parameters
#value#
is now:
#{value}
jdbcType changes
jdbcType="ORACLECURSOR"
is now:
jdbcType="CURSOR"
and
jdbcType="NUMBER"
is now:
jdbcType="NUMERIC"
Stored procedures
the <procedure> tag doesn't exist anymore. Use <select>, <insert> or <update>.
<procedure id="getValues" parameterMap="getValuesPM">
{ ? = call pkgExample.getValues(p_id => ?) }
</procedure>
is now:
<select id="getValues" parameterMap="getValuesPM" statementType="CALLABLE">
{ ? = call pkgExample.getValues(p_id => ?)}
</select>
If you're calling an insert procedure that returns a value, you can use <select> instead of <insert>, but make sure to specify useCache="false" and flushCache="true". You'll also have to force a commit.
for stored procedures that return a cursor, there is a bug (see issue 30 ) when using nested result maps (i.e. the output parameter's resultMap contains an <association> tag with the resultMap attribute). As long as the issue is not fixed, you have to specify the resultMap of the output parameter on the statement itself as well, or the nested resultMap will not be populated.
Caching
<cacheModel id="myCache" type="LRU">
<flushInterval hours="24"/>
<property name="size" value="100" />
</cacheModel>
is now:
<cache flushInterval="86400000" eviction="LRU"/>
Note: you can omit eviction="LRU" since it is the default.
the <flushOnExecute> tag is replaced by the flushCache attribute for the statements and the cache will be used by all select statements by default.
Dynamic SQL
The most common dynamic SQL in my project is isNotNull. Here is an example replacement regex:
Pattern:
<isNotNull.*?property=\"(.*?)\">
</isNotNull>
Replacement:
<if test="$1 != null">
</if>
Also common is the use of isEqual, you can replace this by a similar <if> tag.
发表评论
-
MyBatis排序时施用orderby动态参数时需要注意,用$而不是#
2016-08-10 18:24 934源:http://www.makaidong.com/%E6% ... -
Mybatis中的like查询
2016-01-06 15:30 626源:http://blog.csdn.net/zhang987 ... -
Spring+Mybatis整合事务不起作用之解决方案汇总
2014-12-29 21:36 1350源:http://blog.csdn.net/walkerjo ... -
mybatis xml写动态 sql where set 自动去除 , and/or
2014-11-24 15:19 1915源:http://limingnihao.iteye.com/ ... -
ibatis中 $ 于 # 的 区别?
2014-06-17 16:39 499源:http://www.blogjava.net/lsbwa ... -
Mybatis多参数查询映射
2014-04-30 14:22 768源:http://fengfan876.iteye.com/b ... -
MyBatis insert 返回主键的方法
2014-04-28 10:08 671源:http://www.chendw.cn/original ... -
spring与mybatis三种整合方法
2014-04-27 20:25 603源: 评: 本文主要介绍Spring与Mybatis三种常用整 ... -
mybatis显示sql语句 log4j.properties配置文件
2014-03-20 17:09 1530源:http://my.oschina.net/abian/b ... -
基于MyBatis3.0.6的基本操作介绍
2014-03-06 09:01 908源:http://haohaoxuexi.iteye.com/ ... -
iBatis简单入门教程
2013-12-03 22:16 519源:http://www.cnblogs.com/ycxyyz ... -
ibatis 插入一条数据返回插入这条数据的主键
2013-11-26 11:48 502源:http://www.iteye.com/topic/2 ... -
iBatis入门
2013-11-26 10:51 784源:http://xdwangiflytek.iteye.c ...
相关推荐
`ibatis2mybatisConverter` 是一个工具,旨在帮助开发者将 iBatis 2 的 SQLMap XML 文件无缝迁移到 Mybatis 3。 在 iBatis 2 中,SQLMap XML 文件包含了数据库交互的核心元素,如 SQL 查询、结果映射、事务管理和...
2. 配置SqlMapConfig.xml:这是Ibatis的核心配置文件,包含数据源、事务管理器、SqlMap等配置。 三、SqlMap配置 SqlMap是Ibatis中的核心组件,用于存放SQL语句和结果映射。每个SqlMap对应一个数据库表,通过XML文件...
标题中的“ibatis 连接字符串 SqlMapConfig.xml”指的是使用iBATIS(一个轻量级的Java持久层框架)时,配置数据库连接的关键文件——SqlMapConfig.xml。这个文件是iBATIS的核心配置文件,它包含了数据源、事务管理器...
标题 "Eclipse Spring3.x集成ibatis2.x开发案例" 提供了我们即将探讨的核心内容:如何在Eclipse环境中利用Spring3.x版本与iBatis2.x版本进行整合开发。这个主题涵盖了Java企业级开发中的两个重要框架,Spring作为...
在iBatis中,核心组件主要包括XML配置文件、SqlMapClient、SqlMapConfig.xml以及SqlMap接口。XML配置文件用于定义SQL语句、存储过程和结果映射,SqlMapClient是数据访问的入口,SqlMapConfig.xml是全局配置文件,而...
在2.3.4.726这个版本中,我们可以期待看到一些关键组件,如SqlMapConfig.xml配置文件的解析逻辑,SqlMapClient的构建和执行SQL的方法,以及Statement类型的定义(例如,SelectStatement、InsertStatement等)。...
SqlMapConfig.xml文件是Ibatis-SqlMap的核心配置,包含了数据源、事务管理器等重要设置。 二、版本差异 1. ibatis-sqlmap_2.3.4.jar:这是Ibatis-SqlMap的一个稳定版本,包含了一些bug修复和性能优化。2.3.4版本...
总结来说,"sql-map-2.dtd"和"sql-map-config-2.dtd"是Ibatis 2.x版本中非常关键的组件,它们为XML配置文件提供了结构化规则,使得开发人员能够编写出合法且易于维护的SQL映射文件和全局配置文件。理解并正确使用...
SqlMap的配置是iBatis中应用的核心。这部分任务占据了iBatis开发的...Sql Map配置文件是iBatis配置的核心,从数据库连接到执行SQL时使用的sqlMap文件都是通过此文件中的配置提供给框架的,它通常命名为sqlMapConfig.xml
需要注意的是,IBatis的包声明是org.apache.ibatis开头的,因此需要下载ibatis-common.jar和ibatis-sqlmap.jar文件。 2. IBatis的ResultMap 在IBatis中,ResultMap是用于定义查询结果的结构。ResultMap可以包含多...
Ibatis2的核心是SqlMapConfig.xml配置文件,其中包含了数据源、事务管理以及SqlMap的定义,使得开发者可以自定义SQL语句,避免了传统的Hibernate等ORM框架的过度封装。 在描述中提到的“能够显示所执行的sql”,这...
通过对`sqlMapConfig.xml`文件的深入解析,我们不仅了解了ibatis配置文件的基本结构,还掌握了如何通过配置文件来调整ibatis的行为,这对于实际开发工作具有重要的指导意义。在后续的学习过程中,我们还将进一步探索...
ibatis的配置文件主要包括三部分:`SqlMap.properties`、`SqlMapConfig.xml` 和 `Student.xml`。下面将分别对这三个文件进行详细介绍。 ##### 1. SqlMap.properties 文件 `SqlMap.properties` 文件用于存储数据库...
SqlMapConfig.xml是iBATIS的核心配置文件,它定义了全局的设置和数据源信息,使得整个系统能够正确地运行和管理SQL映射。下面我们将详细解析这个配置文件的各个部分。 首先,配置文件的开头是XML声明和DTD定义,...
iBatis在启动时会解析SqlMapConfig.xml,加载数据源、事务管理器等配置,然后根据SqlMap.xml中的配置创建SqlMapClient,用于后续的数据库操作。 4. **动态SQL** iBatis允许在XML映射文件中编写动态SQL,通过条件...
其中,包含了SqlMapConfig.xml配置文件,这是iBatis系统的核心,用于定义数据源、事务管理器、SqlMapClient等重要组件。此外,还包含了各种SqlMap接口,用于执行SQL语句;Executor接口及其实现类,负责SQL的执行策略...
2. sqlmapconfig.xml:这是iBATIS的全局配置文件,包含了数据源、事务管理器等配置信息。 3. sqlmap.xml:每个数据库相关的操作都会有一个对应的sqlmap.xml文件,定义具体的SQL映射。 4. 事务管理:iBATIS支持事务...
iBatis 是一款著名的开源Java持久层框架,它允许开发者将SQL语句直接写在XML配置文件中,实现了SQL与Java代码的分离,极大地提高了开发效率。本开发文档包括了三份重要的参考资料,分别是:iBATIS-SqlMaps-2_cn.pdf、...
iBatis的配置文件SqlMapConfig.xml是系统启动时加载的关键,它包含了数据源(DataSource)、事务管理器(TransactionManager)和SqlMap配置信息。解析这个XML文件的过程涉及到DOM或SAX解析器,源码中这部分功能通常...