SSM整合,增删改查,写到改时出现400错误
Controller代码
//跳转到修改页面
@RequestMapping("/toUpdateGoods")
public String toUpdateGoods(int id,Model model) {
Goods goods = goodsService.queryGoodsById(id);
System.out.println(goods);
model.addAttribute("QGoods",goods);
return "updateGoods";
}
//修改书籍
@RequestMapping("/updateGoods")
public String updateGoods(Model model, Goods good) {
System.out.println("updateGoods=>"+good);
goodsService.updateGoods(good);
Goods goods = goodsService.queryGoodsById(good.getGoodsID());
model.addAttribute("Goods", goods);
return "redirect:/Goods/allGoods";
}
HTML代码
allGoods.jsp
<tr>
<td>${goods.goodsID}</td>
<td>${goods.goodsName}</td>
<td>${goods.goodsPrice}</td>
<td>${goods.goodsQuantity}</td>
<td>
<a href="${pageContext.request.contextPath}/Goods/toUpdateGoods?id=${goods.goodsID}">更改</a> |
<a href="${pageContext.request.contextPath}/Goods/del/${goods.goodsID}">删除</a>
</td>
</tr>
updateGoods.jsp
<form action="${pageContext.request.contextPath}/Goods/updateGoods" method="post">
<input type="hidden" name="goodsID" value="${goods.getGoodsID()}"/>
货物名称:<input type="text" name="goodsName" value="${goods.goodsName()}"/>
货物单价:<input type="text" name="goodsPrice" value="${goods.goodsPrice()}"/>
货物数量:<input type="text" name="goodsQuantity" value="${goods.goodsQuantity() }"/>
<input type="submit" value="提交"/>
</form>