• 【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>
  • 相关阅读:
    Node.js Express 框架
    Node.js RESTful API
    vim中自动格式化代码
    如何去掉linux配置文件的注释行和空行
    ImmutableJS
    JavaScript的相关知识
    React容器组件和展示组件
    node.js
    svg学习
    Redux 基础概念
  • 原文地址:https://www.cnblogs.com/yangchongxing/p/10498669.html
Copyright © 2020-2023  润新知