oracle - 在 Mybatis 的另一个结果 Map 中选择 List of Department as Collection
问题描述
Java 8.0 版(Springboot),Oracle 数据库
我有我的java类 -
public class AllEmployee{
List<Employee> employees;
}
public class Employee {
String globalId;
int empId;
String name;
List<Department> departmentList;
}
public class Department {
int empId;
int depId;
String depValue;
}
MyBatis xml 配置 -
<resultMap id="empMapper" type="Employee">
<id property="globalId" column="globalId" />
<result property="empId" column="empId" />
<result property="name" column="name" />
<collection property="departmentList" javaType="ArrayList" ofType="Department"/>
<id property="empId" column="empId" />
<result property="depId" column="depId" />
<result property="depValue" column="depValue" />
</collection>
</resultMap>
<select id="retriveAllEmployees" resultMap="empMapper">
SELECT ee.empId, ee.name, dt.depId, dt.depValue FROM employee ee
INNER JOIN department dt on dt.empId = ee.empId
<where>
globalId IN
<foreach collection="globalIdList" item="globalId" separator=", " open="(" close=")">
#{globalId}
</foreach>
</where>
</select>
正确的 json 输出应该是 -
{
"employees": [
{
"empId": 1,
"name": "alton",
"departmentList": [
{
"depId": 2,
"depValue": "fire"
},
{
"depId": 4,
"depValue": "ice"
}
]
}
]
}
但是在以下 json 格式中得到错误的输出-(外部对象重复多次)
{
"employees": [
{
"empId": 1,
"name": "alton",
"departmentList": [
{
"depId": 2,
"depValue": "fire"
}
]
},
{
"empId": 1,
"name": "alton",
"departmentList": [
{
"depId": 4,
"depValue": "ice"
}
]
}
]
}
从 mybatis 获取对象后,我可以使用流和对象操作更正响应,但我需要 mybatis 中的正确方法将其直接转换为我们想要的对象。谁能纠正我,我在这个 xml 代码中缺少什么。
解决方案
推荐阅读
- python - “视图函数未返回有效响应”在哪里。我的 Flask 应用程序出错?
- java - 网址没有发回响应......也没有例外
- python - 属性错误:“无类型”对象没有属性“get_text”
- java - Android rxJava 多响应
- r - R中带有NA的条件转置
- r - 如何将 RShiny reactiveFileReader 与 reactiveUI 和不存在的文件一起使用?
- java - 使用 JSON 正文发送 POST 请求时出现 400 响应
- python - 在 AWS lambda 和 API 网关中部署 Flask sqlalchemy 应用程序
- php - 在角度使用 http.post('phpfile.php') 时将参数传递给 php 文件
- python-3.x - 网页抓取天气数据 400 错误