What is the best way to change my model in Spring MVC if I care about IOC

I am building an application using Spring MVC. I want to make certain changes to my model for each controller in the application. In particular, I want to insert some additional data into the model, which will be present on all pages of the application.

I could do this in several ways: just add data to the end of each controller, use a subclass of the model that adds my extra data, use a subclass of ModelAndView that wraps my model, uses a subclass of VelocityView that wraps the Model before using it ... I'm sure that there are other options.

But I have a limitation of "elegance": I do not want to write code in each controller, I want this behavior to be defined in one- and only one . Ideally, this will be controlled by my IOC bean configuration file.

Does anyone have a recommendation on how to achieve this elegantly?

+3
source share
3 answers

- , Spring MVC - HandlerInterceptor, . postHandle HandlerInterceptor ( , HandlerInterceptor) ModelAndView. , .

+4

. Spring AOP, .

, "" , . , , .

+1

, , , .

, : " , ".

, " , ".

, . , . , "" - , .

Admittedly, I am not entirely familiar with the Spring MVC MVC method, but a more detailed example of what you are trying to achieve may allow a more informed discussion.

0
source

Source: https://habr.com/ru/post/1697866/


All Articles