mysql if test的坑

时间:2022-06-17
本文章向大家介绍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>