<?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.csnf.mapper.StudentMapper">
  <resultMap id="BaseResultMap" type="com.csnf.entity.Student">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="sex" jdbcType="INTEGER" property="sex" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
  </resultMap>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from student
    where id = #{id,jdbcType=INTEGER}
  </delete>

  <insert id="insert" parameterType="com.csnf.entity.Student">
    <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.Integer">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into student (name, sex, phone)
    values (#{name,jdbcType=VARCHAR}, #{sex,jdbcType=INTEGER}, #{phone,jdbcType=VARCHAR})
  </insert>

  <update id="updateByPrimaryKey" parameterType="com.csnf.entity.Student">
    update student
    set name = #{name,jdbcType=VARCHAR},
        sex = #{sex,jdbcType=INTEGER},
        phone = #{phone,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select id, name, sex, phone
    from student
    where name = #{name,jdbcType=VARCHAR}
  </select>

  <select id="selectAll" resultMap="BaseResultMap">
    select id, name, sex, phone
    from student
  </select>
  <select id="selectByName" parameterType="map" resultMap="BaseResultMap">
    select id, name, sex, phone
    from student
    where name = #{name, jdbcType=VARCHAR} and phone = #{phone, jdbcType=VARCHAR}
  </select>

</mapper>
