SQL片段抽取

Sql 中可将重复的 sql 提取出来,使用时用 include 引用即可,最终达到 sql 重用的目的

    <sql id="select_User">
         select * from User
    </sql>
    <!--    if的使用-->
    <select id="findByCondition" parameterType="com.domain.User" resultType="com.domain.User">
        <include refid="select_User"></include>
        <where>
            <if test="id!=0">
                and id=${id}
            </if>
            <if test="username!=null">
                and username='${username}'
            </if>
            <if test="password!=null">
                and password='${password}'
            </if>
        </where>
    </select>
posted @ 2021-02-22 18:07  西红柿里没有番茄  阅读(97)  评论(0编辑  收藏  举报