三种请求路径:
1 .//"http://localhost:8080/myTMaven/courses/view?courserId=2"+@RequestParam("courserId")
2. //"http://localhost:8080/myTMaven/courses/view2/23"+@PathVariable("courserId")
3. //"http://localhost:8080/myTMaven/courses/view3?courserId=2"+request.getParameter("courserId")
三种model:
1. Model model
2. Map<String, Object> model
3. request.setAttribute("courseModel",courseModel);//request来作model
//"http://localhost:8080/myTMaven/courses/view?courserId=2"这样访问
@RequestMapping(value="view",method=RequestMethod.GET)public String viewCourser(@RequestParam("courserId") Integer courserId,Model model) {
CourseModel courseModel=courseService.getCourseModel(courserId);
model.addAttribute("courseModel",courseModel);
return "course_view";
}
//"http://localhost:8080/myTMaven/courses/view2/23"这样访问
@RequestMapping(value="/view2/{courserId}",method=RequestMethod.GET)
public String viewCourser2(@PathVariable("courserId") Integer courserId,Map<String, Object> model) {
CourseModel courseModel=courseService.getCourseModel(courserId);
model.put("courseModel",courseModel);
return "course_view";
}
//"http://localhost:8080/myTMaven/courses/view3?courserId=2"这样访问
@RequestMapping(value="view3",method=RequestMethod.GET)
public String viewCourser3(HttpServletRequest request) {
Integer courserId= Integer.parseInt(request.getParameter("courserId"));
CourseModel courseModel=courseService.getCourseModel(courserId);
request.setAttribute("courseModel",courseModel);
return "course_view";
}