當前位置:編程學習大全網 - 網站源碼 - springmvc mybatis怎麽把mysql的時間格式化

springmvc mybatis怎麽把mysql的時間格式化

方法壹:實體類中加日期格式化註解

[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:不能為空值

  • 上一篇:羅源扮演者
  • 下一篇:用div+css如何做曲線圖
  • copyright 2024編程學習大全網