ibatis返回List<String>

需求:返回电话号码列表,之前查询多个字段时用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.




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值