<?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="test.dao.UserDao" >
  <resultMap id="BaseResultMap" type="test.model.User" >
    <id column="store_id" property="storeId" jdbcType="BIGINT" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="role" property="role" jdbcType="BIGINT" />
    <result column="mobile" property="mobile" jdbcType="VARCHAR" />
  </resultMap>
  
<insert id="insert" parameterType="test.model.User">
  	insert into u_user
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="userId != null" >
        user_id,
      </if>
      <if test="name != null" >
        name,
      </if>
      <if test="role != null" >
        role,
      </if>
      <if test="mobile != null" >
        mobile,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="userId != null" >
        #{userId,jdbcType=BIGINT},
      </if>
      <if test="name != null" >
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="role != null" >
        #{role,jdbcType=BIGINT},
      </if>
      <if test="mobile != null" >
        #{mobile,jdbcType=VARCHAR},
      </if>
    </trim>
    <selectKey resultType="java.lang.Long" keyProperty="userId">  
      <![CDATA[SELECT LAST_INSERT_ID() AS user_id ]]>
    </selectKey>
</insert>