zoukankan      html  css  js  c++  java
  • trim标签&&MyBatis内置参数

    SQL标签:<trim>

    <where>可以处理拼接sql中 【开头】第一个and

    <trim>可以处理拼接sql中 【开头或结尾】第一个and

    开头:给拼接的sql加prefix="where" suffixOverrides="and",处理拼接sql中开头第一个and

    <select id="queryStudentByNoWithONGL" parameterType="student" resultType="student">
            select * from student1
            <trim prefix="where" prefixOverrides="and">
                <if test="stuName != null and stuName != '' ">
                    and stuName like  '%${stuName}%'
                </if>
                <if test="graName != null and graName != '' ">
                    and graName like  '%${graName}%'
                </if>
                <if test="stuAge != null and stuAge != '' ">
                    and stuAge like  '%${stuAge}%'
                </if>
            </trim>
        </select>

     结尾

    <select id="queryStudentByNoWithONGL" parameterType="student" resultType="student">
            select * from student1
            <trim prefix="where" suffixOverrides="and">
                <if test="stuName != null and stuName != '' ">
                    stuName like  '%${stuName}%' and
                </if>
                <if test="graName != null and graName != '' ">
                    graName like  '%${graName}%' and
                </if>
                <if test="stuAge != null and stuAge != '' ">
                    stuAge =  #{stuAge} and
                </if>
            </trim>
        </select>

    predix:拼接  prefixOverrides:删除

    内置参数:

      _parameter:代表mybatis的输入参数

    <select id="queryStudentByNoWithONGL" parameterType="student" resultType="student">
            /*select * from student1 where 1=1*/
            select * from student1
            <trim prefix="where" suffixOverrides="and">
                <if test="_parameter.stuName != null and _parameter.stuName != '' ">
                    stuName like  '%${_parameter.stuName}%' and
                </if>
                <if test="graName != null and graName != '' ">
                    graName like  '%${graName}%' and
                </if>
                <if test="stuAge != null and stuAge != '' ">
                    stuAge =  #{stuAge} and
                </if>
            </trim>
        </select>

      _datebaseId:代表当前数据库的名字

  • 相关阅读:
    一致性哈希算法
    Discourse 的标签(Tag)只能是小写的原因
    JIRA 链接 bitbucket 提示错误 Invalid OAuth credentials
    JIRA 如何连接到云平台的 bitbucket
    Apache Druid 能够支持即席查询
    如何在 Discourse 中配置使用 GitHub 登录和创建用户
    Apache Druid 是什么
    Xshell 如何导入 PuTTYgen 生成的 key
    windows下配置Nginx支持php
    laravel连接数据库提示mysql_connect() :Connection refused...
  • 原文地址:https://www.cnblogs.com/mayouyou/p/13267749.html
Copyright © 2011-2022 走看看