为什么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
}
]
}
```
查出来就是这样呀,没问题吧
不知道你这个问题是否已经解决, 如果还没有解决的话: