Mybatis if test无效的原因(字符串比较)

转自:https://blog.csdn.net/qq_36014192/article/details/78213877?locationNum=4&fps=1

我在xml中写了如下sql:

 <if test="date!=null and date =='2'">
            //要执行的sql
        </if>

当传值date为2的时候并不执行这个if里的sql(date为String类型)

原因:test中字符串比较要用" ",而不是' '.sql改为:

 <if test='date!=null and date =="2"'>
           //要执行的sql
        </if>

猜你喜欢

转载自blog.csdn.net/Dongguabai/article/details/82995804