请写出@Mapper public interface UsersMapper { @Select("select * from users") List<Users> findAll(); @Insert("insert into users(name,salary) values(#{name},#{salary})") @Delete("DELETE FROM users WHERE id = #{id}") @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class) void insert(Users users); } 的相应的XML文件
时间: 2023-06-16 20:03:00 浏览: 85
以下是对应的XML文件:
```xml
<?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.example.mapper.UsersMapper">
<resultMap id="userResultMap" type="com.example.model.Users">
<id property="id" column="id" />
<result property="name" column="name" />
<result property="salary" column="salary" />
</resultMap>
<select id="findAll" resultMap="userResultMap">
select * from users
</select>
<insert id="insert">
insert into users(name, salary) values(#{name}, #{salary})
<selectKey statement="SELECT LAST_INSERT_ID()" keyProperty="id" order="AFTER" resultType="java.lang.Integer"/>
</insert>
<delete id="deleteById">
DELETE FROM users WHERE id = #{id}
</delete>
</mapper>
```
其中,`resultMap` 定义了查询结果映射到 Java 对象的方式,`select` 定义了查询语句,`insert` 定义了插入语句,`selectKey` 用于获取插入数据后自动生成的 ID,`delete` 定义了删除语句。这些语句的 ID 对应了 Java 接口中定义的方法名,MyBatis 会自动将其绑定起来。
阅读全文