Apologies, if you find this question dumb... I am new to Spring framework. I spent hours looking up an answer...
According to the official Spring Framework documentation, you can assign a name to a RequestMapping annotation using the name property.
So the question is what's the point of giving a name to a route mapping?
In Symfony framework, we can use the mapping name to generate a URL.
class BlogController
{
/**
* @Route(name="BlogComments", path="blog/{blog}/comments/{page}")
*/
public function listBlogComments(Blog blog, page)
{
...
}
}
And then we can generate a URL based on the route name.
// This will generate a string "blog/27/comments/1".
$url = $this->generateUrl('BlogComments', [
'blog' => 27,
'page' => 1
]);
This is possible thanks to the Symfony\Component\Routing\Router component.
The controller class can be written like the following in the Spring framework.
@Controller
@ResponseBody
class BlogController {
@RequestMapping(name="BlogComments", path="blog/{blog}/comments/{page}")
public List<Comment> listBlogComments(@PathVariable Blog blog, @PathVariable Long page) {
...
}
}
Now how do I generate a URL based on the name of the mapping which is "BlogComments" in this case? Is there any Spring component or Service available as in the Symfony framework? What other possible use cases are available?