About MyBatis using case when to calculate BigDecimal data return object

Source: Internet
Author: User

Example:

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

Analytical:

There's no problem with querying in MySQL, but in MyBatis, the value returned to DAO is a reference to an object, so it's possible that mybatis involves a case that encapsulates the result into an object, and then returns ' in the Else ' is a varchar type, so the confusion is caused, Causes Mybaits to return the object's reference, as long as we change the "else" to null or to 0. It is important to note that the calculations involved in this case

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.