我是靠谱客的博主 清秀大雁,最近开发中收集的这篇文章主要介绍关于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 数据返回对象的问题的全部内容,希望文章能够帮你解决关于mybatis 使用case when 计算BigDecimal 数据返回对象的问题所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部