1.增
<insert id="insert" parameterType="com.itheima.cn.Student">
<selectKey keyProperty="id" resultType="String" order="BEFORE">SELECT REPLACE(NEWID(),'-','')</selectKey>
INSERT INTO student (stuId,stuName,createDate,birthday)
VALUES
( #{id,jdbcType=VARCHAR},#{stuName,jdbcType=VARCHAR},
{createDate,jdbcType=DATE}, #{birthday,jdbcType=TIMESTAMP})
</insert>
2.删
<delete id="delete">DELETE FROM student WHERE ID IN
<foreach
item="stuId" collection="list" open="(" separator="," close=")">
#{stuId,jdbcType=VARCHAR}
</foreach>
</delete>
3.改
<update id="update" parameterType="com.itheima.cn.Student">UPDATE student
<set>
<if test="stuId!= null">stuId=#{stuId,jdbcType=VARCHAR},</if>
<if test="stuName!= null">stuName=#{stuName,jdbcType=VARCHAR},</if>
<if test="createDate!= null">createDate=#{createDate,jdbcType=DATE},</if>
<if test="birthday!= null">birthday=#{birthday,jdbcType=TIMESTAMP}</if>
</set> WHERE ID=#{id}
</update>
4.基本查询
<resultMap id="student" type="com.itheima.cn.Student">
<id property="stuId" column="stuId"/>
<result property="stuName" column="stuName"/>
<result property="createDate" column="createDate"/>
</resultMap>
<select id="list" resultMap="student" parameterType="map">
SELECT stuId,stuName,createDate,birthday FROM student
<where>
<if test="stuId!= null and stuId!=''">AND stuId LIKE '%'+#{stuId}+'%'</if>
<if test="stuName!= null and stuName!=''">AND stuName LIKE '%'+#{stuName}+'%'</if>
<if test="ids!= null and ids!=''">AND stuId in
<foreach collection="ids" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</where>
</select>
笔记一