目录结构图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/8f62dd2b51752363e937cf9d4139424e.png#pic_center)
实体类
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
public class User {
private Integer id;
private String name;
private Integer age;
private String sex;
}
dao接口
package dangwei.dao;
import dangwei.model.User;
import java.util.List;
public interface UserMapper {
List<User> selectAllUser();
void insert(User user);
void delete(Integer id);
void update(User user);
}
service接口
import dangwei.model.User;
import java.util.List;
public interface UserService {
List<User> selectAllUser();
void insert(User user);
void delete(Integer id);
void update(User user);
}
service接口实现类
package dangwei.service;
import dangwei.dao.UserMapper;
import dangwei.model.User;
import java.util.List;
public class UserServiceImpl implements UserService{
private UserMapper userMapper;
public void setUserMapper(UserMapper userMapper){
this.userMapper=userMapper;
}
public List<User> selectAllUser() {
return userMapper.selectAllUser();
}
public void insert(User user) {
userMapper.insert(user);
}
public void delete(Integer id) {
userMapper.delete(id);
}
public void update(User user) {
userMapper.update(user);
}
}
controller层
package dangwei.controller;
import dangwei.model.User;
import dangwei.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;