美文网首页
mybatis 动态sql

mybatis 动态sql

作者: 开发猛男 | 来源:发表于2019-06-27 12:00 被阅读0次
  • where if
    <select id="findUsersByNameAndSex" parameterType="com.itheima.pojo.User" resultType="com.itheima.pojo.User">
        select * from user
        <where>
            <if test="name!=null and name!=''">
                and name like '%${name}%'
            </if>
            <if test="sex!=null and sex!=''">
                and sex =#{sex}
            </if>
        </where>
    </select>
  • for each
    <select id="findUsersByIds" parameterType="com.itheima.vo.QueryVo" resultType="com.itheima.pojo.User">
        select * from user 
        <where>
            <if test="ids!=null and ids.size>0">
                <foreach collection="ids"  item="id" open="id in (" close=")" separator="," >
                    #{id}
                </foreach>
            </if>
        </where>
    </select>
  • sql
    定义sql段
<sql id="query_user_where">
    <if test="id!=null and id!=''">
        and id=#{id}
    </if>
    <if test="username!=null and username!=''">
        and username like '%${username}%'
    </if>
</sql>
<!-- 传递pojo综合查询用户信息 引用sql段 -->
    <select id="findUserList" parameterType="user" resultType="user">
        select * from user 
        <where>
        <include refid="query_user_where"/>
        </where>
    </select>

相关文章

  • MyBatis动态SQL

    MyBatis 动态SQL 内容 Mybatis动态SQL在XML中支持的几种标签: if chose trim、...

  • MyBatis核心知识点

    (1)Mybatis动态sql是做什么的?都有哪些动态sql?能简述一下动态sql的执行原理不? Mybatis动...

  • MyBatis 动态SQL(*.xml)

    原文参考MyBatis 动态SQL MyBatis的动态SQL大大减少了拼接SQL语句时候的各种格式问题,这里摘录...

  • Mybatis动态SQL

    MyBatis Mybatis笔记连载上篇连接MyBatis缓存Mybatis笔记连载下篇连接 动态SQL 动态S...

  • MyBatis的动态SQL与日志Log4J、SQL语句构造器

    一、MyBatis动态SQL 动态 SQL 是 MyBatis 的强大特性之一。如果你使用过 JDBC 或其它类似...

  • MyBatis学习:动态sql

    1.动态sql 动态sql是mybatis中的一个核心,什么是动态sql?动态sql即对sql语句进行灵活操作,通...

  • mybatis的xml文件的标签详解

    Mybatis #{}和${}和区别 mybatis获取方法参数 动态SQL

  • 第八章 动态SQL

    动态SQL中的元素介绍 动态SQL有什么作用 MyBatis提供了对SQL语句动态组装的功能 动态SQL中的元素 ...

  • JavaEE基础知识学习----MyBatis(四)动态SQL

    MyBatis的动态SQL MyBatis 的强大特性之一便是它的动态 SQL。如果你有使用 JDBC 或其它类似...

  • IT 每日一结

    mybatis动态sql 动态sql绝对是mybatis排列前几的闪光点之一。传统代码中的sql语句需要经过多个字...

网友评论

      本文标题:mybatis 动态sql

      本文链接:https://www.haomeiwen.com/subject/atwlcctx.html