zoukankan      html  css  js  c++  java
  • 【MyBatis】动态 SQL

    【MyBatis】动态 SQL

    转载:

    目录

    ==========================================

    1、if

    2、choose when otherwise

    3、trim where set

    4、foreach

    5、bind

    ==========================================

    1、if

        <select id="selectAuthor" resultType="Author">
            select * from author where sex = 'male'
            <if test="name != null">
                and name = #{name}
            </if>
        </select>

    5、bind

    基本参数

    public List<Blog> selectBlogList(@Param("title") String title);
        <select id="selectBlogList" resultType="Blog">
            <bind name="titlePattern" value="'%' + title + '%'"/>
            select * from blog 
            <where>
                <if test="title != null">
                and title like #{titlePattern}
                </if>
            </where>
        </select>

    对象参数

    public List<Blog> selectBlogList(Blog blog);
    <select id="selectBlogList" resultType="Blog">
            <bind name="titlePattern" value="'%' + _parameter.getTitle() + '%'"/>
            select * from blog 
            <where>
                <if test="title != null">
                and title like #{titlePattern}
                </if>
            </where>
        </select>
  • 相关阅读:
    数组与方法
    数据类型
    认识Java(2)
    认识Java(1)
    面试题集锦
    00-python语言介绍
    06-python-生成器、循环器
    00-python-内置函数笔记
    04-python-闭包
    03-python-装饰器
  • 原文地址:https://www.cnblogs.com/yangchongxing/p/10498669.html
Copyright © 2011-2022 走看看