如需在查询 baseSelect 中返回统计数 total,则可在 ResultMap 中用 Collection 进行处理。
但具体使用方法没有参考到网上具体例子,于是试了下错,得出结果如下:
<select id="baseSelect" resultMap="MyResultMap">
select p_id,p_value from p_detail where p_id = #{pId}
</select>
<resultMap id="MyResultMap" type="com.test.service.demo.model.P" >
<id column="p_id" property="pId" jdbcType="INTEGER" />
<result column="p_value" property="pValue" jdbcType="DECIMAL" />
<collection property="total" model.P 的 total
column="{pId = p_id}" baseSelect返回的p_id 用作childSelect的查询参数pId
select="chilrdSelect" 该字段需要调用的子查询
javaType="java.math.BigDecimal" /> model.P中 total的类型
</resultMap>
<select id="chilrdSelect" resultType="java.math.BigDecimal">
select sum(dt.value) total
from p_detail dt
where dt.p_id = #{pId}
</select>
网友评论