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 中.

相关推荐
R***z1016 小时前
Spring Boot 整合 MyBatis 与 PostgreSQL 实战指南
spring boot·postgresql·mybatis
妄汐霜10 小时前
小白学习笔记(MyBatis)
笔记·学习·mybatis
Java成神之路-13 小时前
Spring 整合 MyBatis 全流程详解(附 Junit 单元测试实战)(Spring系列6)
spring·junit·mybatis
weixin_425023001 天前
PG JSONB 对应 Java 字段 + MyBatis-Plus 完整实战
java·开发语言·mybatis
AlunYegeer1 天前
MyBatis 传参核心:#{ } 与 ${ } 区别详解(避坑+面试重点)
java·mybatis
ictI CABL2 天前
Spring Boot与MyBatis
spring boot·后端·mybatis
lclcooky2 天前
Spring 中使用Mybatis,超详细
spring·tomcat·mybatis
椰汁菠萝2 天前
Mybatis-plus + PostgreSQL json格式类型转换异常
postgresql·json·mybatis
TlYf NTLE2 天前
Spring Boot3.3.X整合Mybatis-Plus
spring boot·后端·mybatis
qqacj2 天前
SpringBoot【十一】mybatis-plus实现多数据源配置,开箱即用!
spring boot·后端·mybatis