mybatis where and or
- 作者: 像我这样叼的有七个
- 来源: 51数据库
- 2020-10-03
相当于sql语句中的where关键字。 这个标签还有一个功能就是自动会去掉第一个and.,比如下面两句sql代码,如果第一个满足的那么就会去掉and这个关键字。 --> and user.sex= #{userCustom.sex} and user.username=#{userCustom.username}
where标签为mybatis的动态语句。
上述代码中若where标签里的if全不成立,则不走where语句。
若第一个if标签里id的值为null的话,那么打印出来的sql为:select * from user where name=”xx” and gender=”xx”
会把and/or自动忽略掉。
若直接用where子句的话可能会导致sql语法错误,查询失败。
where标签为mybatis的动态语句。
上述代码中若where标签里的if全不成立,则不走where语句。
若第一个if标签里id的值为null的话,那么打印出来的sql为:select * from user where name=”xx” and gender=”xx”
会把and/or自动忽略掉。
若直接用where子句的话可能会导致sql语法错误,查询失败。
推荐阅读