作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Spring+Hibernate MVC 项目中执行 CRUD 时遇到问题,IDE 返回 HTTP Status 400 错误。我检查了一些链接,但它们不是解决方案:
这是我的jsp页面中的form:form:
<form:form action="quantity.do" method="GET" commandName="quantity">
<form:input type="hidden" path="quantityId" value="1"/>
<form:input type="hidden" path="clothes" value="<%= clothe%>"/>
<div style="height: 35px; width: 20%; float: left;">
Choose color:
</div>
<div style="height: 35px; width: 78%; float: left">
<form:select path="color">
<!--object Color-->
<form:option value="" label=" - choose color - "/>
<form:options items="${colors}" itemLabel="name"/>
</form:select>
</div>
<div style="height: 35px; width: 20%; float: left;">
Choose Size
</div>
<div style="height: 35px; width: 78%; float: left;">
<form:select path="size">
<!--object size-->
<form:option value="" label=" - choose size - "/>
<form:options items="${sizes}" itemLabel="sizeDescription"/>
</form:select>
</div>
<div style="height: 35px; width: 20%; float: left;">
Quantity:
</div>
<div style="height: 35px; width: 78%; float: left;">
<form:input type="number" path="quantityOfClothes"/>
</div>
<div style="width: 100%; height: 25px"></div>
<div style="height: 50px; width: 16%; float: left; margin-left: 50px">
<input type="submit" name="action" value="Add"/>
</div>
<div style="height: 50px; width: 16%; float: left; margin-left: 50px">
<input type="submit" name="action" value="Update"/>
</div>
<div style="height: 50px; width: 16%; float: left; margin-left: 50px">
<input type="submit" name="action" value="Cancel"/>
</div>
</form:form>
这是 Controller :
@RequestMapping(value = "/quantity.do", method = RequestMethod.GET)
public String doActions(@ModelAttribute Quantity quantity, @RequestParam String action, Map<String, Object> map) {
switch (action.toLowerCase()) {
case "add":
break;
case "update":
break;
case "cancel":
break;
}
return "quantity";
}
我的所有对象都是通过 Serialized 实现的,当我使用“添加”操作时,网址将显示:“http://localhost:8080/pinky_spring/quantity.do?quantityId=1&clothes=model.Clothes@229db7d5&color=model.Color@6b248b2f&size=model.Size@591a3a57&quantityOfClothes=1000&action=Add ”并出现此错误。请告诉我这里有什么问题以及如何解决这个问题,我是 Java Web 新手。
更新:这里是数量类
@Entity
@Table(name = "Quantity", schema = "dbo", catalog = "PinkyDB")
public class Quantity implements java.io.Serializable {
private int quantityId;
private Clothes clothes; //an object
private Color color; //an object
private Size size; //an object
private Integer quantityOfClothes;
private Set<ShoppingCart> shoppingCarts = new HashSet<ShoppingCart>(0);
public Quantity() {
}
public Quantity(int quantityId, Clothes clothes, Color color, Size size) {
this.quantityId = quantityId;
this.clothes = clothes;
this.color = color;
this.size = size;
}
public Quantity(int quantityId, Clothes clothes, Color color, Size size, Integer quantityOfClothes, Set<ShoppingCart> shoppingCarts) {
this.quantityId = quantityId;
this.clothes = clothes;
this.color = color;
this.size = size;
this.quantityOfClothes = quantityOfClothes;
this.shoppingCarts = shoppingCarts;
}
@Id
@Column(name = "QuantityID", unique = true, nullable = false)
public int getQuantityId() {
return this.quantityId;
}
public void setQuantityId(int quantityId) {
this.quantityId = quantityId;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ClothID", nullable = false)
public Clothes getClothes() {
return this.clothes;
}
public void setClothes(Clothes clothes) {
this.clothes = clothes;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ColorID", nullable = false)
public Color getColor() {
return this.color;
}
public void setColor(Color color) {
this.color = color;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SizeID", nullable = false)
public Size getSize() {
return this.size;
}
public void setSize(Size size) {
this.size = size;
}
@Column(name = "QuantityOfClothes")
public Integer getQuantityOfClothes() {
return this.quantityOfClothes;
}
public void setQuantityOfClothes(Integer quantityOfClothes) {
this.quantityOfClothes = quantityOfClothes;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "quantity")
public Set<ShoppingCart> getShoppingCarts() {
return this.shoppingCarts;
}
public void setShoppingCarts(Set<ShoppingCart> shoppingCarts) {
this.shoppingCarts = shoppingCarts;
}}
最佳答案
参数“clothe”必须是原始类型,在你的例子中,clothe是一个可序列化的对象,但它不能被浏览器自动序列化。
更新:你可以这样解决:
<form:input type="hidden" path="clothes.id" value="<%=clothe.getId()%>"/>
关于java - 使用 Spring MVC 进行 CRUD 时出现错误 "The request sent by the client was syntactically incorrect",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34573467/
我是一名优秀的程序员,十分优秀!