将java pojo映射到角度pojo

时间:2017-11-06 14:56:43

标签: java angular spring-data-rest

我正在从数据库中检索帐户对象,以便我可以将其字段与登录屏幕中提交的用户名和密码字段进行比较。

我使用以下代码从数据库中检索它并将其发送到角度组件。

  postCredentials(username:string, password:string): Promise<Account> {
    let params = new URLSearchParams();
    params.append("username", username);
    params.append("password", password);
    console.log(this.data);
    return this.http.get(this.apiPostUrl, {params: params}).toPromise().then(res => res.json() as Account).catch(this.handleError);//this.http.get(this.apiPostUrl, {params: params}).toPromise().then(res => res.json() as Account)
  }

但是,当我打印结果时,我看到Account角度pojo中的id字段是未定义的,Roles字段也是如此。现在我可以理解角色字段是未定义的,但是id字段不应该是未定义的,因为它在数据库中有一个值。

这些是我的pojo's。

java帐户Pojo:

@Entity
public class Account {
    @Id
    @GeneratedValue
    private int id;
    private String username;
    private String password;
    @ManyToMany(cascade = CascadeType.ALL)
    private Collection<Role> roles;
    @OneToOne
    private Person person;

    @Override
    public String toString() {
        return "Account{" +
            "id=" + id +
            ", username='" + username + '\'' +
            ", password='" + password + '\'' +
            ", roles=" + roles +
            ", person=" + person +
            '}';
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Collection<Role> getRoles() {
        return roles;
    }

    public void setRoles(Collection<Role> roles) {
        this.roles = roles;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }
}

这是前端(角度)pojo

export class Account {
  id: number;
  username: string;
  password: string;
  person: Person;
  roles: Role[];
}

谁能告诉我我在这里失踪了什么?

0 个答案:

没有答案