JAVA-MyBaits对应XML的两种使用方式
概述
在使用XML写SQL语句的时候,遇到参数传递的两种方式,也就是Mapper里面带@Param注解和不带的情况,容易混淆,对应XML的写法也不相同,使用的时候要注意对照代码比对(备注XML里面的关键字containsKey,大小写都需要正确)
Mapper代码:
List<InIncome101Report> queryListByPeriod(Page<InIncome101Report> page, Map<String,Object> params);//非注解@Param List<InIncome101Report> queryListByVoucherdata(Page<InIncome101Report> page, @Param("params") Map<String,Object> params);//带注解的
XML内容
1、非@param
<select id="queryListByPeriod" resultType="com.dbgo.acme.report.domain.model.InIncome101Report"> SELECT T.supplier_name supplierName, T.supplier_tax_code supplierTaxcode, COUNT (0) sumCount FROM tbl_in_incomedetail T WHERE T.org_id = #{orgId} <if test="_parameter.containsKey('periodstart')"> AND T.tax_period>= #{periodstart} </if> <if test="_parameter.containsKey('periodend')"> AND T.tax_period <![CDATA[<=]]>#{periodend} </if> GROUP BY T.supplier_name, T.supplier_tax_code </select>
2、带@param
<select id="queryListByVoucherdata" resultType="com.dbgo.acme.report.domain.model.InIncome101Report"> SELECT T.suppliername supplierName, T.suppliertax_code supplierTaxcode, FROM tbl_in_incomedetail T WHERE T.org_id = #{params.orgId} AND T.vouchedata >=#{params.start} AND T.vouchedata <![CDATA[<=]]>#{params.end} GROUP BY T.suppliername , T.suppliertax_code </select>