Mybatis查询数据库,返回List集合,集合元素也是List。

#有时间需求会要求:查询全校的学生数据,且学生数据按班级划分。那么就需要List<List<user>>类型的数据。

SQL语句

复制代码
SELECT JSON_ARRAYAGG(JSON_OBJECT('name' , name ,'BJMC', BJMC ,'BJBH',BJBH)) as dev_user 
FROM dev_user WHERE project_id = 1  GROUP BY BJBH

核心函数是 JSON_ARRAYAGG( JSON_OBJECT())

错误1:Incorrect parameter count in the call to native function 'JSON_OBJECT'

原因:JSON_OBJECT 函数的参数不是成对出现时。在 MySQL 中,JSON_OBJECT 需要成对的键值对输入,例如 JSON_OBJECT('key1', value1, 'key2', value2)。

错误2:Error querying database. Cause: java.lang.UnsupportedOperationException

原因:返回类型错误,mapper文件中接口返回不能是 List<List<user>> ,Mybatis 不支持嵌套list。先使用List<String>接收,后续在程序中将 String 转 List 存在 大List 中.

相关推荐
AlunYegeer17 分钟前
MyBatis 传参核心:#{ } 与 ${ } 区别详解(避坑+面试重点)
java·mybatis
ictI CABL20 小时前
Spring Boot与MyBatis
spring boot·后端·mybatis
lclcooky1 天前
Spring 中使用Mybatis,超详细
spring·tomcat·mybatis
椰汁菠萝1 天前
Mybatis-plus + PostgreSQL json格式类型转换异常
postgresql·json·mybatis
TlYf NTLE1 天前
Spring Boot3.3.X整合Mybatis-Plus
spring boot·后端·mybatis
qqacj1 天前
SpringBoot【十一】mybatis-plus实现多数据源配置,开箱即用!
spring boot·后端·mybatis
希望永不加班1 天前
SpringBoot 整合 MyBatis 完整实战
java·spring boot·后端·spring·mybatis
小红的布丁1 天前
Redis 内存淘汰与过期策略
java·spring·mybatis
zuowei28891 天前
SpringBootInvalid bound statement (not found)的原因和解决方案
mybatis
2601_949814491 天前
Spring-boot3.4最新版整合swagger和Mybatis-plus
mybatis