问题描述
Java 8.0 (Springboot),甲骨文数据库
我的 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,"depValue": "fire"
}
]
},{
"empId": 1,"departmentList": [
{
"depId": 4,"depValue": "ice"
}
]
}
]
}
一旦我从 mybatis 获取对象,我就可以使用流和对象操作来纠正响应,但是我需要在 mybatis 中以正确的方式将其直接转换为我们想要的对象。 谁能纠正我,我在这个 xml 代码中遗漏了什么。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)