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>
上一篇:mysql 根据where条件,分组,联表等统计数据条数


下一篇:Django中的文件操作