处理SpringMVC的时间错误:FielderrorinobjectsysDatumed。。。
错误:
⼗⼀⽉ 27, 2017 8:26:11 下午 org.StandardWrapperValve invoke
严重: Servlet.service() for servlet [springMvc] in context with path [/PrintingSystem] threw exception [Request processing failed; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBind Field error in object 'sysDatumedetai' on field 'storagetime': rejected value [2017-11-27]; codes [typeMismatch.sysDatumedetai.storagetime,typeMismatch.storagetime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework. org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'sysDatumedetai' on field 'storagetime': rejected value [2017-11-27]; codes [typeMismatch.sysDatumedetai.storagetime,typeMismatch.storagetime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework. at org.hod.solveArgument(ModelAttributeMethodProcessor.java:111)
at org.hod.solveArgument(HandlerMethodArgumentResolverComposite.java:75)
at org.hod.MethodArgumentValues(InvocableHandlerMethod.java:156)
at org.hod.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:117)
at org.springframework.web.hod.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.hod.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.hod.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.hod.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at at.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.tor.CoyoteAdapter.service(CoyoteAdapter.java:408)
at http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at at.util.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)
at at.util.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)
at urrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at urrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
因为菜鸟所以这个问题弄了挺久的,这个是时间的问题。
因为springMVC没有没办法把字符串转换成⽇期类型,所以需要⾃定义参数绑定
前端控制器接收到请求后,到注解形式的处理器适配器
所以我在l的配置⽂件中加了这些写代码
/**
* 时间的新增必须要经过处理,因为springMVC没有没办法把字符串转换成⽇期类型。所以需要⾃定义参数绑定
* 前端控制器接收到请求后,到注解形式的处理器适配器,
* <!-- ⽇期转换必须放在<mvc:annotation-driven />前⾯ -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean>
<!-- 注解⽅式 -->
<mvc:annotation-driven conversion-service="conversionService">
</mvc:annotation-driven>
<!-- 配置⽇期转换器 -->
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="zhu.util.DateConverter"></bean>
</set>
</property>
</bean>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:mvc="/schema/mvc" xmlns:xsi="/2001/XMLSchema-instance"
xmlns:p="/schema/p" xmlns:context="/schema/context"
xsi:schemaLocation="/schema/beans
菜鸟教程springmvc/schema/beans/spring-beans-3.1.xsd
/schema/context
/schema/context/spring-context-3.1.xsd
/schema/mvc
/schema/mvc/spring-mvc-3.1.xsd">
<!-- ⾃动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
<context:component-scan base-package="zhu.web">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- ⽇期转换必须放在<mvc:annotation-driven />前⾯ -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean>
<!-- 注解⽅式 -->
<mvc:annotation-driven conversion-service="conversionService">
</mvc:annotation-driven>
<!-- 配置⽇期转换器 -->
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="zhu.unitl.DateConverter"></bean>
</set>
</property>
</bean>
<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<!--mvc配置视图解析 -->
<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!--跳转的时候只⽤写jsp名字,不⽤带后缀,因为默认的后缀“.jsp”,路径为“/WEB-INF/jsp” -->
</beans>
然后再创建⼀个时间⼯具类
package zhu.unitl;
SimpleDateFormat;
import java.util.Date;
import verter.Converter;
/**
* 时间处理
* @author XiaoZhu
*
*/
public class DateConverter implements Converter<String, Date>{
@Override
public Date convert(String source) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
return simpleDateFormat.parse(source);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
这些都是上⽹了好久的
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论