我正在创建一个Spring MVC应用程序,使用大量的表单输入和带有多个List字段的模型属性。在我的jsp页面上,我有类似目录的东西,用户可以指定他想要的不同大小的产品&#39 ;订购。 index.jsp的:
<div class="catalog_element">
<img src="/resources/img/fb.png" width="250px" height="250px" class="product_image"/>
<h4>Фундаментные блоки</h4>
<div class="product_picker">
<div class="show_fb_content">
<img width="80px" height="40px" src="/resources/img/pointer_down.png">
</div>
<div class="fb_content">
<div class="product_item">
<h3>Размер L H B </h3>
<h3 class="amount_input">Кол</h3>
</div>
<c:forEach items="${FBContainer.products}" varStatus="i" var="product">
<div class="product_item">
<h3>${product.toString()}</h3>
<form:input cssClass="amount_input"
path="fbContainer.products[${i.index}].amount"/>
</div>
</c:forEach>
</div>
</div>
</div>
<div class="catalog_element">
<img src="/resources/img/roadplates.png" width="250px" height="250px" class="product_image"/>
<h4>Плиты перекрытия</h4>
<div class="product_picker">
<div class="show_fb_content">
<img width="80px" height="40px" src="/resources/img/pointer_down.png">
</div>
<div class="fb_content">
<div class="product_item">
<h3>Размер L H B </h3>
<h3 class="amount_input">Кол</h3>
</div>
<c:forEach items="${CPContainer.products}" varStatus="i" var="product">
<div class="product_item">
<h3>${product.toString()}</h3>
<form:input cssClass="amount_input"
path="cpContainer.products[${i.index}].amount"/>
</div>
</c:forEach>
</div>
</div>
</div>
因此,在forEach循环中,我为每种产品创建了一个金额输入。每种产品类型(其中有6种)都有自己的容器。 类似于CPContainer:
public class CPContainer implements Container {
private List<CPProduct> products;
private int id;
private int amount;
@Override
public List<CPProduct> getProducts() {
return products;
}
@Override
public CPProduct getProductById(int id) {
return products.get(id);
}
public void setProducts(List<CPProduct> products) {
this.products = products;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
@Override
public String toString() {
return "CPContainer{" +
"products=" + products +
", id=" + id +
", amount=" + amount +
'}';
}
}
答案 0 :(得分:2)
使用POST
方法代替GET。 GET请求生成请求参数,该参数在URL中可见。
像这样: