4000 springMVC中日期格式转换问题
2016-10-21 16:46
441 查看
SpringMVC中不能自动将Spring转换成Date,所以要在Action实现类中添加日期转换器,用来转换日期格式,不然,jsp页面数据传输时会不能和javaBean实体类的属性相对应。在Action实现类中的构造方法后面添加initBinder方法
/**
* springMVC不能自动将String类型转换为Date类型
* 自定义类型转换器,将String-》Date类型(格式yyyy-MM-dd)
*/
@Override
protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) throws Exception {
//向springMVC内部注入一个自定义的类型转换器
//参数一:将String转成什么类型的字节码
//参数二:自定义转换规则
//true表示可以为空
binder.registerCustomEditor(Date.class,
new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
}
/**
* springMVC不能自动将String类型转换为Date类型
* 自定义类型转换器,将String-》Date类型(格式yyyy-MM-dd)
*/
@Override
protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) throws Exception {
//向springMVC内部注入一个自定义的类型转换器
//参数一:将String转成什么类型的字节码
//参数二:自定义转换规则
//true表示可以为空
binder.registerCustomEditor(Date.class,
new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
}
相关文章推荐
- oracle java中常用日期格式转换问题
- SpringMVC返回JSON数据时日期格式化问题
- SpringMVC使用@ResponseBody时返回json的日期格式及可能产生的问题
- Springmvc接收前台字符串类型日期格式转换
- SpringMVC日期类型转换问题三大处理方法归纳
- 日期格式转换问题
- SpringMVC日期类型转换问题三大处理方法归纳
- springMVC 页面传入日期报错问题处理:org.springframework.validation.BindException: org.springframework.validation.
- springMvc与fastJson 集成时日期格式的问题
- SpringMVC日期和编码问题
- SpringMVC返回JSON数据时日期格式化问题
- Springmvc中对日期类型的属性转换问题和自定义的参数解析器
- JavaEE_Mybatis_SpringMVC SpringMVC日期类型转换问题三大处理方法归纳
- SpringMVC同时使用<mvc:resources … />和日期转换Formatter时出现问题的解决方法
- SpringMVC日期类型转换问题三大处理方法归纳
- MySQL日期计算及格式转换问题
- SpringMVC使用Jackson返回JSON时日期少一天的问题
- springmvc学习笔记--json--返回json的日期格式问题
- springmvc提交数据到controller进行日期格式转换
- 关于日期格式转换问题