<?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.lwb.dao.IUserDao"><!-- 查询所有 --><select id="findAll" resultType="com.lwb.domain.User">
select * from user;</select><!-- 保存用户 --><insert id="saveUser" parameterType="com.lwb.domain.User"><!-- 配置插入操作后,获取插入数据的id --><selectKey keyProperty="id" keyColumn="id" resultType="int" order="AFTER">
select last_insert_id()</selectKey>
insert into user (username,address,sex,birthday) values (#{username},#{address},#{sex},#{birthday});</insert><!-- 更新用户 --><update id="updateUser" parameterType="com.lwb.domain.User">
update user set username=#{username},address=#{address},sex=#{sex},birthday=#{birthday} where id=#{id}</update><!-- 删除用户 --><delete id="deleteUser" parameterType="java.lang.Integer">
delete from user where id = #{uid}</delete><!-- 根据id查询用户 --><select id="findById" parameterType="INT" resultType="com.lwb.domain.User">
select * from user where id = #{id}</select><!-- 根据名称模糊查询 --><select id="findByName" parameterType="String" resultType="com.lwb.domain.User"><!-- 这种是预编译的情况prepareStatement -->
select * from user where username like#{name}<!--另一种写法使用Statement,字符串拼接,了解一下即可--><!--select * from user where username like '%${value}%'--></select><!-- 获取用户的总记录条数 --><select id="findTotal" resultType="int">
select count(id) from user
</select></mapper>