springboot JPA 实现jpql查询时报错:org.springframework.core.convert.ConverterNotFoundException 解决方案

解决 No converter found capable of converting from type [java.lang.String] to type ... 的问题 今天在项目的启动类中,加上这行代码`@MapperScan("com.**.mapper")`后,启动项目时便报出下面的错误:No converter found capable of converting from type [java.lang.String] to type [@org.springframework.boot.context.properties.NestedConfigurationProperty org.apache.ibatis.session.Configuration]。 阅读详情

在接口中写入jpql语句想要查询表中的特定字段,接口中的代码如下:

    @Query("select unitName, createTime, status, serviceCount, averageEval from UnitDetail")
    List<UnitDetail> loadUnitDetailList();

使用postman测试时,存在错误信息如下:
·org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.Object[]] to type [@org.springframework.data.jpa.repository.Query com.remotegov.pojo.UnitDetail] for value '{1, 2021-07-08 16:28:12.0, 0, 1, 1}'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [@org.springframework.data.jpa.repository.Query com.remotegov.pojo.UnitDetail]

原因:
查询结果集封装到了Object[ ]中,并没有直接封装到unitDetail对象中,直接接收的话会产生转换异常。

解决方案:
方案1、将存储结果集的数组对象转换为Object[ ]类型;
方案2、由于Object[ ]类型操作不便,可以封装到实体类中,代码实现如下:
① 将字段值封装到对象中

    @Query("select new UnitDetail (unitName, createTime, status, serviceCount, averageEval) from UnitDetail")
    List<UnitDetail> loadUnitDetailList();

② 在实体类中添加字段对应的构造器

    public UnitDetail(String unitName, Date createTime, String status, String serviceCount, String averageEval) {
        this.unitName = unitName;
        this.createTime = createTime;
        this.status = status;
        this.serviceCount = serviceCount;
        this.averageEval = averageEval;
    }

运行后如下图,操作成功!
在这里插入图片描述

解决mongodb中BigDecimal和Decimal128互转异常 java 对象的使用BigDecimal 存入mongodb 时候,需要将BigDecimal 转成Decimal128 格式存储, 从mongodb中读取数据时候,需要将Decimal128转成BigDecimal 格式读取,否则就会报以下异常。 查询时异常 No converter found capable of converting from type [org.bson.types.Decimal128] to type [java.math.BigDecimal] 保存,修改时异常 阅读详情

相关推荐

软件工程期末知识点总结【超详细】

生命周期模型(过程模型):瀑布模型、快速原型模型、增量模型、螺旋模型、喷泉模型。2、实体联系图:1、数据对象2、属性3、联系(1:1、1:N、M:N)3、语句覆盖 就是设计足够的调试用例,使得程序中的每个语句至少执行一次。 5、判定覆盖就是设计足够的测试用例,使得程序中每个判定的取“真”分支和取“假”分支至少都执行一次,判定覆盖又称分支覆盖 6、条件覆盖就是设计足够的测试用例,使得程序判定中的每个条件能获得各种可能的结果。7、软件开发时期通常分成4个阶段:总体设计、详细设计、编码和单元测试、综合测试。

这个人好有趣....hh 1万+

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of convertin

Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.sql.Driver] at org.springframework.core.convert.support.GenericConversionService.handleConverter...

qigeshenm的博客 1万+

WPS专业版自带字体

WPS专业版其中一个好处就是自带了部分有版权的字体,就算你安装了没买授权,他也会给你在系统里面安装上这些字体,至于没授权继续用合不合规我不知道。但是带来的实实在在的好处就是有些子他支持的全啊。 /usr/share/fonts/wps-office/FZWBK.TTF: 方正魏碑_GBK,FZWeiBei\-S03:style=Regular /usr/share/fonts/wps-office/FZFSK.TTF: 方正仿宋_GBK,FZFangSong\-Z02:style=Regular /us

chenqioulin的博客 5707

springboot中传递时间字符串报格式不匹配

