zoukankan      html  css  js  c++  java
  • mybatis_常用标签

    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 id="user_where">
     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 id="findByUsernameAndGender" parameterType="com.itheima.mybatis.pojo.User" resultType="com.itheima.mybatis.pojo.User">
    3         select * from user 
    4         <!-- 引入封装查询条件的SQL标签 -->
    5         <include refid="user_where"></include>
    6     </select>
    复制代码
  • 相关阅读:
    [bzoj5483][Usaco2018 Dec]Balance Beam_凸包_概率期望
    [bzoj3829][Poi2014]FarmCraft_树形dp
    [bzoj3420]Poi2013 Triumphal arch_树形dp_二分
    [bzoj4240]有趣的家庭菜园_树状数组
    [CF9D]How Many Trees?_动态规划_树形dp_ntt
    拖拽排序
    windows-build-tools
    阿里云七牛云oss获取视频内的帧图片
    转义符输入的转换
    node脚本下载geo数据
  • 原文地址:https://www.cnblogs.com/wangchaoyuana/p/7545228.html
Copyright © 2011-2022 走看看