pojo层·
package com.example.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class User {
private int id;
private String name;
private String pwd;
}
mapper层
package com.example.mapper;
import com.example.pojo.User;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface UserMapper {
/**
* 查
* @return
*/
List<User>queryUser();
/**
* 增
* @param user
* @return
*/
int addUser(User user);
/**
* 修改
* @param user
* @return
*/
int updateUser(User user);
/**
* 删除
* @param id
* @return
*/
int deleteUser(@Param("id") int id);
}
mapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mapper.UserMapper">
<select id="queryUser" resultType="com.example.pojo.User">
select * from user
</select>
<insert id="addUser" parameterType="com.example.pojo.User">
insert into user(id,name,pwd) values (null,#{name},#{pwd})
</insert>
<update id="updateUser" parameterType="com.example.pojo.User">
update user set name=#{name},pwd=#{pwd} where id=#{id}
</update>
<delete id="deleteUser" parameterType="int">
delete from user where id=#{id}
</delete>
</mapper>
service层
package com.example.servict;
import com.example.pojo.User;
import org.apache.ibatis.annot