MyBatis 增删改查

增 返回id 

// 增 返回id 
<insert id="addPic" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO table
        (photo_address,photo_description)
        VALUES
        (#{paramCondition.photoAddress},#{paramCondition.photoDescription})
</insert>

批量添加

<insert id="insertBatch">
        insert into table
        (photo_address,photo_description)
        values 
        <foreach collection="param" separator="," item="item">
            (#{item.photoAddress},#{item.photoDescription})
        </foreach>
</insert>

<delete id="delPic" parameterType="int">
        DELETE FROM table WHERE id=#{id}
</delete>

批量删

<delete id="delPic" >
       DELETE FROM table WHERE id IN (${ids})
</delete>

<update id="updPic" >
     UPDATE table
     SET photo_address=#{paramCondition.photoAddress},photo_description=#{paramCondition.photoDescription}
     WHERE id=#{paramCondition.id}
 </update>

批量改

<update id="updateBatch" parameterType="java.util.List">
        <foreach collection="list" item="item" separator=";">
            update table set photo_address=#{item.photoAddress},photo_description=#{item.photoDescription}
            where id=#{item.id}
        </foreach>
</update>

<select id="customMapList" resultType="cn.stylefeng.guns.modular.DemoPro.model.result.DemoResult" parameterType="cn.stylefeng.guns.modular.DemoPro.model.params.DemoParam">
        select <include refid="Base_Column_List"/>
        from table where 1 = 1
</select>

In

<select id="costomList" parameterType="java.util.ArrayList" resultType="cn.stylefeng.guns.DemoPro.model.result.DemoResult">
     select * from table where id in
     <foreach collection="array" index="index" item="item" open="(" separator="," close=")">
          #{item}
     </foreach>
 </select> 
 

 

@

 

posted @ 2019-12-20 10:45  DarGi  阅读(262)  评论(0编辑  收藏  举报