<!--列表查询--><selectid="selectLoanInfoList"parameterType="com.zyamc.debt.domain.LoanInfo"resultMap="LoanInfoResult">
select id, loaner_id, loanee_id, contract_number
from tbl_loan_info
<where><iftest="loanerId != null "> and loaner_id = #{loanerId} </if><iftest="loaneeId != null "> and loanee_id = #{loaneeId} </if><iftest="contractNumber != null and contractNumber != ''"> and contract_number like concat('%', #{contractNumber}, '%') </if></where>
order by `status` desc, expire_date asc
</select><!--遍历idList查询--><selectid="selectLoanInfoByIds"parameterType="Long"resultMap="LoanInfoResult"><includerefid="selectLoanInfoVo"/><where><iftest="ids != null and ids.size() != 0">
id in
<foreachcollection="ids"item="id"open="("separator=","close=")">
#{id}
</foreach></if></where></select><!--通过id查询--><selectid="selectLoanInfoById"parameterType="Long"resultMap="LoanInfoResult"flushCache="true"><includerefid="selectLoanInfoVo"/>
where id = #{id}
</select>
<!--根据id删除--><deleteid="deleteLoanInfoById"parameterType="Long">
delete
from tbl_loan_info where id = #{id}
</delete><!--根据ids(逗号隔开的字符串)删除--><deleteid="deleteLoanInfoByIds"parameterType="String">
delete from tbl_loan_info where id in
<foreachitem="id"collection="array"open="("separator=","close=")">
#{id}
</foreach></delete>
全文件
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.zyamc.debt.mapper.LoanInfoMapper"><resultMaptype="com.zyamc.debt.domain.LoanInfo"id="LoanInfoResult"><resultproperty="id"column="id"/><resultproperty="loanerId"column="loaner_id"/><resultproperty="loaneeId"column="loanee_id"/><resultproperty="contractNumber"column="contract_number"/></resultMap><sqlid="selectLoanInfoVo">
select id, loaner_id, loanee_id, contract_number
from tbl_loan_info
</sql><!--列表查询--><selectid="selectLoanInfoList"parameterType="com.zyamc.debt.domain.LoanInfo"resultMap="LoanInfoResult">
select id, loaner_id, loanee_id, contract_number
from tbl_loan_info
<where><iftest="loanerId != null "> and loaner_id = #{loanerId} </if><iftest="loaneeId != null "> and loanee_id = #{loaneeId} </if><iftest="contractNumber != null and contractNumber != ''"> and contract_number like concat('%', #{contractNumber}, '%') </if></where>
order by `status` desc, expire_date asc
</select><!--遍历idList查询--><selectid="selectLoanInfoByIds"parameterType="Long"resultMap="LoanInfoResult"><includerefid="selectLoanInfoVo"/><where><iftest="ids != null and ids.size() != 0">
id in
<foreachcollection="ids"item="id"open="("separator=","close=")">
#{id}
</foreach></if></where></select><!--通过id查询--><selectid="selectLoanInfoById"parameterType="Long"resultMap="LoanInfoResult"flushCache="true"><includerefid="selectLoanInfoVo"/>
where id = #{id}
</select><!--条件新增--><insertid="insertLoanInfo"parameterType="com.zyamc.debt.domain.LoanInfo"useGeneratedKeys="true"keyProperty="id">
insert into tbl_loan_info
<trimprefix="("suffix=")"suffixOverrides=","><iftest="loanerId != null">loaner_id, </if><iftest="loaneeId != null">loanee_id, </if><iftest="contractNumber != null and contractNumber != ''"> contract_number, </if></trim><trimprefix="values ("suffix=")"suffixOverrides=","><iftest="loanerId != null"> #{loanerId}, </if><iftest="loaneeId != null"> #{loaneeId}, </if><iftest="contractNumber != null and contractNumber != ''"> #{contractNumber}, </if></trim></insert><!--条件修改--><updateid="updateLoanInfo"parameterType="com.zyamc.debt.domain.LoanInfo">
update tbl_loan_info
<trimprefix="SET"suffixOverrides=","><iftest="loanerId != null"> loaner_id = #{loanerId}, </if><iftest="loaneeId != null"> loanee_id = #{loaneeId}, </if><iftest="contractNumber != null and contractNumber != ''"> contract_number = #{contractNumber}, </if></trim>
where id = #{id}
</update><!--根据id删除--><deleteid="deleteLoanInfoById"parameterType="Long">
delete
from tbl_loan_info where id = #{id}
</delete><!--根据ids(逗号隔开的字符串)删除--><deleteid="deleteLoanInfoByIds"parameterType="String">
delete from tbl_loan_info where id in
<foreachitem="id"collection="array"open="("separator=","close=")">
#{id}
</foreach></delete></mapper>
时间条件过滤举例
方式一:
<iftest="startDate != null"> and lend_date <![CDATA[>=]]> #{startDate}</if><iftest="endDate != null"> and lend_date <![CDATA[<=]]> #{endDate}</if>
方式二:
<iftest="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
</if><iftest="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
</if>