@Mapper //也可以在启动类添加 @MapperScan("com.it.mapper")
@Repository
publicinterfaceUserMapper{
List<User>queryUserList();
User queryUserById(int id);
int addUser(User user);
int updateUser(User user);
int deleteUser(int id);}
在Resources目录下编写接口配置文件
<?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.it.mapper"><select id="queryUserList" resultType="User">
select *from user
</select><select id="queryUserById" resultType="User">
select *from user where id = #{id}</select><insert id=" addUser" parameterType="User">
insert into user(id,username,password)values(#{id}, #{username},#{password})</insert><update id="updateUser" parameterType="User">
update user set username=#{username},password=#{password} where id = #{id}</update><delete id="deleteUser" parameterType="int">deletefrom user where id = #{id}</delete></mapper>