1. 程式人生 > 實用技巧 >xml檔案sql查詢

xml檔案sql查詢

例,根據篩選條件查詢付款明細,用到的表:

  表名稱             別名   註釋

fund_payment               pay      付款明細主表
fund_corporation_info          cor_info   法人公司資訊表
fund_payment_instruction        pay_inst   付款指令表

需要在通用查詢對映結果加上:
<result column="name" property="corporationName" />
<result column="document" property="instructionDocument" />

<select id="listPayment" resultMap="BaseResultMap">
SELECT
cor_info.name,
pay_inst.document,
<include refid="Base_Column_List"></include>
FROM
fund_payment pay
LEFT JOIN fund_corporation_info cor_info ON pay.company_code = cor_info.id_code
LEFT JOIN fund_payment_instruction pay_inst ON pay.payment_instruction_id = pay_inst.id
WHERE pay.deleted = 0
<if test="payment.companyCode != null">
AND pay.company_code = #{payment.companyCode}
</if>
<if test="payment.source != null">
AND pay.source = #{payment.source}
</if>
<if test="payment.payee != null">
AND pay.payee like concat('%',#{payment.payee},'%')
</if>
   <if test="payment.endPayment != null and payment.endPayment != ''">
AND pay.amount &lt;= #{payment.endPayment}
   </if>
   <if test="payment.beginPayment != null and payment.beginPayment != ''">
        AND pay.amount &gt;= #{payment.beginPayment}
</if>
ORDER BY pay.created_date DESC
</select>