1、在DAO层接口声明增删改查
2、在controller层实现函数
@Controller
@RequestMapping(“user”)
public class UserController {
@Autowired
private IUserDao userDao;
@RequestMapping("/all")
public String all(Model model) {
List users=userDao.getUsers();
//键值对形式添加进model
model.addAttribute(“users”, users);
return “index”;
}
@RequestMapping("/insert")
public String insert(Model model) {
userDao.insertUser();
List users=userDao.getUsers();
//键值对形式添加进model
model.addAttribute(“users”, users);
return “index”;
}
@RequestMapping("/delete")
public String delete(Model model) {
userDao.deleteUser();
List users=userDao.getUsers();
//键值对形式添加进model
model.addAttribute(“users”, users);
return “index”;
}
@RequestMapping("/update")
public String update(Model model) {
userDao.updateUser();
List users=userDao.getUsers();
//键值对形式添加进model
model.addAttribute(“users”, users);
return “index”;
}
}
3、在resources.mapper文件中添加SQL语句
4、在jsp文件index.jsp中编写按键
5、运行测试