MyBatis-基本类型列表 [英] MyBatis - lists of primitive types

查看:179
本文介绍了MyBatis-基本类型列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎使我望而却步.我知道我可以使用地图从myBatis查询返回原始的行集,但是如何使用原始类型的 list 来做到这一点?

This seems to have eluded me. I know I can use a map to return a vanilla set of rows from a myBatis query but how to do it with a list of primitive types?

例如如果我有类似的SQL:

e.g. If I had SQL like:

select product_price from products

这是否需要一个resultMap?我尝试将java.util.ArrayList用作结果类型,但得到未找到类的错误.

Does this require a resultMap? I've tried to use java.util.ArrayList as the result type but get class not found errors.

同样,我如何将项目列表作为参数传递给查询.

In a similar vein, how do I pass a list of items as an argument to a query.

任何输入,对文档的指针都表示赞赏.

Any input, pointers to docs appreciated.

推荐答案

只需将resultType声明为所需的原始类型,在您的情况下为Long.它将作为列表返回.

Just declare the resultType as the primitive type that you want, which in your case is a Long. It will be returned as a list.

<select id="getPrice" resultType="java.lang.Long">
  select product_price from products
</select>

在映射器界面中,您应该期望返回Long的列表.

In the mapper interface you should expect to get back a list of Long.

List<Long> getPrice();

这篇关于MyBatis-基本类型列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