SpringMVC: spring form 里 inputform 必须要有一个 modelattribute 吗?

2017-12-11 18:21:00 +08:00
 esolve

一般来说 spring form 如下用:

<form:form id="inputForm" modelAttribute="product" action="${ctx}/product/add" method="POST"\>

<form:input path="name" id="name"/>

需要后端传一个 product bean,而提交的也是 product.name

现在我想要的页面 randominput.jsp 诸如

<form:form id="inputForm" action="${ctx}/randomthings/add" method="POST"\>
<form:input path="type" type="hidden" id="type"/>
<form:input path="applePrice" id="applePrice"/>

<form:input path="location" id="location"/>

location 和 applePrice 并不在同一个 bean 内

后台大致是

 @RequestMapping(value = {"addVouchers"}, method = RequestMethod.GET)
 public String addVouchers(Model model) {
    String type = getType();
    model.addAttribute("type",type);
    return "modules/randominput";
}

这样做结果却是 java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute

如何解决啊?

2248 次点击
所在节点    问与答
1 条回复
esolve
2017-12-11 21:07:04 +08:00
顶顶顶

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/413850

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX