1、通过@RequestParam注解绑定参数
public String viewCourse(@RequestParam("courseId") Integer courseId, Map<String, Object> model){ log.debug("courseId=",courseId); Course course = courseService.getCourseById(courseId); model.put("course",course); return "course_overview"; }2、通过占位符绑定参数
@RequestMapping(value = "/view2/{courseId}") public String viewCourse2(@PathVariable("courseId") Integer courseId, Map<String, Object> model){ log.debug("courseId=",courseId); Course course = courseService.getCourseById(courseId); model.put("course",course); return "course_overview"; }
3、通过传统方式HttpServletRequest绑定参数
@RequestMapping(value = "/view3") public String viewCourse3(HttpServletRequest request){ Integer courseId = Integer.parseInt(request.getParameter("courseId")); Course course = courseService.getCourseById(courseId); request.setAttribute("course", course); return "course_overview"; }