Quote:
The new programming model is an example of a POJO-centric approach that, combined with sensible convention-based defaults, greatly simplifies and facilitates web development based on Spring Web MVC framework.@MVC changes [Spring Web MVC] programming model in 3 significant ways.
- It does not have any interface or base class requirements.
- It allows any number of request handling methods.
- It allows a high degree of flexibility in the method's signature.
Given those three it's fair to say @MVC is not merely an alternative. It's the next step in the evolution of Spring MVC's controller technology.
This is a very welcome change as Spring Web used to be notorious for its verbose and extremely fine-grained configuration. With Spring 2.5 @MVC one can express oneself as consise as follows:
@ControllerThe above code says:
public class AccountsController {
private AccountRepository accountRepository;
@Autowired
public AccountsController(AccountRepository accountRepository) {
this.accountRepository = accountRepository;
}
@RequestMapping(method=RequestMethod.GET)
public void show(@RequestParam("number") String number, Mapmodel)
{
model.put("account", accountRepository.findAccount(number));
}
...
- Map /accounts/show URL to AccountsController.show() method (AccountsController <-> /acccounts and show() <-> /show by convention).
- Parse out number request parameter and pass it as a String argument to show() method.
- Build the model and pass it to /WEB-INF/views/accounts/show.jsp. Here the end parts come from the config file and the middle part is a convention-based function of controller class/method names.