gpt4 book ai didi

collections - Mybatis中另一个结果Map中选择List of Integers作为Collection

转载 作者:行者123 更新时间:2023-12-03 18:35:56 25 4
gpt4 key购买 nike

我想在Mybatis的Result Map中选择整数集合作为集合。我无法想出办法。

结果类是

class Mapping {
private String name;
private List<Integer> ids;
}

Mybatis 如下:
<resultMap id="mapping" type="some.package.Mapping">
<result property="name" column="name"/>
<collection property="ids" column="id" javaType="java.util.List" ofType="java.lang.Integer" />
</resultMap>

<select id="getMapping" resultMap="mapping">
SELECT name, id
FROM mapping
</select>

这段代码不适合我。
我错过了什么?

最佳答案

要在单个 resultMap 中获取整数列表,您可以使用:

<id property="name" column="name"/>
<collection property="ids" ofType="Integer">
<result column="id"/>
</collection>

嵌套选择也可以,但它会执行 N+1 个查询,可能是 a performance issue .

关于collections - Mybatis中另一个结果Map中选择List of Integers作为Collection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34742431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com