开发者

Releasing attributes from Model

I am setting couple attributes to a model of Spring Model

 myModel.setValue1
 myModel.setValue2  //Now setting this to request
 request.setAttribute("All_Values", myModel)

Making a service call under try catch block. If exception received, I want to release the Value2 from my model and set only Value1 to my request and make a service call again.

 try{
 service call
 ...
 }catch(Exception e){
 myModel.release Value2 and have only Value1
 request开发者_开发技巧.setAttribute("All_values", myModel) //This has only Value1
 service call again
 }

This is just an example if I could release couple of values if Exception received. I have many values in my model and not just two, so setting attributes individually to the request would be tedious.

Could this be done?


I think you should first do the controller logic and set the model attributes at the end of the controller method, after all the exception catching etc.

You can store the model attributes in a Map, where you can remove them if needed, and just before the return of the controller do:

model.addAllAttributes(attributesMap);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