ibatis2到mybatis的转变.docx_第1页
ibatis2到mybatis的转变.docx_第2页
ibatis2到mybatis的转变.docx_第3页
ibatis2到mybatis的转变.docx_第4页
ibatis2到mybatis的转变.docx_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Ibatis2 到 mybatis3 的转变连接数据库配置文件New DTDsNew sqlMapConfig.xml DTD: New sqlMap (*.map.xml) DTD: Configuration Root configuration tag is now SettingsWithin the root configuration tag: is now: and can be removed, since the use of namespaces has become mandatory. must be moved out of the element to . and is now: is now: Mapping The root element is now 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 tag The groupBy attribute has been eliminated. Here is an example of groupBy from a 2.x sqlMap: New: Nested resultMapsThese should now be specified using the tag. .is now: .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: #valuejdbcType changesjdbcType=ORACLECURSORis now: jdbcType=CURSORand jdbcType=NUMBERis now: jdbcType=NUMERICStored procedures the tag doesnt exist anymore. Use , or . ? = call pkgExample.getValues(p_id = ?) is now: ? = call pkgExample.getValues(p_id = ?)If youre calling an insert procedure that returns a value, you can use instead of , but make sure to specify useCache=false and flushCache=true. Youll 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 parameters resultMap contains an 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 is now: Note: you can omit eviction=LRU since it is the default. the tag is replaced by the flushCache attribute for the statements and the cache will be used by all select statements by default. Dynamic SQLThe most common dynamic SQL in my project is isNotNull. Here is an example replacement regex: Pattern: Replacement: 配置文件示例SqlMapConfig Mapper SELECT MAX(SYCK_SMS_LIST_ID) FROM T_SYCK_SMS_LIST #startSmsListId and SMS.SYCK_SMS_LIST_ID 高级映射一对一映射 封装时引用别的resultMap,这里你也可以直接在这里写,如下: 建议采用引用,因为那样可以重复利用一对多映射集合的封装是一样的注意:这里的集合映射只能映射实现或者间接实现collection接口的集合类,不能使用Map; 属性对象声明的集合要和这里存放的保持一致动态Sql书写 Mybatis3支持OGNL表达式 在sqlMap的xml文件中可以直接使用 像 ORG_NAME like %|#orgName|%除了if ,mybatis还支持 choose,when , otherwise trim,where,set,foreach 等注意 foreach 只支持 list array文本替换mybatis3的用户指南里关于字符串替换的解释是:字符串替换 默认情况下,使用#格式的语法会导致 MyBatis 创建预处理语句属性并以它为背景设置安全的值(比如?)。这样做很安全,很迅速也是首选做法,有时你只是想直接在 SQL 语句中插入一个不改变的字符串。比如,像 ORDER BY,你可以这样来使用: ORDER BY $columnName 这里 MyBatis 不会修改或转义字符串。 重要:接受从用户输出的内

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论