1. 程式人生 > >mybatis---mapper.xml檔案

mybatis---mapper.xml檔案

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.it.mybaties.mapper.UserMapper">
  <select id="getUserById" resultType="com.it.mybaties.pojo.User" parameterType="Integer">
  	select * from user where id=#{id}
  </select>
  
  <select id="getUserByUsername" parameterType="String" resultType="com.it.mybaties.pojo.User">
  	<!-- 用$符號時,只能用value 其他都是錯 -->
  	<!-- select * from user where username like '%${value}%' -->
  	<!-- #號裡隨便寫什麼 -->
  	select * from user where username like "%"#{username}"%"
  </select>
  
  <insert id="insertUser" parameterType="com.it.mybaties.pojo.User">
  	<selectKey keyProperty="id" resultType="Integer" order="AFTER">
  		select LAST_INSERT_ID()
  	</selectKey>
  	insert into user (username,sex,birthday,address) values (#{username},#{sex},#{birthday},#{address})
  </insert>
  
  <update id="updateUser" parameterType="com.it.mybaties.pojo.User">
  	update user set username=#{username},sex=#{sex},birthday=#{birthday},address=#{address}  where id=#{id}
  </update>
  
  <delete id="deleteUser" parameterType="Integer">
  	delete from user where id=#{id}
  </delete>
  
  
</mapper>