mybatis将返回的多条数据映射为一条数据的多个字段

最近在开发一个权限管理系统,用户是两张表组合的,分别是基础属性表和扩展属性表
基础属性表 pluto_user

id user_name remarks
1 曹操 热爱加班
2 曹丕 热爱吃饭
3 蔡徐坤 喜欢唱、跳、rap、篮球
4 郭嘉 喜欢唱、跳、rap、篮球
5 荀彧 办事效率高
6 程昱 喜欢写代码
7 夏侯渊 精通java

扩展属性表 pluto_user_cust_attr

attribute_name attribute_value user_id
phone 17605018833 1
married true 1
birthday 1995年12月12日 1
phone 17605018833 2
married true 2
birthday 1995年12月12日 2
post 运维 1
post 开发 2
post 测试 3
married false 3
phone 17605018833 3
post 运维 4
married true 4
phone 13523456789 4

一个扩展属性就对应一行,最后要把这两张表映射成一个对象传给前端
但是查出来结果不对,比如我的查询sql是

select p1.*, p2.attribute_name, p2.attribute_value
from  pluto_user p1 left join  pluto_user_cust_attr p2 on p1.id = p2.user_id where p1.id = 1;

结果

id user_name remarks attribute_name attribute_value
1 曹操 热爱加班 1 phone
1 曹操 热爱加班 1 married
1 曹操 热爱加班 1 birthday
1 曹操 热爱加班 1 post

返回的是多个对象,要映射为一个对象,传给前端:

{
   
    "id": 1,
    "userName": "曹操",
    "remarks": "热爱加班",
    "customAttributes": {
   
      "birthday": "1995年12月12日",
      "post": "运维",
      "phone": "17605018833",
      "married": "true"
    
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值