1、<where></where>标签的作用

  • 可以动态的添加where关键字
  • 可以自动去掉第一个拼接条件的and关键字
          • 1      <where>
            2              <if test="username!=null and username!=''">
            3                 and username like '%${username}%'
            4              </if>
            5              <if test="gender!=null and gender!=''">
            6                  and gender='${gender}'
            7              </if>
            8          </where

 

2、<if></if>标签的作用

  • 根据传递过来的查询条件动态拼接sql语句
  • 【注意:通常在使用if标签标签判断非空时,记得一定要进行非空的判断】

 

3、<sql></sql>标签的作用

  • 将公共的查询条件进行封装
 1   <!-- 使用sql标签将查询条件封装,随意拼接-->
 2     <sql >
 3         <!-- 
 4             where标签的作用:
 5             1、可以动态的添加where关键字
 6             2、可以自动去掉第一个拼接条件的and关键字
 7          -->
 8         <where>
 9             <if test="username!=null and username!=''">
10                 and username like '%${username}%'
11             </if>
12             <if test="gender!=null and gender!=''">
13                 and gender='${gender}'
14             </if>
15         </where>
16     </sql>

 

4、<include></include>标签的作用

  • 引入sql标签封装的公共查询条件
1   <!-- 根据条件判断是否为空,来拼接条件查询结果 -->
2     <select >
3         select * from user 
4         <!-- 引入封装查询条件的SQL标签 -->
5         <include ref></include>
6     </select>

 

相关文章:

  • 2021-12-09
  • 2021-10-30
  • 2021-12-21
  • 2021-11-27
  • 2022-01-12
  • 2021-05-14
  • 2022-12-23
  • 2021-12-03
猜你喜欢
  • 2022-02-09
  • 2021-04-23
  • 2021-08-02
  • 2021-10-12
相关资源
相似解决方案