MyBatis中參數為List


mapper中寫接口,必須加上 @Param("partyOrganId"),否則會出錯。
List<EChartsDO> getMemberByAge(@Param("partyOrganId") List<Long> partyOrganId);

xml映射中:
<sql id="WhereClause">
    where isdel='N'
<if test="partyOrganId!= null">
AND party_organ_id in
<foreach collection="partyOrganId" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</sql>
 <select id="getMemberByAge" resultMap="ExtResultMap" parameterType="java.util.List">
select text,count(id) count,total,ROUND(count(id)/total*100,1) percent from
(select case when TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 18 AND 29 then '18-29歲'
when TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 30 AND 39 then '30-39歲'
when TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 40 AND 49 then '40-49歲'
when TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 50 AND 59 then '50-59歲'
when TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 60 AND 69 then '60-69歲'
when TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 70 AND 79 then '70-79歲'
when TIMESTAMPDIFF(YEAR, birthday, CURDATE()) > 80 then '80歲以上' end as text,id,
(select count(id) from common_party_member <include refid="WhereClause" />) total
from common_party_member <include refid="WhereClause" />
)t GROUP BY text
</select>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM