它有一些问题。因为它给了Http状态400- 客户端发送的请求在语法上是不正确的。当我提交。它没有到达控制器。请回顾和帮助。
<c:url var="addr" value="/productsPage"/>
<form:form method="POST" action="${addr}" modelAttribute="productsmodel" enctype="multipart/form-data">
<form:input type="hidden" path="productId" value="" />
<form:input type="hidden" path="vendorDetails" value="" />
<form:input type="hidden" path="productDetail" value="" />
<tr><td>Product Name:--</td><td><form:input type="text" path="ProductName" value=""/></td></tr>
<tr><td>Product Description:--</td><td><form:input type="text" path="ProductDescription" value="" /></td></tr>
<tr><td>Category:--
</td><td><form:input type="text" path="Category" name="categorylist" list="listcategory" />
<datalist id="listcategory">
<option value="Add New">
<c:forEach items="${all_categories}" var="all_categories">
<option value="${all_categories.categoryName}">
</c:forEach>
</datalist>
</td></tr>
<tr><td>Quantity/Unit:--</td><td><form:input type="text" path="quantityPerUnit" value="" /></td></tr>
<tr><td>Unit Price:--</td><td><form:input type="text" path="unitPrice" value="" /></td></tr>
<tr><td>Size:--</td><td><form:radiobutton path="size" value="1"/>L<form:radiobutton path="size" value="2"/>M<form:radiobutton path="size" value="3"/>S<form:radiobutton path="size" value="0"/>NA</td></tr>
<tr><td>Color:--</td><td><form:input type="text" path="color" value=""/></td></tr>
<tr><td>Discount:--</td><td><form:input type="text" path="discount" value=""/></td></tr>
<tr><td>Weight/Unit:--</td><td><form:input type="text" path="weight" value=""/></td></tr>
<tr><td>Units on Order:--</td><td><form:input type="text" path="unitsOnOrder" value=""/></td></tr>
<tr><td>Picture:--</td><td><input type="file" name="pictureLink" size="100" /></td></tr>
<tr><td></td><td><input type="submit" value="Save"/></td></tr>
</form:form>
</table>
控制器
{
@RequestMapping(value={"/productsPage"},method=RequestMethod.POST)
public String ProductPost(@ModelAttribute("productsmodel") Products products, Model model,@RequestParam("picture") MultipartFile file1){
System.out.println("In Post Products");
return "products";
}
}
模型 {
@Entity
@Table(name="Products")
public class Products
{
@Id
@GeneratedValue
@Column(name="ProductId")
private Integer productId;
@Column(name="productName")
private String ProductName;
@Column(name="productDescription")
private String ProductDescription;
@ManyToOne
@JoinColumn(name="category")
private Categories category;
@Column(name="quantityPerUnit")
private int quantityPerUnit;
@Column(name="unitPrice")
private BigDecimal unitPrice;
@Column(name="size")
private int size;
@Column(name="color")
private String color;
@Column(name="discount")
private BigDecimal discount;
@Column(name="weight")
private double weight;
@Column(name="unitsOnOrder")
private int unitsOnOrder;
@ManyToOne
@JoinColumn(name="vendorDetailsId")
private Vendor vendorDetails;
@OneToOne
@JoinColumn(name="ProductExtraDetails")
private ProductExtraDetails productDetail;
}
答案 0 :(得分:1)
谢谢。我明白了。
类别,productDetail和vendordetails已连接到其他表,并且必须添加其ID。 即productDetail.productID as path