【MyBatis中报错‘Error querying database. Cause: java.lang.NumberFormatException: For input string: “XX】

这篇具有很好参考价值的文章主要介绍了【MyBatis中报错‘Error querying database. Cause: java.lang.NumberFormatException: For input string: “XX】。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

MyBatis中报错‘Error querying database. Cause: java.lang.NumberFormatException: For input string: “XXX”’解决方案

SpringBoot项目中通过MyBatisPlus在mapper中查询数据时报错:【通用异常:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: java.lang.NumberFormatException: For input string: “Y”
Cause: java.lang.NumberFormatException: For input string: “Y”】

error querying database. cause: java.lang.numberformatexception: for input s,mybatis,数据库,java,spring boot

mapper中代码:

<if test="dto.insuCode != null and dto.insuCode !='' and dto.insuCode=='Y'">
	and t.insu_code IS NOT NULL
 </if>

查资料得知,报错原因为:mybatis是用OGNL表达式来解析的,在OGNL的表达式中,'Y’会被解析成字符,java是强类型的,char 和 一个string 会导致不等,所以if标签中的sql不会被解析,需要将’Y’改为"Y",或者加 .toString() 来转换。

所以可以将代码改为如下【注意 " 与 ‘ 的使用】:

<if test='dto.insuCode != null and dto.insuCode !="" and dto.insuCode=="Y"'>
	and t.insu_code IS NULL
</if>

或者将字符转为字符串,改为:文章来源地址https://www.toymoban.com/news/detail-842425.html

<if test="dto.insuCode != null and dto.insuCode !='' and dto.insuCode=='Y'.toString()">
	and t.insu_code IS NOT NULL
</if>

到了这里,关于【MyBatis中报错‘Error querying database. Cause: java.lang.NumberFormatException: For input string: “XX】的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed异常

    异常信息: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; neste

    2024年03月13日
    浏览(48)
  • Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown

    ### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column \\\'hx_user\\\' in \\\'field list\\\'  解释:查询数据库错误。原因:com.mysql.jdbc.exceptions.jdbc4。MySQLSyntaxErrorException:字段列表中的未知列“ hx_user ”  可以看见是UserInfoApi实现类出错了,可以 tb_user_info 表进行操

    2024年02月12日
    浏览(29)
  • Error updating database. Cause: java.sql.SQLSyntaxErrorException:

    出现这个错误说明SQL语句出现问题,当前字段和数据库表中字段不一致。 解决办法:与数据库表中字段对比一下,当前字段是否是表中字段,或者对比当前字段是否是和表中字段一致。 例:    

    2024年02月16日
    浏览(28)
  • 【解决问题】Error updating database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your S

    在更新数据时候遇到如下报错信息: Error updating database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘order’’ at line 4 1、先检查自己的字段是否正确匹配,可能是字符出现了错误 2、还有

    2024年02月11日
    浏览(53)
  • Java.lang.NumberFormatException: null

    在Java编程中, java.lang.NumberFormatException: null 是一个常见的异常错误。它表示尝试将一个空值(null)转换成数字时发生了错误。 该异常通常发生在以下情况下: 尝试将一个空字符串转换为数字。例如,使用 Integer.parseInt(null) 或 Double.parseDouble(null) 。 尝试使用一个空值变量进行

    2024年02月08日
    浏览(33)
  • java.lang.NumberFormatException 如何解决

    java.lang.NumberFormatException 表示在将字符串转换为数值类型时发生了格式错误。这通常发生在使用像 Integer.parseInt(String) 、 Double.parseDouble(String) 等方法时,而提供的字符串不能正确解析为相应的数值类型。 以下是一些可能导致 NumberFormatException 的常见原因以及相应的解决方法:

    2024年04月15日
    浏览(23)
  • Java.lang.NumberFormatException 异常及处理方法

    Java.lang.NumberFormatException 异常及处理方法 引言: 在Java编程中,我们常常遇到各种异常情况。其中之一是 java.lang.NumberFormatException 异常,它表示将字符串转换为数字时出现错误。本文将介绍 NumberFormatException 异常的原因、示例代码以及相应的解决办法,帮助开发者更好地理解和

    2024年02月08日
    浏览(36)
  • java.lang.NumberFormatException: For input string: ““问题修复

    在进行数字的格式化时出现了异常,比如我这里遇到的就是使用Long.parseLong(param)方法时,参数param传入了一个空的字符串\\\"\\\",导致了异常的发生。 在使用Long.parseLong(参数)方法时,先判断参数param是否不为空字符串,即可避免该问题。 对于java.lang.NumberFormatException: For input strin

    2024年02月09日
    浏览(38)
  • java.lang.NumberFormatException: null的原因及解决方案

    查找到了异常是出现在  paseInt() 方法中,在 String 类在转换成 Int 类时, 存在转换失败或空值的隐患 ,代码如下: 为了消除转换该隐患,当转换失败或为 null 时,使用默认值来代替转换失败的值,代码如下: 测试之后,java.lang.NumberFormatException: null 的异常没有再出现。在开

    2024年02月15日
    浏览(52)
  • 【Neo4j】SOLVED:java.lang.RuntimeException: Error starting Neo4j database server

    问题描述:Neo4j 数据库服务启动失败 java.lang.RuntimeException: Error starting Neo4j database server 问题分析:APOC插件问题 解决办法1: 关闭APOC占用程序进程( zulu platform x64 architecture ), 重启Neo4j 数据库   解决办法2:卸载APOC,重装与Neo4j 数据库对应版本 neo4j-contrib/neo4j-apoc-procedures -

    2024年02月12日
    浏览(49)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包