Spring mvc Spring请求参数在调用中是唯一的
大规模编辑 假设我有两个不同的控制器。一个渲染视图,另一个渲染Spring mvc Spring请求参数在调用中是唯一的,spring-mvc,parameters,Spring Mvc,Parameters,大规模编辑 假设我有两个不同的控制器。一个渲染视图,另一个渲染标记 视图控制器: @Controller public class ViewController { @Resource private VehicleCatalogAPIService vehicleCatalogAPIService; @RequestMapping("/en/new/{organizationUnitId}") public String view(ModelMap model
标记
视图控制器
:
@Controller
public class ViewController {
@Resource
private VehicleCatalogAPIService vehicleCatalogAPIService;
@RequestMapping("/en/new/{organizationUnitId}")
public String view(ModelMap modelMap, Locale locale,
@PathVariable Integer organizationUnitId,) {
Vehicles vehicles = vehicleCatalogAPIService.getVehicule(organizationUnitId);
modelMap.put("vehicles", vehicles);
return "/catalog/" + view;
}
}
IncludeController
:
@Controller
public class IncludeController{
@Resource
VehicleCatalogAPIService vehicleCatalogAPIService;
@RequestMapping(value = "/fragment/test", produces = "text/html")
public String test(ModelMap modelMap,
@RequestParam("view") String view,
@RequestParam("test") String test,
@RequestParam("vehicleId") String vehicleId,
Locale locale) {
Vehicle particularVehicle = vehicleCatalogAPIService.get(vehicleId);
modelMap.put("vehicle", vehicle);
return "/catalog/vehicle/fragments/" + view;
}
@RequestMapping(value = "/fragment/test2", produces = "text/html")
public String test(ModelMap modelMap,
@RequestParam("test") String test,
@RequestParam("view") String view,
Locale locale) {
return "/catalog/vehicle/fragments/" + view;
}
}
我在浏览器中点击页面:
调用ViewController并返回必须呈现的jsp页面,在本例中为/catalog/listing.jsp
。JSP如下所示:
<jsp:useBean id="vehicles" type="java.util.List<com.sm360.auto.webauto.webapplib.bean.display.VehicleDisplayBean>" scope="request"/>
<h1> LISTING JSP </h1>
<div>
<c:forEach items="${vehicles}" var="vehicle" begin="${k.index}" end="${k.index + k.step-1}">
<div class="c-item-out">
<content:sheet-new-vehicule vehicle="${vehicle}" isCompact="true" hasCompared="true" />
</div>
</c:forEach>
</div>
<jsp:include page="/fragment/test">
<jsp:param name="view" value="view1"/>
<jsp:param name="vehicle1" value="vehicle1"/>
<jsp:param name="test" value="test1"/>
</jsp:include>
清单JSP
该include现在使用3个参数调用IncludeController:view、vehicleId和test。调用正确的方法并返回正确的视图(view1)
view1包含另一个功能,包括:
<jsp:useBean id="vehicle" type="com.sm360.auto.webauto.webapplib.bean.display.VehicleDisplayBean" scope="request"/>
<h1> view 1 </h1>
<div>
<h2>${vehicle.name}
</div>
<jsp:include page="/fragment/test2">
<jsp:param name="view" value="view2"/>
<jsp:param name="test" value="test2"/>
</jsp:include>
视图1
${vehicle.name}
在第二次调用中,view参数将是“view2,view1”,test参数将是“test2,test1”
我希望第二个include拥有它传递给控制器的参数的自己的值,而不是来自另一个调用的合并
编辑:
按照此图,当视图呈现过程中遇到
时,该过程是否返回到前控制器,并将请求重新委托给include
标记中指定的控制器,该控制器具有更新参数的相同请求
有可能有一组新的参数吗?很难:在设置下一个参数之前,您能从中查看
条目吗?我在想,请张贴您的代码以澄清
@RequestMapping("/helloWorld")
public String helloWorld(Model model) {
model.remove("view");
model.addAttribute("view", "foobar");
return "helloWorld";
}
你能粘贴有问题的控制器方法吗?你能说明视图包含对同一个或另一个控制器的另一个调用是什么意思吗?是否有链接、表单提交?该视图中有一个
标记。它调用给定的url并将输出呈现在它所在的位置。我想到了这一点,但我需要一个更通用的解决方案,因为问题将发生在其他参数上,而不仅仅是像我的示例那样的“视图”参数。我已经更新了一些代码和另一个示例。使用modelMap.clear()清除模型怎么样?我想这太笼统了(我只在重定向之前使用它)。如果是这样,您实际上是在寻找替换值的方法,而不是删除它们。如何从视图中调用第二次,在视图中,值被追加而不是替换?您是从JSP生成
标记还是用Java调用它?我将更新我的问题,我认为我的方法在这里是错误的。这种附加行为在某些情况下是有用的。