Mybatis批量操作配置文件UserMapper.xml

UserMapper.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.huawei.bbs.dao.inf.IUserDao">

    <select id="queryUserByName" parameterType="String" resultType="User">
        select uid, email, username, password from hw_common_member where username = #{name}
    </select>
    
    <select id="query" resultType="User">
        select uid, email, username, password from hw_common_member
    </select>
    
    <insert id="insert" parameterType="User">
        insert into hw_common_member(uid, email, username, password)
        values(#{uid}, #{email}, #{username}, #{password})
    </insert>
    
    <insert id="batchInsert" parameterType="User">
        insert into hw_common_member(uid, email, username, password) values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.uid}, #{item.email}, #{item.username}, #{item.password})
        </foreach>
    </insert>

    <update id="update" parameterType="User">
        update hw_common_member
        <set>
            username = #{username}, email = #{email}
        </set>
        where uid = #{uid}
    </update>
    
    <update id="batchUpdate" parameterType="User">
        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            update hw_common_member
            <set>
                username = #{item.username}, email = #{item.email}
            </set>
            where uid = #{item.uid}
        </foreach>
    </update>
    
    <delete id="delete" parameterType="User">
        delete from hw_common_member where uid =  #{uid}
    </delete>
    
    <delete id="batchDelete" parameterType="User">
        delete from hw_common_member where uid in
        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
            #{item.uid}
        </foreach>
    </delete>
    
    <delete id="batchDelete2" parameterType="java.util.Map">
        delete from hw_common_member where password = #{password} and uid in
        <foreach item="item" index="index" collection="uids" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>
    
</mapper>


上一篇:Python编写简单的谷歌翻译软件

下一篇:Python详细学习笔记+总结 第四天