New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@RequestMapping inheritance on inner classes [SPR-14513] #19082
Comments
Rossen Stoyanchev commented We can consider some feature for a URL-based hierarchy of controllers. However two concerns with the suggested approach. First it is not explicit enough. I could happen to create a controller as an inner class within another and without intending for the inner class to be relative to the containing class? Second it imposes requirements that are quite harsh. It forces the use of nested classes which may or may not be desired and it could get quite ugly with more than one levels of nesting. Also worth noting the nested controller in the example is not static which probably means you have to declare it explicitly and that is yet another undue requirement. By contrast we are talking about saving a URL prefix from being duplicated which seems uncomfortable but URL structure in itself doesn't change that often so is it really an issue in practice? That said perhaps a case can be made for a controller that handles a sub-URL space under one or more root URLs. We could do something similar to JAX-RS sub-resources where an |
Rossen Stoyanchev commented All in all I lean towards not fixing this. |
@rstoyanchev hello, it's been a while since this issue was closed, would you care to reconsider? This should be similar to the recent support of |
Is it really all that different from this which can be nested or not: @Controller
@RequestMapping("/category")
public class CategoriesController {
// maps to "/category/"
@RequestMapping("/")
public String showAll(Model model) { [...] }
}
@RequestMapping("/category/{category}")
public class CategoryController {
// maps to "/category/{category}/"
@RequestMapping("/")
public String showCategory(@PathVariable Category category, Model model) { [...] }
// maps to "/category/{category}/download"
@RequestMapping("/download")
public String downloadCategory(@PathVariable Category category, Model model) { [...] }
} |
@rstoyanchev It's not a big deal of course but you have to copy-paste the instance variables and the URL prefix. This would just be a nice little addition with low impact |
Yes it would be a nice little addition but I'm also concerned with issues for existing apps that rely on the current behavior. As for the instance variables, the above could be an inner or nested class just as well. |
that's right, that actually would be a breaking change. I'm not sure if classpath scanning would work on an inner class though. |
Darion Haase opened SPR-14513 and commented
Similar to how mapping 'inheritance' works on methods it should be possible to do this on inner classes as well:
The CategoryController could itself include another class if necessary. This system would reduce duplicate mapping descriptions on larger controllers, currently it has to be like this:
More mapped methods would increase the amount of duplication.
There has been a similar request which uses inheritance of classes in #16048
No further details from SPR-14513
The text was updated successfully, but these errors were encountered: