发表于: 2018-02-26 23:46:10
1 411
今天完成的事情
1.初步完成SSM的整合
首先是控制器
@Controller
@RequestMapping({""})
public class StudentSController {
@Autowired
StudentSService studentSService;
public StudentSController(){}
@RequestMapping({"listStudentS"})
public ModelAndView listStudentS(){
ModelAndView mav = new ModelAndView();
List<StudentS> cs=studentSService.list();
// 放入转发参数
mav.addObject("cs", cs);
// 放入jsp路径
mav.setViewName("listStudentS");
return mav;
}
@RequestMapping("addStudentS")
public ModelAndView addStudentS(StudentS studentS){
studentSService.add(studentS);
ModelAndView mav=new ModelAndView("redirect:/listStudentS");
return mav;
}
@RequestMapping("deleteStudentS")
public ModelAndView deleteStudentS(StudentS studentS){
studentSService.delete(studentS);
ModelAndView mav = new ModelAndView("redirect:/listStudentS");
return mav;
}
@RequestMapping("updateStudentS")
public ModelAndView updateStudentS(StudentS studentS){
studentSService.update(studentS);
ModelAndView mav = new ModelAndView("redirect:/listStudentS");
return mav;
}
@RequestMapping("editStudentS")
public ModelAndView editStudentS(StudentS studentS) {
StudentS c = studentSService.get(studentS.getId());
if (null == c) {
ModelAndView mav = new ModelAndView("good");
mav.addObject("message", "用户不存在");
return mav;
}
ModelAndView mav = new ModelAndView("editStudentS");
mav.addObject("c",c);
return mav;
}
}
这是和昨天没有CRUD功能最大的区别
执行以后
点击删除最后一个ID为6
其他功能就不一一展示了,
明天计划的事情:
学习rest风格
遇到的问题
今天遇到的问题比较多,首先是在页面上出现了乱码,找了很多原因,最后在各位师兄大佬的努力下得到了解决,然后在实现查询功能中时,教程中并没有提供查询不存在时的情况,询问了师兄以后说可以用try catch,但是我对try catch不是很会用,最后使用了if。
收获
实现了SSM中的CRUD功能
评论