October 2017
Intermediate to advanced
396 pages
10h 2m
English
Spring MVC allows you to pass parameters in the URI instead of passing them through request parameters. The passed values can be extracted from the request URLs. It is based on URI templates. It is not a Spring-specific concept, and is used in many frameworks by using {...} placeholders and the @PathVariable annotation. It allows clean URLs without request parameters. The following is an example:
@Controller
public class AccountController {
@GetMapping("/accounts/{accountId}")
public String show(@PathVariable("accountId") long accountId, Model model) {
Account account = accountService.findOne(accountId);
model.put("account", account);
return "accountDetails";
}
...
}
In the previous handler, ...
Read now
Unlock full access