model - How to store variables in all pages requestScopes within Spring -
i add objects in jsp requestscopes using controllers.
for example, if need list categories in "localhost/products/viewall", change productscontroller adding like
@requestmapping("/products/viewall") public void viewcategories(model model) { list<category> categories = service.findallcategories(); model.addattribute("categories", categories); }
so, method adds list of categories requestscope.
i need same, pages of website (since variable need used in layout of site).
how can add pages requestscopes spring?
i think have @ least 2 possible options this:
using mvc interceptor. interceptor can perform common operations requests. can extend handlerinterceptoradapter , add common model data in
posthandle
using
@modelattribute
annotation within controller. can use add common data request mappings within controller. can use @controlleradvice (with@modelattribute
annotated methods inside) if want provide model data controllers. section using @modelattribute on method should provide additional information this.
Comments
Post a Comment