我创建了一个这样的 Spring 表单:
索引.jsp
<a href="/Spring_MVC/order.jsp">Order</a>
订单.jsp
<form:form action="createOrder" method="Post" modelAttribute="order">
<table>
<tr>
<th>
Order ID:
</th>
<td>
<form:input path="order.orderId"/>
</td>
</tr>
<tr>
<th>
Product Name:
</th>
<td>
<form:input path="order.productName"/>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit"/>
</td>
</tr>
</table>
</form:form>
订单.java:
public class Order {
private String orderId;
private String productName;
/**
*
*/
public Order() {
}
public Order(String orderId, String productName) {
super();
this.orderId = orderId;
this.productName = productName;
}
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
}
订单控制器.java:
@Controller
public class OrderController {
private static final Logger logger = Logger.getLogger(LoginController.class.getName());
/**
*
*/
public OrderController() {
super();
}
@RequestMapping(value = "/createOrder", method=RequestMethod.POST)
public String createOrder(@ModelAttribute("order")Order order, BindingResult result) {
logger.log(Level.INFO, "Order ID: " + order.getOrderId());
logger.log(Level.INFO, "Product Name: " + order.getProductName());
// Implementation validator
// Data Binding the form properties to Order field
if (result.hasErrors()) {
logger.log(Level.INFO, "Error in Binding Result");
}
return "/order";
}
}
对于可用的 bean 名称顺序,我得到了既没有 BindingResult 也没有普通目标对象。我是否需要使用 GET 创建一个 bean 名称顺序并在 POST 回服务器之前先传递到网络。
请帮忙。谢谢。