<?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="Dao.UserDao"><resultMap id="result" type="model.User"><id column="id" property="id"/><result column="name" property="name"/><result column="age" property="age"/></resultMap><select id="select" parameterType="model.User" resultMap="result">
select * from user
<where><if test="name!=null">
name=#{name}</if><if test="age!=null">
and age=#{age}</if></where></select><insert id="insert" parameterType="model.User">
insert into user(name,age) values (#{name},#{age})</insert><update id="update" parameterType="model.User">
update user
<set><if test="name!=null">
name=#{name},</if><if test="age!=null">
age=#{age}</if></set>
where id=#{id}</update><delete id="deleteByArray" parameterType="int[]">
delete from user where id in
<foreach collection="array" item="id" open="(" close=")" separator=",">
#{id}</foreach></delete><delete id="deleteByList" parameterType="java.util.List">
delete from user where id in
<foreach collection="list" item="id" open="(" close=")" separator=",">
#{id}</foreach></delete><delete id="deleteByMap" parameterType="java.util.Map">
delete from user where id in
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}</foreach></delete></mapper>
sql语句drop table if exists user;create table user( id int primary key auto_increment, name varchar(20) not null unique, age int);实体类import lombok.Getter;import lombok.Setter;import lombok.ToString;/** * ClassName:User * Package:model