Skip to content

Commit 110ccaa

Browse files
committed
Use annotation attribute aliases in examples
This commit updates examples in the reference manual to use annotation attribute aliases.
1 parent a7d8103 commit 110ccaa

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

src/asciidoc/core-validation.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ To trigger validation of a `@Controller` input, simply annotate the input argume
17231723
@Controller
17241724
public class MyController {
17251725
1726-
@RequestMapping("/foo", method=RequestMethod.POST)
1726+
@RequestMapping(path="/foo", method=RequestMethod.POST)
17271727
public void processFoo(**@Valid** Foo foo) { /* ... */ }
17281728
----
17291729

@@ -1755,7 +1755,7 @@ instance per `@Controller` class:
17551755
binder.setValidator(new FooValidator());
17561756
}
17571757
1758-
@RequestMapping("/foo", method=RequestMethod.POST)
1758+
@RequestMapping(path="/foo", method=RequestMethod.POST)
17591759
public void processFoo(@Valid Foo foo) { ... }
17601760
17611761
}

src/asciidoc/web-mvc.adoc

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,12 @@ application that uses this annotation:
556556
return appointmentBook.getAppointmentsForToday();
557557
}
558558
559-
**@RequestMapping(value="/{day}", method = RequestMethod.GET)**
559+
**@RequestMapping(path = "/{day}", method = RequestMethod.GET)**
560560
public Map<String, Appointment> getForDay(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date day, Model model) {
561561
return appointmentBook.getAppointmentsForDay(day);
562562
}
563563
564-
**@RequestMapping(value="/new", method = RequestMethod.GET)**
564+
**@RequestMapping(path = "/new", method = RequestMethod.GET)**
565565
public AppointmentForm getNewForm() {
566566
return new AppointmentForm();
567567
}
@@ -695,7 +695,7 @@ to the value of a URI template variable:
695695
[source,java,indent=0]
696696
[subs="verbatim,quotes"]
697697
----
698-
@RequestMapping(value="/owners/{ownerId}", method=RequestMethod.GET)
698+
@RequestMapping(path="/owners/{ownerId}", method=RequestMethod.GET)
699699
public String findOwner(**@PathVariable** String ownerId, Model model) {
700700
Owner owner = ownerService.findOwner(ownerId);
701701
model.addAttribute("owner", owner);
@@ -717,7 +717,7 @@ template variable by name. You can specify it in the annotation:
717717
[source,java,indent=0]
718718
[subs="verbatim,quotes"]
719719
----
720-
@RequestMapping(value="/owners/{ownerId}", method=RequestMethod.GET)
720+
@RequestMapping(path="/owners/{ownerId}", method=RequestMethod.GET)
721721
public String findOwner(**@PathVariable("ownerId")** String theOwner, Model model) {
722722
// implementation omitted
723723
}
@@ -730,7 +730,7 @@ will match the method argument name to the URI template variable name:
730730
[source,java,indent=0]
731731
[subs="verbatim,quotes"]
732732
----
733-
@RequestMapping(value="/owners/{ownerId}", method=RequestMethod.GET)
733+
@RequestMapping(path="/owners/{ownerId}", method=RequestMethod.GET)
734734
public String findOwner(**@PathVariable** String ownerId, Model model) {
735735
// implementation omitted
736736
}
@@ -742,7 +742,7 @@ A method can have any number of `@PathVariable` annotations:
742742
[source,java,indent=0]
743743
[subs="verbatim,quotes"]
744744
----
745-
@RequestMapping(value="/owners/{ownerId}/pets/{petId}", method=RequestMethod.GET)
745+
@RequestMapping(path="/owners/{ownerId}/pets/{petId}", method=RequestMethod.GET)
746746
public String findPet(**@PathVariable** String ownerId, **@PathVariable** String petId, Model model) {
747747
Owner owner = ownerService.findOwner(ownerId);
748748
Pet pet = owner.getPet(petId);
@@ -886,7 +886,7 @@ Below is an example of extracting the matrix variable "q":
886886
----
887887
// GET /pets/42;q=11;r=22
888888
889-
@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET)
889+
@RequestMapping(path = "/pets/{petId}", method = RequestMethod.GET)
890890
public void findPet(@PathVariable String petId, @MatrixVariable int q) {
891891
892892
// petId == 42
@@ -903,10 +903,10 @@ specific to identify where the variable is expected to be:
903903
----
904904
// GET /owners/42;q=11/pets/21;q=22
905905
906-
@RequestMapping(value = "/owners/{ownerId}/pets/{petId}", method = RequestMethod.GET)
906+
@RequestMapping(path = "/owners/{ownerId}/pets/{petId}", method = RequestMethod.GET)
907907
public void findPet(
908-
@MatrixVariable(value="q", pathVar="ownerId") int q1,
909-
@MatrixVariable(value="q", pathVar="petId") int q2) {
908+
@MatrixVariable(name="q", pathVar="ownerId") int q1,
909+
@MatrixVariable(name="q", pathVar="petId") int q2) {
910910
911911
// q1 == 11
912912
// q2 == 22
@@ -921,7 +921,7 @@ A matrix variable may be defined as optional and a default value specified:
921921
----
922922
// GET /pets/42
923923
924-
@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET)
924+
@RequestMapping(path = "/pets/{petId}", method = RequestMethod.GET)
925925
public void findPet(@MatrixVariable(required=false, defaultValue="1") int q) {
926926
927927
// q == 1
@@ -936,7 +936,7 @@ All matrix variables may be obtained in a Map:
936936
----
937937
// GET /owners/42;q=11;r=12/pets/21;q=22;s=23
938938
939-
@RequestMapping(value = "/owners/{ownerId}/pets/{petId}", method = RequestMethod.GET)
939+
@RequestMapping(path = "/owners/{ownerId}/pets/{petId}", method = RequestMethod.GET)
940940
public void findPet(
941941
@MatrixVariable Map<String, String> matrixVars,
942942
@MatrixVariable(pathVar="petId"") Map<String, String> petMatrixVars) {
@@ -994,7 +994,7 @@ media type. For example:
994994
[subs="verbatim,quotes"]
995995
----
996996
@Controller
997-
@RequestMapping(value = "/pets", method = RequestMethod.POST, **consumes="application/json"**)
997+
@RequestMapping(path = "/pets", method = RequestMethod.POST, **consumes="application/json"**)
998998
public void addPet(@RequestBody Pet pet, Model model) {
999999
// implementation omitted
10001000
}
@@ -1024,7 +1024,7 @@ condition. For example:
10241024
[subs="verbatim,quotes"]
10251025
----
10261026
@Controller
1027-
@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET, **produces="application/json"**)
1027+
@RequestMapping(path = "/pets/{petId}", method = RequestMethod.GET, **produces="application/json"**)
10281028
@ResponseBody
10291029
public Pet getPet(@PathVariable String petId, Model model) {
10301030
// implementation omitted
@@ -1057,7 +1057,7 @@ example with a request parameter value condition:
10571057
@RequestMapping("/owners/{ownerId}")
10581058
public class RelativePathUriTemplateController {
10591059
1060-
@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET, **params="myParam=myValue"**)
1060+
@RequestMapping(path = "/pets/{petId}", method = RequestMethod.GET, **params="myParam=myValue"**)
10611061
public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) {
10621062
// implementation omitted
10631063
}
@@ -1075,7 +1075,7 @@ specific request header value:
10751075
@RequestMapping("/owners/{ownerId}")
10761076
public class RelativePathUriTemplateController {
10771077
1078-
@RequestMapping(value = "/pets", method = RequestMethod.GET, **headers="myHeader=myValue"**)
1078+
@RequestMapping(path = "/pets", method = RequestMethod.GET, **headers="myHeader=myValue"**)
10791079
public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) {
10801080
// implementation omitted
10811081
}
@@ -1302,7 +1302,7 @@ The following code snippet shows the usage:
13021302

13031303
Parameters using this annotation are required by default, but you can specify that a
13041304
parameter is optional by setting ++@RequestParam++'s `required` attribute to `false`
1305-
(e.g., `@RequestParam(value="id", required=false)`).
1305+
(e.g., `@RequestParam(path="id", required=false)`).
13061306

13071307
Type conversion is applied automatically if the target method parameter type is not
13081308
`String`. See <<mvc-ann-typeconversion>>.
@@ -1320,7 +1320,7 @@ be bound to the value of the HTTP request body. For example:
13201320
[source,java,indent=0]
13211321
[subs="verbatim,quotes"]
13221322
----
1323-
@RequestMapping(value = "/something", method = RequestMethod.PUT)
1323+
@RequestMapping(path = "/something", method = RequestMethod.PUT)
13241324
public void handle(@RequestBody String body, Writer writer) throws IOException {
13251325
writer.write(body);
13261326
}
@@ -1399,7 +1399,7 @@ response body (and not placed in a Model, or interpreted as a view name). For ex
13991399
[source,java,indent=0]
14001400
[subs="verbatim,quotes"]
14011401
----
1402-
@RequestMapping(value = "/something", method = RequestMethod.PUT)
1402+
@RequestMapping(path = "/something", method = RequestMethod.PUT)
14031403
@ResponseBody
14041404
public String helloWorld() {
14051405
return "Hello World";
@@ -1546,7 +1546,7 @@ form field individually.
15461546
[source,java,indent=0]
15471547
[subs="verbatim,quotes"]
15481548
----
1549-
@RequestMapping(value="/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST)
1549+
@RequestMapping(path = "/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST)
15501550
public String processSubmit(**@ModelAttribute Pet pet**) { }
15511551
----
15521552

@@ -1568,7 +1568,7 @@ using an URI template variable and a type converter. Here is an example:
15681568
[source,java,indent=0]
15691569
[subs="verbatim,quotes"]
15701570
----
1571-
@RequestMapping(value="/accounts/{account}", method = RequestMethod.PUT)
1571+
@RequestMapping(path = "/accounts/{account}", method = RequestMethod.PUT)
15721572
public String save(@ModelAttribute("account") Account account) {
15731573
15741574
}
@@ -1593,7 +1593,7 @@ following the `@ModelAttribute` argument:
15931593
[source,java,indent=0]
15941594
[subs="verbatim,quotes"]
15951595
----
1596-
@RequestMapping(value="/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST)
1596+
@RequestMapping(path = "/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST)
15971597
public String processSubmit(**@ModelAttribute("pet") Pet pet**, BindingResult result) {
15981598
15991599
if (result.hasErrors()) {
@@ -1617,7 +1617,7 @@ subsequently reported back to the user:
16171617
[source,java,indent=0]
16181618
[subs="verbatim,quotes"]
16191619
----
1620-
@RequestMapping(value="/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST)
1620+
@RequestMapping(path = "/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST)
16211621
public String processSubmit(**@ModelAttribute("pet") Pet pet**, BindingResult result) {
16221622
16231623
new PetValidator().validate(pet, result);
@@ -1636,7 +1636,7 @@ annotation:
16361636
[source,java,indent=0]
16371637
[subs="verbatim,quotes"]
16381638
----
1639-
@RequestMapping(value="/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST)
1639+
@RequestMapping(path = "/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST)
16401640
public String processSubmit(**@Valid @ModelAttribute("pet") Pet pet**, BindingResult result) {
16411641
16421642
if (result.hasErrors()) {
@@ -1956,7 +1956,7 @@ the view class or interface to be used:
19561956
@RestController
19571957
public class UserController {
19581958
1959-
@RequestMapping(value = "/user", method = RequestMethod.GET)
1959+
@RequestMapping(path = "/user", method = RequestMethod.GET)
19601960
@JsonView(User.WithoutPasswordView.class)
19611961
public User getUser() {
19621962
return new User("eric", "7!jd#h23");
@@ -2008,7 +2008,7 @@ to the model:
20082008
@Controller
20092009
public class UserController extends AbstractController {
20102010
2011-
@RequestMapping(value = "/user", method = RequestMethod.GET)
2011+
@RequestMapping(path = "/user", method = RequestMethod.GET)
20122012
public String getUser(Model model) {
20132013
model.addAttribute("user", new User("eric", "7!jd#h23"));
20142014
model.addAttribute(JsonView.class.getName(), User.WithoutPasswordView.class);
@@ -2758,7 +2758,7 @@ through `Model` nor `RedirectAttributes`. For example:
27582758
[source,java,indent=0]
27592759
[subs="verbatim,quotes"]
27602760
----
2761-
@RequestMapping(value = "/files/{path}", method = RequestMethod.POST)
2761+
@RequestMapping(path = "/files/{path}", method = RequestMethod.POST)
27622762
public String upload(...) {
27632763
// ...
27642764
return "redirect:files/{path}";
@@ -2936,7 +2936,7 @@ application/atom+xml is shown below.
29362936
29372937
private List<SampleContent> contentList = new ArrayList<SampleContent>();
29382938
2939-
@RequestMapping(value="/content", method=RequestMethod.GET)
2939+
@RequestMapping(path="/content", method=RequestMethod.GET)
29402940
public ModelAndView getContent() {
29412941
ModelAndView mav = new ModelAndView();
29422942
mav.setViewName("content");
@@ -3542,7 +3542,7 @@ use `MultipartHttpServletRequest` or `MultipartFile` in the method parameters:
35423542
@Controller
35433543
public class FileUploadController {
35443544
3545-
@RequestMapping(value = "/form", method = RequestMethod.POST)
3545+
@RequestMapping(path = "/form", method = RequestMethod.POST)
35463546
public String handleFormUpload(@RequestParam("name") String name,
35473547
@RequestParam("file") MultipartFile file) {
35483548
@@ -3571,7 +3571,7 @@ the method parameter:
35713571
@Controller
35723572
public class FileUploadController {
35733573
3574-
@RequestMapping(value = "/form", method = RequestMethod.POST)
3574+
@RequestMapping(path = "/form", method = RequestMethod.POST)
35753575
public String handleFormUpload(@RequestParam("name") String name,
35763576
@RequestParam("file") Part file) {
35773577
@@ -3629,7 +3629,7 @@ multipart:
36293629
[source,java,indent=0]
36303630
[subs="verbatim,quotes"]
36313631
----
3632-
@RequestMapping(value="/someUrl", method = RequestMethod.POST)
3632+
@RequestMapping(path = "/someUrl", method = RequestMethod.POST)
36333633
public String onSubmit(**@RequestPart("meta-data") MetaData metadata,
36343634
@RequestPart("file-data") MultipartFile file**) {
36353635
@@ -3840,7 +3840,7 @@ When writing error information, the status code and the error message set on the
38403840
@Controller
38413841
public class ErrorController {
38423842
3843-
@RequestMapping(value="/error", produces="application/json")
3843+
@RequestMapping(path="/error", produces="application/json")
38443844
@ResponseBody
38453845
public Map<String, Object> handle(HttpServletRequest request) {
38463846

src/asciidoc/web-websocket.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ type, for example:
13611361
this.template = template;
13621362
}
13631363
1364-
@RequestMapping(value="/greetings", method=POST)
1364+
@RequestMapping(path="/greetings", method=POST)
13651365
public void greet(String greeting) {
13661366
String text = "[" + getTimestamp() + "]:" + greeting;
13671367
this.template.convertAndSend("/topic/greetings", text);
@@ -1684,7 +1684,7 @@ public class MyController {
16841684
}
16851685
16861686
@MessageExceptionHandler
1687-
@SendToUser(value="/queue/errors", broadcast=false)
1687+
@SendToUser(destinations="/queue/errors", broadcast=false)
16881688
public ApplicationError handleException(MyBusinessException exception) {
16891689
// ...
16901690
return appError;
@@ -1961,7 +1961,7 @@ scope proxy mode for WebSocket-scoped beans:
19611961
[subs="verbatim,quotes"]
19621962
----
19631963
@Component
1964-
@Scope(value="websocket", proxyMode = ScopedProxyMode.TARGET_CLASS)
1964+
@Scope(name = "websocket", proxyMode = ScopedProxyMode.TARGET_CLASS)
19651965
public class MyBean {
19661966
19671967
@PostConstruct

0 commit comments

Comments
 (0)