weixin_60977509 2023-03-07 17:15 采纳率: 100%
浏览 60
已结题

关于#java#的问题:为什么java中mysql有时候一对多查询数据不能整合

为什么java中mysql有时候一对多查询数据不能整合

 <resultMap type="PjtBudgetCategory" id="PjtBudgetCategoryResult">
        <result property="categoryId"    column="category_id"    />
        <result property="categoryName"    column="category_name"    />
        <result property="parentId"    column="parent_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="categoryStatus"    column="category_status"    />
    </resultMap>

    <resultMap id="PjtBudgetCategoryAndBudgetResult" type="PjtBudgetCategory" extends="PjtBudgetCategoryResult">
        <collection property="pjtBudgetList" notNullColumn="budget_id" javaType="java.util.List" resultMap="PjtBudgetResult" />
    </resultMap>

    <resultMap type="com.huato.project.domain.PjtBudget" id="PjtBudgetResult">
        <result property="budgetId"    column="budget_id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="budgetCategory"    column="budget_category"    />
        <result property="categoryId"    column="category_id"    />
        <result property="company"    column="company"    />
        <result property="nameSpecificationModel"    column="name_specification_model"    />
        <result property="unitPrice"    column="unit_price"    />
        <result property="quantity"    column="quantity"    />
        <result property="amount"    column="amount"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="billId"    column="bill_id"    />
        <result property="ancestorId"    column="ancestor_id"    />
    </resultMap>



select b.category_id, b.category_name, b.parent_id, a.remark, a.category_id,
        a.budget_id, a.user_id, a.user_name, a.company, a.name_specification_model, a.unit_price, a.quantity, a.amount, a.bill_id
        from pjt_budget a
        left join pjt_budget_category b on a.category_id = b.category_id
        where bill_id = #{billId}


查询的数据是这样


```java
msg: "操作成功",
code: 200,
data: [
{
searchValue: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null,
deleteTagging: null,
params: { },
categoryId: 28,
categoryName: "工资",
parentId: 0,
pjtBudgetList: [
{
searchValue: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null,
deleteTagging: null,
params: { },
budgetId: 1,
userId: null,
budgetCategory: null,
userName: "张三",
categoryId: 28,
company: "华图",
nameSpecificationModel: null,
unitPrice: 500,
quantity: 2,
amount: 1000,
billId: 69
}
],
totalAmount: null,
name: null,
categoryStatus: null,
ancestorId: null,
arranges: null
},
{
searchValue: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: "",
deleteTagging: null,
params: { },
categoryId: 28,
categoryName: "工资",
parentId: 0,
pjtBudgetList: [
{
searchValue: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: "",
deleteTagging: null,
params: { },
budgetId: 2,
userId: null,
budgetCategory: null,
userName: "李四",
categoryId: 28,
company: "华图",
nameSpecificationModel: "",
unitPrice: 500,
quantity: 1,
amount: 500,
billId: 69
}
],
totalAmount: null,
name: null,
categoryStatus: null,
ancestorId: null,
arranges: null
},
{
searchValue: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null,
deleteTagging: null,
params: { },
categoryId: 32,
categoryName: "外购材料",
parentId: 0,
pjtBudgetList: [
{
searchValue: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null,
deleteTagging: null,
params: { },
budgetId: 3,
userId: null,
budgetCategory: null,
userName: null,
categoryId: 32,
company: null,
nameSpecificationModel: "服务器100",
unitPrice: 3000,
quantity: 2,
amount: 6000,
billId: 69
}
],
totalAmount: null,
name: null,
categoryStatus: null,
ancestorId: null,
arranges: null
}
]
}

```

  • 写回答

2条回答 默认 最新

  • 嗝屁小孩纸 2023-03-07 18:35
    关注

    查出来就是这样呀,没问题吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月22日
  • 已采纳回答 3月14日
  • 修改了问题 3月7日
  • 创建了问题 3月7日

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分