MyBatis之动态SQL

 

<mapper namespace="mapper.ICategory">

    

    <select id="selectAll" resultType="pojo.Category">

        SELECT

            id,

            name

        FROM category

    </select>

    <insert id="insert" parameterType="pojo.Category">

        INSERT INTO category (name) VALUES (#{name})

    </insert>



    <select id="selectlike" resultType="pojo.Category">

        SELECT * FROM category WHERE id>2

        <if test="name !=null">

            <bind name="_name" value="'%'+name+'%'"></bind>

            AND name LIKE #{_name}

        </if>

  

--      相当于swich case



        <choose>

            <when test="">



            </when>

            <otherwise>



            </otherwise>

        </choose>

    </select>

    <!--动态添加SQL语句-->

    <update id="XXX">

        UPDATE category

        <set>

            <if test="name!=null">ename=#{ename},</if>

        </set>

        WHERE id=#{id}

    </update>

    

    <delete id="delete">

        delete from user where id IN

        # 如果foreach操作数组或集合时,collection根据传入对象决定是array或list,与参数名无关

        # public void delete(int[] id);

        <foreach collection="array" item="id" open="(" separator="," close=")">

            #{id}

        </foreach>

    </delete>

</mapper>

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值