转载自:https://blog.csdn.net/Coder_Arley/article/details/81910705

springboot中报错如下:

springmvc也可以使用类似处理方法。其他参考:SrpingMVC通过JSON注入from数据到实体自定义(LocalDateTime,LocalDate,Boolean类型)字段的序列化、反序列化方法

java.lang.IllegalStateException: No primary or default constructor found for class java.time.LocalDate
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:)
at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:)
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:)

解决方法:在maven添加如下依赖

让框架可以处理jsr310的新日期、时间类

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.9</version>
</dependency>

任意一个带Configuration注解的类中添加以下代码

  @Bean
public Converter<String, String> StringConvert() {
return new Converter<String, String>() {
@Override
public String convert(String source) {
return StringUtils.trimToNull(source);
}
};
} @Bean
public Converter<String, LocalDate> LocalDateConvert() {
return new Converter<String, LocalDate>() {
@Override
public LocalDate convert(String source) {
if (StringUtils.isBlank(source)) {
return null;
}
return LocalDate.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
} };
} @Bean
public Converter<String, LocalDateTime> LocalDateTimeConvert() {
return new Converter<String, LocalDateTime>() {
@Override
public LocalDateTime convert(String source) {
if (StringUtils.isBlank(source)) {
return null;
}
return LocalDateTime.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} };

Controller里面添加注解@RequestParam(required=false)

@RequestMapping(value = "/test")
@ResponseBody
public String test(@RequestParam(required = false) LocalDate startDate) {
System.out.println(startDate);
return "success";
}

java.lang.IllegalStateException: No primary or default constructor found for class java.time.LocalDate的更多相关文章

  1. SpringMVC开发中遇到的异常1:No primary or default constructor found for interface java.util.List

    Request processing failed; nested exception is java.lang.IllegalStateException: No primary or defaul ...

  2. cause: java.lang.IllegalStateException: Serialized class com.taotao.pojo.TbItem must implement java.io.Serializable

    HTTP Status 500 - Request processing failed; nested exception is com.alibaba.dubbo.rpc.RpcException: ...

  3. java.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade

    2012-10-4 19:50:37 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for se ...

  4. struts2异常记录--java.lang.IllegalStateException

    java.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFa ...

  5. java.lang.IllegalStateException——好头疼

    在我东,下下来一个项目总会出现启动不了的问题,这些问题往往在编译的时候发现不了,当你的服务器启动的时候,就是一片片的报错,有些问题可以通过异常的提示信息,判断出来哪里配置错了,但是也有些情况下,从异常 ...

  6. java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context 错误

    spring boot 项目启动报错:原因一般是注入了相同名字的service -- :: com.gxcards.mes.MainWwwWeb: logStartupProfileInfo INFO ...

  7. 报错:java.lang.IllegalStateException: Cannot call sendError() after the response has been committed(待解答)

    严重: Servlet.service() for servlet [default] in context with path [/20161101-struts2-1] threw excepti ...

  8. response.sendRedirect 报 java.lang.IllegalStateException 异常的解决思路

    今天在进行代码开发的时候,出现了 java.lang.IllegalStateException异常,response.sendRedirect("./DEFAULT.html") ...

  9. 处理eclipse启动时报java.lang.IllegalStateException

    这是我写的第一篇博客,博客我来了: 我是好学的人,希望在这上面遇到志同道合的人,对技术有更高追求的人: 重启eclipse的时候报出来 An error has occurred, See the l ...

随机推荐

  1. jquery中prop,attr,data的区别

    这两天翻了jq的源码,今天看到了jq关于数据存储的几个方法,遂总结一下,和小伙伴没分享一下,哪里说的不对,还望批评指正~~~ 废话不多说,直接上代码: $(function(){ $('#div1') ...

  2. 浏览器获取当前ip

    function findIP(callback) { var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConn ...

  3. HDU 6735 结论网络流 机器人不重叠路径

    我们可以得到一个结论:没有两个机器人走过的路会重叠 所以题目就转变为了能不能让机器人的路径不重叠且每个机器人能到达终点 直接一个点朝他四连通方向的四个点连容量为1的边即可 #include<bi ...

  4. python+mysql:实现一千万条数据插入数据库

    作业要求 构建一个关系模式和课本中的关系movies(title,year,length,movietype,studioname,producerC)一样的关系,名称自定,在这个关系中插入1000万 ...

  5. spring lookup method 注入

           lookup method注入是spring动态改变bean里方法的实现.方法执行返回的对象,使用spring内原有的这类对象替换,通过改变方法返回值来动态改变方法.内部实现为使用cgl ...

  6. 实例化Vue时的两种挂载方式el与$mount

    el 与mount 都是挂载. el vue官网的介绍https://cn.vuejs.org/v2/api/#el mount vue官网的介绍 https://cn.vuejs.org/v2/ap ...

  7. ACM-ICPC 2018 徐州赛区现场赛 I. Rikka with Sorting Networks (思维+DFS)

    题目链接:https://codeforces.com/gym/102012/problem/I 题意:问有多少个 1 到 n 的排列,使得用给定的 k 个比较器(使 au 和 av 有序)排序后,整 ...

  8. winfrom 窗体首次加载

    #region Override Functions /// <summary> /// OnLoad /// </summary> /// <param name=&q ...

  9. P5043【模板】树同构([BJOI2015]树的同构)

    思路:树哈希 提交:1次 题解: 怕不是用的oi-wiki上的公式: \[f_u=size_u\times\sum f_{son_{u,i}}\times Base^{i-1}\] #include& ...

  10. 004_FreeRTOS创建与删除任务

    (一)创建与删除任务函数 (二)上面的四个函数目前只用动态创建任务和删除任务 (三)动态创建任务 函数 xTaxkCreate() 1. 宏 configSUPPORT_DYNAMIC_ALLOCAT ...