@@ -1082,6 +1082,7 @@ method has been added.
1082
1082
with method `handleFoo` is named "FC#handleFoo". The naming strategy is pluggable.
1083
1083
It is also possible to name an `@RequestMapping` explicitly through its name attribute.
1084
1084
A new `mvcUrl` function in the Spring JSP tag library makes this easy to use in JSP pages.
1085
+ See <<mvc-links-to-controllers-from-views>>.
1085
1086
* `ResponseEntity` provides a builder-style API to guide controller methods
1086
1087
towards the preparation of server-side responses, e.g. `ResponseEntity.ok()`.
1087
1088
* `RequestEntity` is a new type that provides a builder-style API to guide client-side REST
@@ -32574,7 +32575,7 @@ Therefore the use of flash attributes is recommended mainly for redirect scenari
32574
32575
32575
32576
32576
32577
32577
- [[mvc-construct-encode- uri]]
32578
+ [[mvc-uri-building ]]
32578
32579
=== Building URIs
32579
32580
32580
32581
Spring MVC provides a mechanism for building and encoding a URI using
@@ -32649,8 +32650,8 @@ also have the literal part of the servlet mapping included:
32649
32650
.path("/accounts").build()
32650
32651
----
32651
32652
32652
- [[mvc-construct-uri -controllers]]
32653
- === Building URIs to Controllers and methods
32653
+ [[mvc-links-to -controllers]]
32654
+ ==== Building URIs to Controllers and methods
32654
32655
32655
32656
Spring MVC provides another mechanism for building and encoding URIs that link to
32656
32657
Controllers and methods defined within an application.
@@ -32697,6 +32698,54 @@ URIs by coding against the actual Controller's API:
32697
32698
URI uri = uriComponents.encode().toUri();
32698
32699
----
32699
32700
32701
+ [[mvc-links-to-controllers-from-views]]
32702
+ ==== Building URIs to Controllers and methods from views
32703
+
32704
+ It is also useful to build links to annotated controllers from views (e.g. JSP).
32705
+ This can be done through a method on `MvcUriComponentsBuilder` which refers to mappings
32706
+ by name called `fromMappingName`.
32707
+
32708
+ As of 4.1 every `@RequestMapping` is assigned a default name based on the
32709
+ capital letters of the class and the full method name. For example, the method `getFoo` in class
32710
+ `FooController` is assigned the name "FC#getFoo". This naming strategy is pluggable
32711
+ by implementing `HandlerMethodMappingNamingStrategy` and configuring it on your
32712
+ `RequestMappingHandlerMapping`. Furthermore the `@RequestMapping` annotation includes
32713
+ a name attribute that can be used to override the default strategy.
32714
+
32715
+ [NOTE]
32716
+ ====
32717
+ The assigned request mapping names are logged at TRACE level on startup.
32718
+ ====
32719
+
32720
+ The Spring JSP tag library provides a function called `mvcUrl` that can be used to
32721
+ prepare links to controller methods based on this mechanism.
32722
+
32723
+ For example given:
32724
+
32725
+ [source,java,indent=0]
32726
+ [subs="verbatim,quotes"]
32727
+ ----
32728
+ @RequestMapping("/people/{id}/addresses")
32729
+ public class MyController {
32730
+
32731
+ @RequestMapping("/{country}")
32732
+ public HttpEntity getAddress(@PathVariable String country) { ... }
32733
+ }
32734
+ ----
32735
+
32736
+ The following JSP code can prepare a link:
32737
+
32738
+ [source,jsp,indent=0]
32739
+ [subs="verbatim,quotes"]
32740
+ ----
32741
+ <%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
32742
+ ...
32743
+ <a href="${s:mvcUrl('PC#getPerson').arg(0,'123').build()}">Get Person</a>
32744
+ ----
32745
+
32746
+
32747
+
32748
+
32700
32749
32701
32750
[[mvc-localeresolver]]
32702
32751
=== Using locales
0 commit comments