踩坑记录:input 使用需要注意的地方

多条件查询中,表单有多个input,type类型为text,这种input没有填入值的情况下传参到后台的是一个空字符串“”,而非null。

我这里写的是判断不为null,

<select id="findByMovie" parameterType="Movie"  resultType="Movie" >
        select * from t_movie where 1 = 1
        <if test="publishedTime != null">
            and published_time = #{publishedTime}
        </if>
        <if test="title != null">
            and title like concat('%', #{title}, '%')
        </if>
        <if test="director != null">
            and director like concat('%', #{director}, '%')
        </if>
        <if test="performer != null">
            and performer like concat('%', #{performer}, '%')
        </if>
</select>

然后因为type为text类型的input,传到后台默认的参数为一个空字符串"",所以不能达到我想要的效果。

然后我就在control中做了下面改动。

if("" == movie.getTitle())
     movie.setTitle( null );
if("" == movie.getDirector())
     movie.setDirector( null );
if("" == movie.getPerformer())
     movie.setPerformer( null );

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值