接收参数
前端传入日期参数如:2015-02-23 12:12:12
后端接收:
1)直接使用Date 作为形参直接接收
解决:就是在controller里面中的一个方法加上@InitBinder注解,例子如下:
@InitBinder
public void initBinder(WebDataBinder binder) {
DateFormat sdf_yyyyMMdd_hhmmss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf_yyyyMMdd_hhmmss.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf_yyyyMMdd_hhmmss, true));
binder.registerCustomEditor(Double.class, new CustomNumberEditor(Double.class,true));
binder.registerCustomEditor(String.class,new StringTrimmerEditor(false));
binder.registerCustomEditor(Long.class,new CustomNumberEditor(Long.class,true));
}
2)参数为POJO,date为其属性值时,属性上加@DateTimeFormat(pattern = “yyyy-MM-dd”),格式可调
3)直接使用String 格式接收时间格式字段
后端(mybatis)使用date作为参数sql查询
1)使