Spring MVC Form表单 参数绑定异常

q539816590 q539816590 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
异常如下:

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute


Controller view方法:

@RequestMapping("/view")
public String view(@ModelAttribute("orderOid") BigDecimal orderOid,
Errors errors, Model model, HttpSession session) throws Exception
{
OrderHolder orderHolder = orderService.queryOrderByOid(orderOid);
//中间的代码就不写了
model.addAttribute("promotionOid", BigDecimal.ZERO);
model.addAttribute("order", orderHolder);
model.addAttribute("promotionList", promotionList);
session.setAttribute(SESSION_UNPAID_ORDER, orderHolder);

return "/order/view";
}


JSP view 页面:

<form:form cssClass="cmxform form-horizontal tasi-form" id="submitForm" method="post" action="">
<div class="form-group">
<label for="Title" class="promotion">
<s:message code="label.order.total.price"/>:
</label>
<div class="col-lg-5">
<span class="price">
<fmt:formatNumber value="${order.totalAmt}" pattern="#,##0.00"/>
</span>
</div>
</div>
<!--中间代码不写了-->
<div class="form-group">
<label for="Title" class="promotion">
<s:message code="label.order.select.promotion"/>
</label>
<div class="col-lg-5">
<form:select id="promo" path="promotionOid" cssClass="select" size="1">
<form:option value="" label="<s:message code='label.please.select'/>"/>
<form:options items="${promotionList}" itemLabel="description" itemValue="oid" />
</form:select>
</div>
</div>
</form:form>


执行controller view方法,最后跳转到view页面,但是在呈现view页面时,一直报异常,难道我使用spring form表单,必须要在后台实例化一个POJO对象传给页面么?
我的view页面提交form时,只需要提交一个spring select标签(属性是promotionOid),依据我以前struts的使用,根本不需要使用一个POJO对象去接收它, 只需要在后台使用String对象接收这个promotionOid就行了,为什么出异样呢,求解释。
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
q539816590
Web 开发 81,108 成员 341,721 内容