Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 从模型中释放属性_Spring Mvc_Attributes_Model_Request_Try Catch - Fatal编程技术网

Spring mvc 从模型中释放属性

Spring mvc 从模型中释放属性,spring-mvc,attributes,model,request,try-catch,Spring Mvc,Attributes,Model,Request,Try Catch,我正在为Spring模型的模型设置耦合属性 myModel.setValue1 myModel.setValue2 //Now setting this to request request.setAttribute("All_Values", myModel) 在try-catch块下进行服务调用。如果收到异常,我想从我的模型中释放Value2,并在我的请求中仅设置Value1,然后再次进行服务调用 try{ service call ... }catch(Exception

我正在为Spring模型的模型设置耦合属性

 myModel.setValue1
 myModel.setValue2  //Now setting this to request
 request.setAttribute("All_Values", myModel)
在try-catch块下进行服务调用。如果收到异常,我想从我的模型中释放Value2,并在我的请求中仅设置Value1,然后再次进行服务调用

 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
 }
这只是一个例子,如果收到异常,我可以释放几个值。我的模型中有很多值,而不仅仅是两个值,因此为请求单独设置属性将非常繁琐


可以这样做吗?

我认为您应该首先执行控制器逻辑,并在所有异常捕获等之后,在控制器方法的末尾设置模型属性

可以将模型属性存储在地图中,如果需要,可以在地图中删除这些属性,并在控制器返回之前执行以下操作:

model.addAllAttributes(attributesMap);

为什么需要调用request.setAttribute?@axtavt:我正在将请求和其他参数一起发送到服务。该请求还用于获取portlet会话和其他一些内容。