Mysql查询默认值 ''不等于java ""

标签 mysql spring-mvc mybatis

我正在使用Mybatis查询数据库

mysql表结构

enter image description here

parent_id 默认为 ''

插入值为

enter image description here

Mybatis获取值好像错误? , parent_id 应该是 "" 而不是 null 值?

enter image description here

最佳答案

如果 DB 中的值为空字符串,而 Java 对象中的值为 int/Integer,MyBatis 无法转换该列。要解决此问题,您可以:

  • 修改您的数据库,使parent_id默认为空
  • 修改您的选择查询并将列parent_id更改为IF(parent_id = '', null,parent_id)作为parent_id

关于Mysql查询默认值 ''不等于java "",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48040628/

相关文章:

php - 如何知道我的数据库中的表是否已更新?

MySQL 存储函数出现故障,但作为独立查询工作

php - Laravel 中的 Id 命名约定

java - Spring在jsp中使用不同的上下文和SpringBeanAutowiringSupport

java - 使用 AngularJS 和 Java Spring 发布表单数据

PHP 绑定(bind)变量、无效参数号错误或 PDO 更新语句

spring - 如何使用 Spring HATEOAS 更改 HAL 链接格式

java - HashMap 中的 MyBatis 参数

java - 如何执行mybatis-spring-boot-starter-test?

spring-boot - MockBean 和 MyBatis Mapper 不能一起工作(就像他们在 Spring Boot 2.2.7 之前所做的那样)