<?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="org.hx.springboot_mybatis_demo27.mapper.UserMapper2"><resultMap id="UserMap" type="org.hx.springboot_mybatis_demo27.model.User"><id property="id" column="id"/><result property="name" column="name"/><result property="passwd" column="passwd"/></resultMap><select id="getUserById" resultMap="UserMap">
select * from t1 where id=#{id};</select><select id="getAllUsers" resultMap="UserMap">
select * from t1 ;</select><insert id="addUser" parameterType="org.hx.springboot_mybatis_demo27.model.User" useGeneratedKeys="true" keyProperty="id">
insert into t1 (name,passwd) values (#{name},#{passwd});</insert><delete id="deleteById">
delete from t1 where id=#{id};</delete><update id="updateById">
update t1 set name =#{name} where id=#{id};</update></mapper>
在测试类中加入代码
@Autowired
UserMapper2 userMapper2;@Testvoidtest2(){
User user=userMapper2.getUserById(113);
System.out.println(user);}@Testvoidtest3(){
List<User> user = userMapper2.getAllUsers();
System.out.println(user);
User u =newUser();
u.setName("hhh");
u.setPasswd("123456");
userMapper2.addUser(u);
System.out.println(u.getId());
userMapper2.deleteById(114);
userMapper2.updateById("韩星",112);}