spring mvc时间string转Date问题(一)
2016-02-20 16:34
411 查看
要在springMVC配置文件中加上:
<!-- 解析器注册 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="stringHttpMessageConverter"/>
</list>
</property>
</bean>
<!-- String类型解析器,允许直接返回String类型的消息 -->
<bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter"/>
在controller里:
@InitBinder
public void initBinder(WebDataBinder binder) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setLenient(true);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
加个这个注解一半是可以的。
<!-- 解析器注册 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="stringHttpMessageConverter"/>
</list>
</property>
</bean>
<!-- String类型解析器,允许直接返回String类型的消息 -->
<bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter"/>
在controller里:
@InitBinder
public void initBinder(WebDataBinder binder) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setLenient(true);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
加个这个注解一半是可以的。
相关文章推荐
- java分布式对象(RMI+部署使用RMI的程序)
- java 测试 solr更新和查询
- 初识 ScheduledThreadPoolExecutor
- Spring MVC 学习笔记 Viewresol和View
- 搭建持续集成单元测试平台(Jenkins+Ant+Java+Junit+SVN)
- 蓝桥杯 历届试题 打印十字图 java详解
- Java 集合系列03之 ArrayList详细介绍(源码解析)和使用示例
- eclipse常用快捷键
- Spark - ERROR Executor: Exception in tjava.lang.OutOfMemoryError: unable to create new native thread
- Mac上如何安装gradle以及eclipse上如何搭建gradle
- Java发送get及post请求工具方法
- Java认证考试实例疑难辨析(11)
- Spring 资源访问剖析和策略模式应用
- 夯实JAVA基本之一——泛型详解(2):高级进阶
- Servlet JNICALL Java_calcServlet_calc
- 夯实JAVA基本之一 —— 泛型详解(1):基本使用
- Spring DI
- 数组中出现次数超过一半的数字 -java
- JAVA多线程-线程间通信(二)-生产者/消费者模式实现
- java中截取字符串技巧