java.lang.IllegalStateException: No primary or default constructor found for class java.time.LocalDate
转载自: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的更多相关文章
- 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 ...
- 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: ...
- 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 ...
- struts2异常记录--java.lang.IllegalStateException
java.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFa ...
- java.lang.IllegalStateException——好头疼
在我东,下下来一个项目总会出现启动不了的问题,这些问题往往在编译的时候发现不了,当你的服务器启动的时候,就是一片片的报错,有些问题可以通过异常的提示信息,判断出来哪里配置错了,但是也有些情况下,从异常 ...
- java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context 错误
spring boot 项目启动报错:原因一般是注入了相同名字的service -- :: com.gxcards.mes.MainWwwWeb: logStartupProfileInfo INFO ...
- 报错: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 ...
- response.sendRedirect 报 java.lang.IllegalStateException 异常的解决思路
今天在进行代码开发的时候,出现了 java.lang.IllegalStateException异常,response.sendRedirect("./DEFAULT.html") ...
- 处理eclipse启动时报java.lang.IllegalStateException
这是我写的第一篇博客,博客我来了: 我是好学的人,希望在这上面遇到志同道合的人,对技术有更高追求的人: 重启eclipse的时候报出来 An error has occurred, See the l ...
随机推荐
- centos7防火墙相关
selinux(保护文件安全) 安全增强型 Linux(Security-Enhanced Linux)简称 SELinux,它是一个 Linux 内核模块,也是 Linux 的一个安全子系统. SE ...
- jade-render-renderFile
var http = require('http'); var jade = require('jade'); http.createServer(function(req, res){ res.wr ...
- Codeforces 1187 F - Expected Square Beauty
F - Expected Square Beauty 思路:https://codeforces.com/blog/entry/68111 代码: #pragma GCC optimize(2) #p ...
- springbatch
springbatch job的创建使用 job:作业,是批处理中的核心概念,是batch操作的基础单元,每个job由多个step组成 step:步骤,任务完成的节点 每个job是由JobBuildF ...
- 码云 VS首次提交代码报错:failed to push some refs to 'https://gitee.com/Liu_Cabbage/ASP.NET-MVC-QQ-Connect.git'
打开命令提示符: 执行合并命令: git pull --rebase origin master 最后总结: 1.多为第一次提交代码,本地和码云仓库不一致,README.md文件不在本地代码目录中 2 ...
- ln -s /usr/local/jdk1.8.0_201/bin/java /bin/java
ln -s /usr/local/jdk1.8.0_201/bin/java /bin/java
- Ubuntu Linux虚拟机与windows快速创建共享文件夹
有时候我们需要在windows下与远程Linux服务器传输文件,之前使用pscp传输文件很方便,但不方便传输多文件,同时也不便于查看.看了网上的教程总结创建共享文件夹的流程: 1.首先在本地windo ...
- 【leetcode】1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold
题目如下: Given a m x n matrix mat and an integer threshold. Return the maximum side-length of a square ...
- CAZAC序列
定义: CAZAC(Const Amplitude Zero Auto-Corelation),即为恒包络零自相关序列. 性质: 1,恒包络特性:任意长度的CAZAC序列幅值恒定. 2,理想的周期自相 ...
- word文档如何选择全部图片粘贴
很多时候我们用一些管理系统的时候,发布新闻.公告等文字类信息时,希望能很快的将word里面的内容直接粘贴到富文本编辑器里面,然后发布出来.减少排版复杂的工作量. 下面是借用百度doc 来快速实现这个w ...