mysql if test的坑

在使用if test做判断时
mapper.xml中

    <if test="myType != null and myType != ''">
    //sql语句
    </if>

dao层

List<IssueInfo> findPage(@Param("myType")Integer myType, Page<IssueInfo> page);

如果按照上面的方式写,这个sql的条件是永远进不来的,因为这个myType是个Integer类型,他和空字符串不能比较,所以and 的后面永远是false。
正确方式是:

    <if test="myType != null">
    //sql语句
    </if>

猜你喜欢

转载自blog.csdn.net/weixin_39800144/article/details/80995580