首先引入jodatime jar
代码语言:javascript复制<dependency>
<groupId>joda-timegroupId>
<artifactId>joda-timeartifactId>
<version>2.9.9version>
dependency>
Controller方法通过@DateTimeFormat注解来接收参数
代码语言:javascript复制@RequestParam("time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date time
传入值?time=2017-12-12
也可通过实体接收
代码语言:javascript复制@InitBinder("query")
public void initBinderQuery(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
binder.setFieldDefaultPrefix("query.");
}
传入值?query.time=2017-12-12