我正在开发带有注释的 Spring MVC。我还没有注册任何 customDateEditory
在我的班级中,我有一个 java.lang.Date 类型的属性
我读到的是 customDateEditor 默认没有注册。但是当我提交带有空白日期的表单时,它会抛出非法ArgumentException
如果我输入日期然后提交它不会抛出异常
然后之后我将 BindingResult 作为参数添加到控制器方法现在它接受空白值
我没有在我的控制器中添加任何 initbinder
控制器
@Controller("orderController")
@RequestMapping(value = "/admin")
public class OrderController extends BaseController {
@RequestMapping(value = "/viewOrders.htm", method = RequestMethod.GET)
public String viewOrders(@ModelAttribute("searchOrder") SearchOrder searchOrder,BindingResult bindingResult,Model model) {
List<Order> orders=orderService.getOrders(searchOrder);
model.addAttribute("orders", orders);
return "order/searchOrder";
}
}
Pojo 包含日期字段
public class SearchOrder {
private Integer orderId;
private Long customerId;
private String customerPo;
private Date dateCreatedFrom;
private Date dateCreatedTo;
private Date dateUpdatedFrom;
private Date dateUpdatedTo;
public Integer getOrderId() {
return orderId;
}
public void setOrderId(Integer orderId) {
this.orderId = orderId;
}
public Long getCustomerId() {
return customerId;
}
public void setCustomerId(Long customerId) {
this.customerId = customerId;
}
public String getCustomerPo() {
return customerPo;
}
public void setCustomerPo(String customerPo) {
this.customerPo = customerPo;
}
public Date getDateCreatedFrom() {
return dateCreatedFrom;
}
public void setDateCreatedFrom(Date dateCreatedFrom) {
this.dateCreatedFrom = dateCreatedFrom;
}
public Date getDateCreatedTo() {
return dateCreatedTo;
}
public void setDateCreatedTo(Date dateCreatedTo) {
this.dateCreatedTo = dateCreatedTo;
}
public Date getDateUpdatedFrom() {
return dateUpdatedFrom;
}
public void setDateUpdatedFrom(Date dateUpdatedFrom) {
this.dateUpdatedFrom = dateUpdatedFrom;
}
public Date getDateUpdatedTo() {
return dateUpdatedTo;
}
public void setDateUpdatedTo(Date dateUpdatedTo) {
this.dateUpdatedTo = dateUpdatedTo;
}
@Override
public String toString() {
return "SearchOrder [orderId=" + orderId + ", customerId=" + customerId
+ ", customerPo=" + customerPo + ", dateCreatedFrom="
+ dateCreatedFrom + ", dateCreatedTo=" + dateCreatedTo
+ ", dateUpdatedFrom=" + dateUpdatedFrom + ", dateUpdatedTo="
+ dateUpdatedTo + "]";
}
}
请投一些光