首页 > 数据库技术 > 详细

Mybatis入门之动态sql

时间:2019-03-01 11:18:23      阅读:166      评论:0      收藏:0      [点我收藏+]

Mybatis入门之动态sql

    通过mybatis提供的各种标签方法实现动态拼接sql。

  1、if、where、sql、include标签(条件、sql片段)

<sql id="selector">
        select * from account
</sql>

<!--根据性别和名称查询用户 where标签可以去掉第一个前and -->
    <select id="selectUserBySexAndUsername" parameterType="deep.pojo.Account"
        resultType="deep.pojo.Account">
        <include refid="selector"/>
        <where>
            <if test="sex != null and sex != ‘‘ ">
                sex = #{sex}
            </if>
            <if test="username != null and username !=‘‘">
                and username = #{username}
            </if>
        </where>
    </select>

 

Mybatis入门之动态sql

原文:https://www.cnblogs.com/deepSleeping/p/10455193.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!