ibatis返回List<String>
来源:互联网 发布:windows android语言 编辑:程序博客网 时间:2024/06/06 02:49
需求:返回电话号码列表,之前查询多个字段时用Map作为返回类型,现在单个字段列表用List。
最开始的写法:
<select id="selectCellListByShopId" resultClass="List" parameterClass="java.lang.Long">
select P.TEL_PHONE
from SHOP_PHONE P
WHERE P.SHOP_ID =#shopId:BIGINT#
and P.IS_DEL = '0' and P.IS_ACTIVE = '1'
</select>
这样查到的结果是[]列表,后来在老外的一篇文章上找到的解决方案,地址如下:
http://ibatis.10938.n7.nabble.com/return-simple-String-or-List-lt-String-gt-td17133.html
其中重点如下:
Tomas,
I am assuming that you have not read the developers guide and I just
giving things a go. You need to read the guide completely.
In this case Guy was saying that if your query only returns a string
then set the resultType to String. Then use the ibatis queryForList()
to compile your results into a List<String>.
Nathan
按照这个方案修改后的代码如下:
<select id="selectCellListByShopId" resultClass="java.lang.String" parameterClass="java.lang.Long">
select P.TEL_PHONE
from SHOP_PHONE P
WHERE P.SHOP_ID =#shopId:BIGINT#
and P.IS_DEL = '0' and P.IS_ACTIVE = '1'
</select>
Dao层通过queryForList()方法查询出来即可。
小结:遇到这种问题的常用解决方案
1.查询ibatis的官方文档.
2.Google 关键字ibatis resultClass.
- ibatis返回List<String>
- ibatis 返回list<string> 集合 (有效)
- ibatis 返回list<String[]>----resultClass="hashMap" 可以实现
- Ibatis Vo 中含有List<String>
- Spring Mybatis 返回 List<String> 和List<Map<String,Object>>
- ibatis中直执行sql,返回存储Map的List类型
- ibatIS中返回结果map 并使用list获取
- 数据库查询返回List<Map<String, Object>>
- mybatis返回List<Map<String,Object>>
- java thrift返回List<String>异常
- mybaties 一对多 list<String> 返回数据
- Spring Mybatis 返回List<Map<String,Object>>
- mybatis返回list<String>类型数据
- 获取List<Map>中的Key值,返回List<String>
- mybatis返回类型string,或者对象,均可用list<string>或者,list<对象>来接收
- Mybatis 如何 返回 List<String> 类型 或 List<Map<String,Object>>类型
- xfire webService返回Map<String,List<E>>嵌套复杂类型
- 服务端返回List<Map<String,Object>>数据,$http 无法接收
- 【人文】第一部分对保不住秘密的人,要保持距离
- pthreads 安装error: pthreads requires ZTS,please re-compile PHP with ZTS enabled
- 将文字显示在图片上面,并使文字背景半透明
- jquery获取颜色,ie和ff的区别
- 【C++专题】static_cast, dynamic_cast, const_cast探讨
- ibatis返回List<String>
- UIAlertview中自定义ALert, confirm, promopt
- Can't load AMD 64-bit .dll on a IA 32-bit platform
- linux下vi命令大全
- Oracle创建表空间和表空间用户的步骤
- 测试
- cocos2d-x使用CCControlButton的一些问题
- WinCE获取系统语言
- SQL 语句获取表字段名称,属性