这是在Spring MVC使用ThrowawayController的例子:Spring MVC中的ThrowawayController如何从请求中获取参数?
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;
}
}
凭借其在XML文件中的声明:
<bean id="displayCourseController"
class="com.spring.mvc.DisplayCourseController"
singleton="false">
<property name="courseService">
<ref bean="courseService"/>
</property>
</bean>
这两个两段代码的不指定如何参数ID找到请求中的。任何人都可以告诉我它是如何工作的吗?
编辑: 我觉得逻辑可能会被使用getParameterNames()和的getParameter()检索所有参数,并使用Java反射来获取相应的setter。
谢谢。
如果你使用Spring 2.5,那么你不应该使用ThrowawayController,它将在Spring 3中被删除。 – skaffman
你们都提到它。我会牢记这一点。谢谢。 –