问题报错如下: nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@com.baomidou.mybatisplus.annotation.TableField java.util.Date] for value ‘2020-09-11 12:00:00’; nested exceptio

qq_40516010的博客 1498

无人机蜂群联合指挥作战技术详解

随着人工智能、通信技术、新材料等领域的不断进步,无人机蜂群联合指挥作战技术将迎来更加广阔的发展前景。未来,无人机蜂群将更加智能化、自主化,能够执行更加复杂、精细的作战任务。同时,加强国际合作,共同制定国际规则和标准,将是推动无人机蜂群技术健康发展的重要方向。无人机蜂群技术,是指通过先进的通信技术、自主导航与决策算法,将大量小型、低成本、功能各异的无人机组织成一个高度协同的群体,执行复杂多样的军事任务。2. 通信与数据链:采用高速、低延迟、抗干扰的通信技术,保障群体内无人机间的信息交换。

专注多旋翼、复合翼无人机技术研究,从事低空经济行业。 1546

从零搭建YOLOv2硬件加速器:基于PYNQ-Z2的Vivado HLS与Jupyter Notebook实战

本文详细介绍了如何从零搭建YOLOv2硬件加速器,基于PYNQ-Z2开发板,结合Vivado HLS与Jupyter Notebook实现高效目标检测。通过硬件加速,YOLOv2推理速度提升8倍,功耗降低80%。文章涵盖硬件准备、Vivado HLS工程配置、IP核集成、PYNQ部署及常见问题解决,为开发者提供完整实战指南。

weixin_29188997的博客 1008

nested exception is org.springframework.core.convert.ConverterNotFoundException

nested exception is org.springframework.core.convert.ConverterNotFoundException

ideal-lingyun 1562

VS Code配置Java开发环境避坑指南:从JDK到Spring Boot插件全流程

本文详细介绍了在VS Code中配置Java开发环境的完整流程,涵盖JDK选择、环境变量配置、核心插件安装、构建工具优化及Spring Boot项目专项设置。特别针对常见问题提供避坑方案,帮助开发者快速搭建高效稳定的开发环境,提升Java和Spring Boot开发效率。

weixin_28839699的博客 982

Java No converter found capable of converting from type问题解决

问题描述: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [com.pit.system.dto.SysUserRoleDto

旭东怪的博客 3万+

博途AI助手演示,完成简单且重复的梯形图代码,并导入到博途

自写个博途AI助手,下面演示AI帮我生成完善多个模拟量输入转换的代码,

gsjkwg的博客 1529

芒果YOLOv5改进05:损失函数IoU 篇之Repulsion Loss:原创改进损失函数 Repulsion:解决目标遮挡场景下检测,为解决密集人群检测中遮挡设计的损失函数,打造高效检测器涨点

YOLOv5改进代码实践|结合Repulsion 解决目标遮挡场景下检测🚀

包括YOLOv5、YOLOv7、YOLOv8等模型改进 4566

org.springframework.core.convert.ConversionFailedException

适用:1.你在springmvc.xml中写了静态资源处理&lt;mvc:resources location="/" mapping="/**"&gt;&lt;/mvc:resources&gt;2.你在springmvc.xml中写了日期类型转换解决方法:首先检测你的spring版本,然后1.spring3.0后将&lt;mvc:resources location="/" mapping=".

u013400631的博客 5141

大模型角色提示词写得再严密,也能被绕过?我用攻击者思维把自己吓了一跳!

很多人以为提示词是“只要写清楚了,模型就能理解”,但实际上——模型并不具备严格的规则意识,它只是在预测下一句话。所以我们必须从“攻防”角度出发,设计更强的防护机制。我这次就是亲身踩坑,用红队思维模拟攻击,才意识到原来提示词注入这么容易中招。你如果也在做 AI 应用、角色系统、提示词驱动的功能,建议你也用类似方式测试一下,不然被绕了都不知道。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 1028

spring boot从git上拉取配置文件,报错:org.springframework.core.convert.ConverterNotFoundException

使用config-server和config-client,配置后已经调通,新建的client服务可以从git上拉取配置文件。但是当在另外一个client服务上使用后,运行时报错:org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from typ...

午后拐角的博客 2527

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

【SpringBoot】日期格式转换问题

这段时间在学习使用 SpringBoot 做项目,由于是初次使用,过程中遇到不少坑,学习过程中,时间允许的话会通过写文章方式记录我的填坑之旅。此刻的状态 进入正题,我使用 SpringBoot 的时候,首先遇到的问题就是日期格式转换了。实体类中有时间类型的属性,往往会在前端与后台的数据交换中出现日期格式转换的问题,当然也有简单粗暴的方法,把属性设置为 S...

皮卡战记 6770

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

JPA使用原生SQL结果集映射的问题

JPA封装的原生方法无法满足复杂SQL的操作,而使用原生SQL导致结果集转换不到自定义对象上,报错,网络水军太多,记录一下

Caiden_Michael 3820

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Failed to convert from type [java.lang.String] to type [java.util.Date]

nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.Date] for value ‘2019-05-30 14:47:24’; nested exceptio...

