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

相关推荐
loading小马3 小时前
Mybatis-Plus超级实用的多种功能用法
java·spring boot·后端·maven·mybatis
高山上有一只小老虎7 小时前
mybatisplus分页查询版本 3.5.8 以下和版本 3.5.9及以上的区别
java·spring boot·mybatis
人道领域7 小时前
javaWeb从入门到进阶(MyBatis拓展)
java·tomcat·mybatis
J2虾虾16 小时前
SpringBoot和mybatis Plus不兼容报错的问题
java·spring boot·mybatis
pp起床1 天前
【苍穹外卖】Day03 菜品管理
java·数据库·mybatis
九皇叔叔1 天前
【01】SpringBoot3 MybatisPlus 工程创建
java·mybatis·springboot3·mybatis plus
BD_Marathon1 天前
MyBatis逆向工程之清晰简洁版
mybatis
九皇叔叔1 天前
【02】SpringBoot3 MybatisPlus 加入日志功能
java·mysql·mybatis·日志·mybatisplus
齐 飞1 天前
MybatisPlus真正的批量新增
spring boot·mybatis
小北方城市网1 天前
Spring Cloud Gateway 生产问题排查与性能调优全攻略
redis·分布式·缓存·性能优化·mybatis