当前位置: 首页 > 工具软件 > mysqltest > 使用案例 >

mysql if test的坑

邰勇军
2023-12-01

在使用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>
 类似资料: