多条件查询中,表单有多个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 );