Halo333的博客 3万+

解决JPA Native 查询不能使用投影(Projection)的问题 org.springframework.core.convert.ConverterNotFoundException:

问题原因 org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$Tu...

youngboy的博客 2万+

springboot关于日期报错No converter found capable of converting from type [java.util.Date] to type的解决

在页面对时间操作时报错:nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.Date] to type [@org.springframework.format.annotation.DateTimeFormat java.sql.Date]]],提示无法将java.util.

那条大鱼的博客 4952

JPA 报错 No converter found capable of converting from type [java.lang.Integer] to type [com.wchat.bea

在使用 Spring Data JPA 时遇到报错:No converter found capable of converting from type [java.lang.Integer] to type [com.wchat.bean.Group] 报错详细内容如下 org.springframework.core.convert.ConverterNotFoundException:...

悟世君子的博客 3万+

JPA踩坑记:Spring Data Jpa 原生SQL联表查询返回自定义DTO

ps: 注意SQL查寻出的字段名要与实体中的字段名一致,也可扩展工具类实现查寻出数据库原始字段名再转换的驼峰命名对应到实体中.ps: YyyDto是一个接口,这里返回的是JPA生成的YyyDto的代理类,是可以直接json序列化成json字符串的。方案4.@SqlResultSetMapping注解实现。方案5. 独创方案,自定义注解+注入convert实现。方案3.查寻出Map结果,利用工具类转换成需要的实体。方案1.HQL查询+实体全参数的构造方法。方案2.实体定义成接口的形式。

哇哇哇,真的学到了!!! 4756

mongoDBTemplate .convert.ConverterNotFoundException的解决

mongoDBTemplate .convert.ConverterNotFoundException的解决 org.springframework.core.convert.ConverterNotFoundException: 在利用mongodbTemplate做数据查询的时候,出现了该问题 问题解决 在利用Mongodb Template插入数据时,使用了upsert方法,导致被插入的数据并没有对应的实体类。class文件,因此当反向查询时并不能找到对应的实体类 所以就会报错。 解决方法是删除掉

qq_38721353的博客 1348

org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.util.Ar

org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.util.ArrayList<?> to type java.util.List<org.springframework.core.io.Resource> for value '[/jso...

sssyyy_hhh的博客 3661

spring boot升级到2.0.0.M7后报错ConverterNotFoundException for java.time.Duration的解决方案...

最近学习搭建spring boot的脚手架过程中,boot的版本升级成了2.0.0.M7,然后发现项目启动之后redis配置那块报了错。错误信息如下 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.redis-org.spring...

weixin_30734435的博客 1034
上一篇: Springboot banner 在线生成图案并配置在idea项目中
下一篇: Java数组的常用操作
Sun_lightYY
博客等级 码龄8年 7粉丝 35原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值