ibatis传入list对象
2015-08-23 22:44
465 查看
在使用ibatis的时候经常需要传入list对象,sql语句如下。
这个是简单的sql语句,对于list中是别的对象的,比如List<Person>这个参数传进来时需要这样使用
注意:上面select语句入参用的是parameterClass是java.util.ArrayList类,而不是一个map,这时iterator语句就不需要有property="ids"属性,即
如果有这个属性的话ibatis会从参数中去找属性为ids这个对象,而参数是一个list没有这个属性,因此就会报错:
如果parameter使用map,那么需要在java代码中将这个list封装进map。
<select id="GET-PERSONS" parameterClass="java.util.ArrayList" resultClass="pojo.Person"> <![CDATA[ select * from person where id in ]]> <iterate open="(" close=")" conjunction=","> #list[]# </iterate> </select>
这个是简单的sql语句,对于list中是别的对象的,比如List<Person>这个参数传进来时需要这样使用
<select id="GET-PERSONS" parameterClass="java.util.List" resultClass="pojo.Person"> <![CDATA[ select * from person where id in ]]> <iterate open="(" close=")" conjunction=","> <![CDATA[ #list[].id# ]]> </iterate> </select>
注意:上面select语句入参用的是parameterClass是java.util.ArrayList类,而不是一个map,这时iterator语句就不需要有property="ids"属性,即
<select id="GET-PERSONSS" parameterClass="java.util.ArrayList" resultClass="pojo.Person"> <![CDATA[ select * from person where id in ]]> <iterate property="ids" open="(" close=")" conjunction=","> #ids[]# </iterate> </select>
如果有这个属性的话ibatis会从参数中去找属性为ids这个对象,而参数是一个list没有这个属性,因此就会报错:
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in person-sqlmap.xml. --- The error occurred while preparing the mapped statement for execution. --- Check the person.GET-PERSONS. --- Check the parameter map. --- Cause: com.ibatis.common.beans.ProbeException: Error getting ordinal list fr om JavaBean. Cause java.lang.StringIndexOutOfBoundsException: String index out o f range: -1
如果parameter使用map,那么需要在java代码中将这个list封装进map。
相关文章推荐
- 【C#】事务
- js封装获取标签处理操作 ,ajax,ready()方法
- Perl学习(七)
- 互斥锁-单例之懒汉式的线程安全
- 20150823 作业
- SVN服务器搭建和使用(一) (转载)
- 进程的地址空间:TEXT,DATA,BSS,HEAP,STACK
- Devc++编译系统分配给int多少字节
- 1076. Forwards on Weibo (30) - 记录层的BFS改进
- POJ 3067 japan
- PHP实现页面跳转方法
- ESX6如何实现开机登录的界面
- 1076. Forwards on Weibo (30) - 记录层的BFS改进
- Wiki_Android_双击或多次点击事件
- TalkingData灵动分析背后的产品故事
- python import 产生的问题(name 'xml' is not defined)
- CocurrentHashMap和Hashtable的区别
- MySql常用函数大全讲解
- ibatis中使用List作为传入参数的使用方法及 CDATA使用
- git@osc使用教程