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>
    复制代码
  • 相关阅读:
    Servlet概述
    JAVA WEB开发环境与搭建
    Java scirpt简介
    用HTML+CSS编写一个计科院网站首页的静态网页
    CSS样式
    HTML简介
    Web服务器的原理
    静态网页与动态网页的区别
    debugger工具的使用以及调试
    javascript页面刷新的几种方法
  • 原文地址:https://www.cnblogs.com/wangchaoyuana/p/7545228.html
Copyright © 2011-2022 走看看