Mybatis中通過HaseMap封裝引數作為查詢條件
阿新 • • 發佈:2019-02-08
HaseMap封裝引數
Map<String, Object> paramMap = new HashMap<String, Object>(); List<Long> aprrovalStatus = new ArrayList<Long>(); aprrovalStatus.add(AprrovalStatus.COMMITED.getKey()); aprrovalStatus.add(AprrovalStatus.SYNCHRONIZED.getKey()); paramMap.put("aprrovalStatus", aprrovalStatus); paramMap.put("parentFundsId", detailId);
查詢
Long commitedAmt = LONG_ZERO;
Long CommitedTotalAmt = reconFundsDetailTmpService.queryCommitedTotalAmt(paramMap); // 大於0入金多,小於0出金多
Mybatis中的sql,
<select id="queryCommitedTotalAmt" parameterType="java.util.HashMap" resultType="java.lang.Long"> SELECT SUM(FUNDS_AMT_IN)-SUM(FUNDS_AMT_OUT) FROM T_CBS_RECON_FUNDS_DETAIL_TMP WHERE PARENT_FUNDS_ID = #{parentFundsId} AND APRROVAL_STATUS in <foreach item="item" index="index" collection="aprrovalStatus" open="(" separator="," close=")"> #{item} </foreach> </select>
if (CommitedTotalAmt != null) {
commitedAmt = CommitedTotalAmt;
}
//順便提一下, 對於小數的處理, 用的是BigDecimal, 在頁面上對小數的控制
BigDecimal bigAmt = new BigDecimal(String.valueOf(amt));// 拆分金額