select * from t_rule_rebate t where 1=1and t.merchantid = #{merchantId}and t.ztbz = #{ztbz}and t.type = #{type}<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="ActRebateMapper">
<resultMap type="ActRebate" id="actRebateResultMap">
<result column="MERCHANTID" property="merchantId" />
<result column="STYPE" property="stype" />
<result column="RULE_AMT" property="rule_amt" />
<result column="KSRQ" property="ksrq" />
<result column="JSRQ" property="jsrq" />
<result column="ZTBZ" property="ztbz" />
<result column="ACC_AMT" property="acc_amt" />
<result column="BZ" property="bz" />
</resultMap>
<select id="getList" parameterType="ActRebate" resultType="ActRebate">
select * from t_rule_rebate t where 1=1
<if test="merchantId !=null and merchantId !=''"> and t.merchantid = #{merchantId}</if>
<if test="ztbz!=null and ztbz!=''"> and t.ztbz = #{ztbz}</if>
<if test="type!=null and type!=''"> and t.type = #{type}</if>
</select>
</mapper>
问题解决了:我的数据库的表的字段的数据类型是char类型的,问题就出现在这里,所以在条件里头作比较的时候我应该先使用trim函数去除多余的空格,所以我就把sql语句改成如下:
<select id="getList" parameterType="ActRebate" resultMap="actRebateResultMap">
select t.* from t_rule_rebate t where 1=1
<if test="merchantId !=null and merchantId !=''"> and t.merchantid = trim(#{merchantId})</if>
<if test="ztbz!=null and ztbz!=''"> and trim(t.ztbz) = #{ztbz} </if>
<if test="type!=null and type!=''"> and trim(t.type) = #{type} </if>
</select>
select t.* from t_rule_rebate t where (merchantId IS null OR t.merchantid = #{merchantId} )
AND (ztbz IS null OR trim(t.ztbz) = #{ztbz})
AND (type IS null OR trim(t.type) = #{type})
</select>
传进去的参数就不要在SQL中做处理了。。。。参数在传之前处理。
大概这样吧,请参考。追问
报错了:
Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型: 1111