Java – extending annotated controllers in spring MVC
•
Java
I'm developing a small project and have some existing code. I want to keep clearing my changes, so I need to extend an annotated controller, but it doesn't work:
package a; @controller public class BaseController { // Autowired fields protected x toExtend() { // do stuff } @RequestMapping(value = "/start") protected ModelAndView setupForm(...) { toExtend(); // more stuff } } package b; @controller public class NewController extends BaseController { // Autowired fields @Override protected x toExtend() { super.toExtend(); //new stuff } }
Scan package a and B scan controller, I can't change it I really don't want this job because @ requestmapping (value = "/ start") is redundant in both controllers So I got an exception
So my question is, can I actually extend such an annotation driven controller without changing the basecontroller?
Solution
You can extend a spring controller with another spring controller
When the spring MVC controller extends another controller, the function of the sub controller can be directly used by the sub controller using the request URL of the sub controller You can get more details here
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码