This is an example of using ThrowawayController in Spring MVC:
public class DisplayCourseController
implements ThrowawayController {
private Integer id;
public void setId(Integer id) { this.id = id; }
public ModelAndView execute() throws Exception {
Course course = courseService.getCourse(id);
return new ModelAndView("courseDetail", "course", course);
}
private CourseService courseService;
public void setCourseService(CourseService courseService) {
this.courseService = courseService;
}
}
With its declaration in the xml file:
<bean id="displayCourseController"
class="com.spring.mvc.DisplayCourseController"
singleton="false">
<property name="courseService">
<ref bean="courseService"/>
</property>
</bean>
Both of these two pieces of code do not specify how the parameter id in a request is found identified. Can anybody tell me how it works?
EDITED: I think the logic would probably be using getParameterNames() and getParameter() to retrieve all the parameters, and using java reflection to get the corresponding setter.
Thanks.