From 110ccaa7213561c436aed1574a6c822e79010926 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 29 Jun 2015 16:54:28 +0200 Subject: [PATCH] Use annotation attribute aliases in examples This commit updates examples in the reference manual to use annotation attribute aliases. --- src/asciidoc/core-validation.adoc | 4 +- src/asciidoc/web-mvc.adoc | 64 +++++++++++++++---------------- src/asciidoc/web-websocket.adoc | 6 +-- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/asciidoc/core-validation.adoc b/src/asciidoc/core-validation.adoc index 5e307efcba..2bf93b8a09 100644 --- a/src/asciidoc/core-validation.adoc +++ b/src/asciidoc/core-validation.adoc @@ -1723,7 +1723,7 @@ To trigger validation of a `@Controller` input, simply annotate the input argume @Controller public class MyController { - @RequestMapping("/foo", method=RequestMethod.POST) + @RequestMapping(path="/foo", method=RequestMethod.POST) public void processFoo(**@Valid** Foo foo) { /* ... */ } ---- @@ -1755,7 +1755,7 @@ instance per `@Controller` class: binder.setValidator(new FooValidator()); } - @RequestMapping("/foo", method=RequestMethod.POST) + @RequestMapping(path="/foo", method=RequestMethod.POST) public void processFoo(@Valid Foo foo) { ... } } diff --git a/src/asciidoc/web-mvc.adoc b/src/asciidoc/web-mvc.adoc index 9d186bc671..6a1792c7b5 100644 --- a/src/asciidoc/web-mvc.adoc +++ b/src/asciidoc/web-mvc.adoc @@ -556,12 +556,12 @@ application that uses this annotation: return appointmentBook.getAppointmentsForToday(); } - **@RequestMapping(value="/{day}", method = RequestMethod.GET)** + **@RequestMapping(path = "/{day}", method = RequestMethod.GET)** public Map getForDay(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date day, Model model) { return appointmentBook.getAppointmentsForDay(day); } - **@RequestMapping(value="/new", method = RequestMethod.GET)** + **@RequestMapping(path = "/new", method = RequestMethod.GET)** public AppointmentForm getNewForm() { return new AppointmentForm(); } @@ -695,7 +695,7 @@ to the value of a URI template variable: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping(value="/owners/{ownerId}", method=RequestMethod.GET) + @RequestMapping(path="/owners/{ownerId}", method=RequestMethod.GET) public String findOwner(**@PathVariable** String ownerId, Model model) { Owner owner = ownerService.findOwner(ownerId); model.addAttribute("owner", owner); @@ -717,7 +717,7 @@ template variable by name. You can specify it in the annotation: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping(value="/owners/{ownerId}", method=RequestMethod.GET) + @RequestMapping(path="/owners/{ownerId}", method=RequestMethod.GET) public String findOwner(**@PathVariable("ownerId")** String theOwner, Model model) { // implementation omitted } @@ -730,7 +730,7 @@ will match the method argument name to the URI template variable name: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping(value="/owners/{ownerId}", method=RequestMethod.GET) + @RequestMapping(path="/owners/{ownerId}", method=RequestMethod.GET) public String findOwner(**@PathVariable** String ownerId, Model model) { // implementation omitted } @@ -742,7 +742,7 @@ A method can have any number of `@PathVariable` annotations: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping(value="/owners/{ownerId}/pets/{petId}", method=RequestMethod.GET) + @RequestMapping(path="/owners/{ownerId}/pets/{petId}", method=RequestMethod.GET) public String findPet(**@PathVariable** String ownerId, **@PathVariable** String petId, Model model) { Owner owner = ownerService.findOwner(ownerId); Pet pet = owner.getPet(petId); @@ -886,7 +886,7 @@ Below is an example of extracting the matrix variable "q": ---- // GET /pets/42;q=11;r=22 - @RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET) + @RequestMapping(path = "/pets/{petId}", method = RequestMethod.GET) public void findPet(@PathVariable String petId, @MatrixVariable int q) { // petId == 42 @@ -903,10 +903,10 @@ specific to identify where the variable is expected to be: ---- // GET /owners/42;q=11/pets/21;q=22 - @RequestMapping(value = "/owners/{ownerId}/pets/{petId}", method = RequestMethod.GET) + @RequestMapping(path = "/owners/{ownerId}/pets/{petId}", method = RequestMethod.GET) public void findPet( - @MatrixVariable(value="q", pathVar="ownerId") int q1, - @MatrixVariable(value="q", pathVar="petId") int q2) { + @MatrixVariable(name="q", pathVar="ownerId") int q1, + @MatrixVariable(name="q", pathVar="petId") int q2) { // q1 == 11 // q2 == 22 @@ -921,7 +921,7 @@ A matrix variable may be defined as optional and a default value specified: ---- // GET /pets/42 - @RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET) + @RequestMapping(path = "/pets/{petId}", method = RequestMethod.GET) public void findPet(@MatrixVariable(required=false, defaultValue="1") int q) { // q == 1 @@ -936,7 +936,7 @@ All matrix variables may be obtained in a Map: ---- // GET /owners/42;q=11;r=12/pets/21;q=22;s=23 - @RequestMapping(value = "/owners/{ownerId}/pets/{petId}", method = RequestMethod.GET) + @RequestMapping(path = "/owners/{ownerId}/pets/{petId}", method = RequestMethod.GET) public void findPet( @MatrixVariable Map matrixVars, @MatrixVariable(pathVar="petId"") Map petMatrixVars) { @@ -994,7 +994,7 @@ media type. For example: [subs="verbatim,quotes"] ---- @Controller - @RequestMapping(value = "/pets", method = RequestMethod.POST, **consumes="application/json"**) + @RequestMapping(path = "/pets", method = RequestMethod.POST, **consumes="application/json"**) public void addPet(@RequestBody Pet pet, Model model) { // implementation omitted } @@ -1024,7 +1024,7 @@ condition. For example: [subs="verbatim,quotes"] ---- @Controller - @RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET, **produces="application/json"**) + @RequestMapping(path = "/pets/{petId}", method = RequestMethod.GET, **produces="application/json"**) @ResponseBody public Pet getPet(@PathVariable String petId, Model model) { // implementation omitted @@ -1057,7 +1057,7 @@ example with a request parameter value condition: @RequestMapping("/owners/{ownerId}") public class RelativePathUriTemplateController { - @RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET, **params="myParam=myValue"**) + @RequestMapping(path = "/pets/{petId}", method = RequestMethod.GET, **params="myParam=myValue"**) public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) { // implementation omitted } @@ -1075,7 +1075,7 @@ specific request header value: @RequestMapping("/owners/{ownerId}") public class RelativePathUriTemplateController { - @RequestMapping(value = "/pets", method = RequestMethod.GET, **headers="myHeader=myValue"**) + @RequestMapping(path = "/pets", method = RequestMethod.GET, **headers="myHeader=myValue"**) public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) { // implementation omitted } @@ -1302,7 +1302,7 @@ The following code snippet shows the usage: Parameters using this annotation are required by default, but you can specify that a parameter is optional by setting ++@RequestParam++'s `required` attribute to `false` -(e.g., `@RequestParam(value="id", required=false)`). +(e.g., `@RequestParam(path="id", required=false)`). Type conversion is applied automatically if the target method parameter type is not `String`. See <>. @@ -1320,7 +1320,7 @@ be bound to the value of the HTTP request body. For example: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping(value = "/something", method = RequestMethod.PUT) + @RequestMapping(path = "/something", method = RequestMethod.PUT) public void handle(@RequestBody String body, Writer writer) throws IOException { writer.write(body); } @@ -1399,7 +1399,7 @@ response body (and not placed in a Model, or interpreted as a view name). For ex [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping(value = "/something", method = RequestMethod.PUT) + @RequestMapping(path = "/something", method = RequestMethod.PUT) @ResponseBody public String helloWorld() { return "Hello World"; @@ -1546,7 +1546,7 @@ form field individually. [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping(value="/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST) + @RequestMapping(path = "/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST) public String processSubmit(**@ModelAttribute Pet pet**) { } ---- @@ -1568,7 +1568,7 @@ using an URI template variable and a type converter. Here is an example: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping(value="/accounts/{account}", method = RequestMethod.PUT) + @RequestMapping(path = "/accounts/{account}", method = RequestMethod.PUT) public String save(@ModelAttribute("account") Account account) { } @@ -1593,7 +1593,7 @@ following the `@ModelAttribute` argument: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping(value="/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST) + @RequestMapping(path = "/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST) public String processSubmit(**@ModelAttribute("pet") Pet pet**, BindingResult result) { if (result.hasErrors()) { @@ -1617,7 +1617,7 @@ subsequently reported back to the user: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping(value="/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST) + @RequestMapping(path = "/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST) public String processSubmit(**@ModelAttribute("pet") Pet pet**, BindingResult result) { new PetValidator().validate(pet, result); @@ -1636,7 +1636,7 @@ annotation: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping(value="/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST) + @RequestMapping(path = "/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST) public String processSubmit(**@Valid @ModelAttribute("pet") Pet pet**, BindingResult result) { if (result.hasErrors()) { @@ -1956,7 +1956,7 @@ the view class or interface to be used: @RestController public class UserController { - @RequestMapping(value = "/user", method = RequestMethod.GET) + @RequestMapping(path = "/user", method = RequestMethod.GET) @JsonView(User.WithoutPasswordView.class) public User getUser() { return new User("eric", "7!jd#h23"); @@ -2008,7 +2008,7 @@ to the model: @Controller public class UserController extends AbstractController { - @RequestMapping(value = "/user", method = RequestMethod.GET) + @RequestMapping(path = "/user", method = RequestMethod.GET) public String getUser(Model model) { model.addAttribute("user", new User("eric", "7!jd#h23")); model.addAttribute(JsonView.class.getName(), User.WithoutPasswordView.class); @@ -2758,7 +2758,7 @@ through `Model` nor `RedirectAttributes`. For example: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping(value = "/files/{path}", method = RequestMethod.POST) + @RequestMapping(path = "/files/{path}", method = RequestMethod.POST) public String upload(...) { // ... return "redirect:files/{path}"; @@ -2936,7 +2936,7 @@ application/atom+xml is shown below. private List contentList = new ArrayList(); - @RequestMapping(value="/content", method=RequestMethod.GET) + @RequestMapping(path="/content", method=RequestMethod.GET) public ModelAndView getContent() { ModelAndView mav = new ModelAndView(); mav.setViewName("content"); @@ -3542,7 +3542,7 @@ use `MultipartHttpServletRequest` or `MultipartFile` in the method parameters: @Controller public class FileUploadController { - @RequestMapping(value = "/form", method = RequestMethod.POST) + @RequestMapping(path = "/form", method = RequestMethod.POST) public String handleFormUpload(@RequestParam("name") String name, @RequestParam("file") MultipartFile file) { @@ -3571,7 +3571,7 @@ the method parameter: @Controller public class FileUploadController { - @RequestMapping(value = "/form", method = RequestMethod.POST) + @RequestMapping(path = "/form", method = RequestMethod.POST) public String handleFormUpload(@RequestParam("name") String name, @RequestParam("file") Part file) { @@ -3629,7 +3629,7 @@ multipart: [source,java,indent=0] [subs="verbatim,quotes"] ---- - @RequestMapping(value="/someUrl", method = RequestMethod.POST) + @RequestMapping(path = "/someUrl", method = RequestMethod.POST) public String onSubmit(**@RequestPart("meta-data") MetaData metadata, @RequestPart("file-data") MultipartFile file**) { @@ -3840,7 +3840,7 @@ When writing error information, the status code and the error message set on the @Controller public class ErrorController { - @RequestMapping(value="/error", produces="application/json") + @RequestMapping(path="/error", produces="application/json") @ResponseBody public Map handle(HttpServletRequest request) { diff --git a/src/asciidoc/web-websocket.adoc b/src/asciidoc/web-websocket.adoc index a1ec2f8e71..c7c854b6b3 100644 --- a/src/asciidoc/web-websocket.adoc +++ b/src/asciidoc/web-websocket.adoc @@ -1361,7 +1361,7 @@ type, for example: this.template = template; } - @RequestMapping(value="/greetings", method=POST) + @RequestMapping(path="/greetings", method=POST) public void greet(String greeting) { String text = "[" + getTimestamp() + "]:" + greeting; this.template.convertAndSend("/topic/greetings", text); @@ -1684,7 +1684,7 @@ public class MyController { } @MessageExceptionHandler - @SendToUser(value="/queue/errors", broadcast=false) + @SendToUser(destinations="/queue/errors", broadcast=false) public ApplicationError handleException(MyBusinessException exception) { // ... return appError; @@ -1961,7 +1961,7 @@ scope proxy mode for WebSocket-scoped beans: [subs="verbatim,quotes"] ---- @Component -@Scope(value="websocket", proxyMode = ScopedProxyMode.TARGET_CLASS) +@Scope(name = "websocket", proxyMode = ScopedProxyMode.TARGET_CLASS) public class MyBean { @PostConstruct