转载自: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. RHEL7启动到命令模式

    打开/etc/inittab 文件会看到以下信息 从中知道想要启动后就进入完整的多用户文本模式(命令行模式) 以root权限执行: ln -sf /lib/systemd/system/multi-u ...

  2. waitpid()

    waitpid() pid_t waitpid(pid_t pid, int *status, int options); 参数: pid>0 只等待进程ID等于pid的子进程,不管其它已经有多 ...

  3. linux实操_shell自定义函数

    基本语法: #定义函数 function 函数名(){ 函数体 } #调用函数 函数名 参数1 参数2... 实例:计算两个数的和. 运行后

  4. Vue-main.js中的一些配置

    import Vue from 'vue' import App from './App.vue' import router from './router' import store from '. ...

  5. login.exp

    #!/usr/bin/expect ] ] ] ] spawn ssh -p $user@$host expect { "*yes/no*" {send "yes\r&q ...

  6. 第六章 Flask数据库(二)

    Flask-SQLALchemy Flask-SQLALchemy 是一个给你的应用添加 SQLALchemy 支持的 Flask 扩展. 它需要 SQLAlchemy 0.6 或更高的版本.它致力于 ...

  7. 后代元素 span:first-child{...}

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  8. linux笔试题

    1. cron 后台常驻程序 (daemon) 用于: A. 负责文件在网络中的共享 B. 管理打印子系统 C. 跟踪管理系统信息和错误 D. 管理系统日常任务的调度 2. 在大多数Linux发行版本 ...

  9. aspnet_regiis命令使用

    1.使用aspnet_regiis.exe加密web.config文件 http://www.cnblogs.com/MinSentinel/archive/2008/08/01/1258168.ht ...

  10. BZOJ 4241: 历史研究 ( 回 滚 )

    题目:  链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4241 题意:给你一个长度为n序列,m次查询,每次询问 一段区间 最大的  a[ i ...