I type @RequestMapping
and @Controller
before almost all my Controllers.
@RequestMapping("/clients")
@Controller
class ClientsController {
}
If you introduce a path
attribute in @Controller
, this can be reduced to:
@Controller(path="/clients")
class ClientsController {
}
Comment From: sbrannen
I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference.
Comment From: sbrannen
Hi @hansdesmet,
Thanks for creating your first Spring Framework issue!
Regarding your proposal, we would not want to introduce a path
attribute in @Controller
since controller classes are not required to declare a class-level @RequestMapping
.
However, you can make use of a custom composed annotation that will help you achieve your goal.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
@RequestMapping
public @interface MappedController {
@AliasFor(annotation = Controller.class)
String value() default "";
@AliasFor(annotation = RequestMapping.class)
String path();
}
You can then use that composed annotation as follows.
@MappedController(path = "/clients")
class ClientsController {
// ...
}
In light of that, I am closing this issue.
Comment From: rstoyanchev
Note also @Controller
isn't defined as a Web controller and doesn't have to be. It is also supported for STOMP or RSocket messaging in which case a path
attribute wouldn't fit well.