我是 Spring Boot 的新手。尝试从具有相关角色的员工集合中获取所有文档。当尝试使用“findAll()”方法从 mongo 存储库中获取所有员工文档时,我得到空角色,如下面的输出所示。Note : Roles are associated with each employee in MongoDB.REST 调用的输出[ { "id": 0, "name": null, "organization": null, "email": null, "password": null, "roles": null, "enabled": false, "skills": null }, { "id": 123, "name": "Harry", "organization": "Hollywood", "email": "harry@demo.com", "password": "HarryMovie", "roles": [], "enabled": true, "skills": [ "Performer", "Entertainer", "Actor", "Producer" ] }, { "id": 1902, "name": "Harry", "organization": "Hollywood", "email": "harry@demo.com", "password": "HarryMovie", "roles": [], "enabled": true, "skills": [ "Performer", "Entertainer", "Actor", "Producer" ] }]员工类package com.app.TestSecurityApp.Pojo;import org.springframework.data.annotation.Id;import org.springframework.data.mongodb.core.mapping.DBRef;import org.springframework.data.mongodb.core.mapping.Document;import java.io.Serializable;import java.util.List;import java.util.Set;@Document(collection="employee")public class Employee implements Serializable { @Id private int id; private String name; private String organization; private String email; private String password; @DBRef private List<Role> roles; private boolean enabled; private List <String> skills; public Employee() { } public List <Role> getRoles() { return roles; } public void setRoles(List <Role> roles) { this.roles = roles; } public boolean isEnabled() { return enabled; } public void setEnabled(boolean enabled) { this.enabled = enabled; }
1 回答
九州编程
TA贡献1785条经验 获得超4个赞
它没有正确序列化,因为它没有实现标记接口。更改public class Role
为public class Role implements Serializable
。
也不需要@DBRef,它用于将父级和子级作为单独的文档与引用一起存储在数据库中。向所有类添加序列化,使文档嵌入。
添加回答
举报
0/150
提交
取消