我是 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;
}
九州编程
相关分类