关于mybatis 使用case when 计算BigDecimal 数据返回对象的问题

例子:

SELECT
ai.auditing_code AS auditingCode,
ci.contract_code AS contractCode,
ai.customer_name AS customerName,
ai.id_code AS idCode,
ai.recorder_pargana_code AS recorderParganaCode,
ai.recorder_pargana AS recorderPargana,
ai.recorder_store AS recorderStore,
ai.recorder_store_code AS recorderStoreCode,
ai.recorder_id AS recorderId,
ai.recorder_name AS recorderName,
ai.contract_balance AS contractBalance,
pr.payment_balance AS paymentBalance,
pr.payment_time AS paymentTime,
rp.repayment_day AS repaymentDay,
rp.month_balance AS monthBalance,
rp.should_capital AS shouldCapital,
rp.should_interest AS shouldInterest,
rp.should_service_fee AS shouldServiceFee,
rp.should_penalty_interest AS shouldPenaltyInterest,
rp.should_late_fee AS shouldLateFee,
rp.fact_capital AS factCapital,
rp.fact_interest AS factInterest,
rp.fact_service_fee AS factServiceFee,
rp.fact_penalty_interest AS factPenaltyInterest,
rp.fact_late_fee AS factLateFee,
rp.should_balance AS shouldBalance,
rp.fact_balance AS factBalance,
rp.plan_state AS planState,
ca.availablel_cash AS availablelCash,
rp.is_settlement AS isSettlement,
CASE
WHEN rp.is_settlement = 1 THEN
(
SELECT
sum(r.should_interest)
FROM
repayment_plan r
WHERE
r.section_code > rp.section_code
AND r.auditing_info_Id = ai.auditing_info_Id
)
ELSE ''

END AS remainingInterest,
ai.periods,
rp.section_code AS sectionCode
FROM
auditing_info ai
LEFT JOIN contract_info ci ON ai.auditing_info_id = ci.auditing_info_Id
LEFT JOIN payment_record pr ON ai.auditing_info_id = pr.auditing_info_id AND pr.payment_state = 1
LEFT JOIN repayment_plan rp ON ai.auditing_info_id = rp.auditing_info_id
LEFT JOIN customer_account ca ON ai.auditing_info_id = ca.auditing_info_id
LEFT JOIN customer_info_snapshot cis ON ai.auditing_info_id = cis.auditing_info_id

解析:

这样在mysql中查询是没有问题的,但是在mybatis中,返回给dao 的值是一个对象的引用,由此判断可能mybatis涉及到case会将结果封装成一个对象,然后在else中返回''是varchar类型,所以造成的混乱,使mybaits将对象的引用返回了,我们只要将else中的''换为null或者是0就可以了。由此case中涉及到计算都要注意

你可能感兴趣的:(关于mybatis 使用case when 计算BigDecimal 数据返回对象的问题)