[java] view plaincopy
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date receiveAppTime;
如上,在對應的屬性上,加上指定日期格式的註解,本人親自測試過,輕松解決問題!
需要 import org.springframework.format.annotation.DateTimeFormat;
轉換函數位於spring-context.jar包中
方法二:控制器Action中加入壹段數據綁定代碼
[java] view plaincopy
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); //true:允許輸入空值,false:不能為空值