<?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.ces.mybatis.dao.IUserDao">

    <resultMap id="BaseResultMap" type="com.ces.mybatis.model.User">
        <id column="user_id" property="userId" />
        <result column="user_name" property="userName" />
        <result column="password" property="password" />
        <result column="context" property="context" typeHandler="com.ces.mybatis.typeHandler.ContentTypeHandler"/>
    </resultMap>
    
    
    
    
    <insert id="insert" useGeneratedKeys="true" keyProperty="userId" keyColumn="user_id" parameterType="com.ces.mybatis.model.User">
        insert into t_sys_user(user_id,user_name,password,context) values(#{userId},#{userName},#{password},#{context})
    </insert>

	<insert id="insertOrUpdateByBatch" keyProperty="userId" useGeneratedKeys="true" keyColumn="user_id" >
	insert into t_sys_user (user_id,user_name,password,context)
	VALUES
        <foreach item="user" index= "index" collection ="list" separator ="),(" open="(" close=")">
			user.userId,user.userName,user.password,user.context
        </foreach>
        	ON DUPLICATE KEY UPDATE
				user_name = VALUES(user_name)
				password = VALUES(password)
				context = VALUES(context)
	</insert>
	
	
	
	
    <update id="update" parameterType="com.ces.mybatis.model.User">
       update t_sys_user
       <set>
           <if test="userName != null">user_name=#{userName},</if>
           <if test="password != null">password=#{password},</if>
           <if test="context != null">context=#{context},</if>
       </set>
        where user_id=#{userId}
    </update>




    <delete id="delete">
        delete from t_sys_user where user_id=#{userId}
    </delete>





    <select id="getAll" resultType="com.ces.mybatis.model.User" >
       select user_id,user_name,password,context from t_sys_user order by user_id desc
    </select>





    <select id="find" resultType="com.ces.mybatis.model.User" >
        select user_id,user_name,password,context  from t_sys_user where user_id = #{userId}
    </select>

</mapper>