大规模编辑
假设我有两个不同的控制器。一个渲染视图,一个渲染<jsp:include>
标签。
ViewController
: _
@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;
}
}
我在浏览器中点击了页面:http ://example.com/en/new
调用 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>
该 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>
在第二次调用中,视图参数将是“view2,view1”,测试参数将是“test2, test1”。
我希望第二个包含有它自己传递给控制器的参数值,而不是来自另一个调用的合并。
编辑 :
按照这个图,当<jsp:include>
在视图渲染过程中遇到a时,流程是否会返回到Front Controller,并重新将请求委托给include
标签中指定的Controller,同样的请求更新了参数?
是否有可能拥有一组新的新参数?