我是 Spring MVC 的初学者。所以我不明白控制流是从控制器类到 training-servlet.xml,反之亦然。contextConfigLocation 文件(training-servlet.xml)解释为:
<beans:bean id="userService" class="com.my.control.UserServiceImpl" />
<beans:bean name="/userRegistration.htm" class="com.my.control.HomeController">
<beans:property name="validator">
<beans:bean class="com.my.validations.HomeValidations" />
</beans:property>
<beans:property name="userService" ref="userService"></beans:property>
<beans:property name="formView" value="userForm"></beans:property>
<beans:property name="successView" value="userSuccess"></beans:property>
</beans:bean>
<beans:bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/jsp/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
我的 Controller 类扩展了 SimpleFormController 并且是:
public class HomeController extends SimpleFormController {
private UserService userService;
public HomeController() {
setCommandClass(User.class);
setCommandName("user");
}
public void setUserService(UserService userService) {
this.userService = userService;
}
protected ModelAndView onSubmit(Object command) throws Exception {
System.out.println("Hai Inside");
User user = (User) command;
userService.add(user);
return new ModelAndView("userSuccess","user",user);
}
}
请帮助我了解模型和控制器之间的流程。