1.使用<foreach>标签遍历List集合
案例: 1)查询出代码在List<String> accountCodes列表中的所有值
mapper文件:
List<JournalLineAgeDTO> listGeneralLineAging(
RowBounds page,
@Param("ew") Wrapper<GeneralLedgerJournalLineDTO> wrapper,
List<String> accountCodes);
xml文件:
<select id="listGeneralLineAging" resultType="com.hand.hcf.app.accounting.web.dto.JournalLineAgeDTO">
select
l.*
from(
select
T.*,
IF (T.days >=0 and T.days <=90,T.days,"")day1,
IF (T.days >=91 and T.days<=180,T.days,"")day2,
IF (T.days >=181 and T.days<=360,T.days,"")day3,
IF (T.days >=361 and T.days<=720,T.days,"")day4,
IF (T.days >=721,T.days,"")day5
from(
select
g.transaction_number,STR_TO_DATE(g.accounting_date,"%Y-%m-%d")accounting_date,g.accounting_period,g.attribute2,CONCAT(g.account_code,"-",(select a.account_desc from fec_mdata.sys_accounts a where g.account_code=a.account_code))accountName,
g.entered_amount_dr,
g.entered_amount_cr,
g.account_code,
r.company_id,
DATEDIFF(now(),g.accounting_date)days
from gl_journal_line g,fec_expense.exp_report_header r
where g.transaction_number=r.requisition_number and r.status="1004" and g.entered_amount_dr is not null
<if test="accountCodes!=null and accountCodes.size()>0">
and g.account_code in
<foreach collection="accountCodes" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
union all
select
g.transaction_number,STR_TO_DATE(g.accounting_date,"%Y-%m-%d")accounting_date,g.accounting_period,g.attribute2,CONCAT(g.account_code,"-",(select a.account_desc from fec_mdata.sys_accounts a where g.account_code=a.account_code))accountName,
g.entered_amount_dr,
g.entered_amount_cr,
h.company_id,
g.account_code,
DATEDIFF(now(),g.accounting_date)days
from gl_journal_line g,fec_prepayment.csh_payment_requisition_head h
where g.transaction_number=h.requisition_number and h.status="1004" and g.entered_amount_dr is not null
union all
select
g.transaction_number,STR_TO_DATE(g.accounting_date,"%Y-%m-%d")accounting_date,g.accounting_period,g.attribute2,CONCAT(g.account_code,"-",(select a.account_desc from fec_mdata.sys_accounts a where g.account_code=a.account_code))accountName,
g.entered_amount_dr,
g.entered_amount_cr,
r.company_id,
g.account_code,
DATEDIFF(now(),g.accounting_date)days
from
gl_journal_line g,fec_expense.exp_report_header r
where g.transaction_number=r.requisition_number and
not EXISTS(select o.* from fec_payment.csh_write_off o where o.document_header_id=r.id)
and g.entered_amount_cr is not null
)T
)l
<where>
${ew.sqlSegment}
</where>
order by l.transaction_number asc
</select>