在Controller中如下定义方法
public PassQueryRequest trade(@ModelAttribute PassQueryRequest tradeRequest,
@RequestParam(value="startDate", required=true)Date startDate,
@RequestParam(value="endDate", required=true)Date endDate
1,在springmvc中使用对象接收参数时
在PassQueryRequest中,在日期属性的set方法中增加定义,以及maven配置
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
public Date getStartDate() {
return startDate;
}
joda-time
joda-time
${joda-time.version}
2,直接使用java.util.Date变量接收参数
@org.springframework.web.bind.annotation.InitBinder
public void InitBinder(
/* HttpServletRequest request, */ServletRequestDataBinder binder) {
// 不要删除下行注释!!! 将来"yyyy-MM-dd"将配置到properties文件中
// SimpleDateFormat dateFormat = new
// SimpleDateFormat(getText("date.format", request.getLocale()));
System.out.println("执行了InitBinder方法");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, null, new CustomDateEditor(dateFormat, true));
}