1

我创建了两个EntityUserPost

一个用户可以有很多帖子,所以我添加@OnetoMany了 forUser@ManytoOneforPost

用户.JAVA ---

@Entity
public class Users extends Model{

    @Id
    public Long id;

    @Constraints.Required
    @NotNull
    public String username;

    @Constraints.Required
    @NotNull
    @Constraints.Email
    public String email;

    @Constraints.Required
    @Constraints.MinLength(6)
    @NotNull
    public String password;


    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    public List<Post> post;

    public Users(){}

    public Users(String username,String email,String password){
        this.username=username;
        this.email=email;
        this.password=password;
        this.post=new ArrayList<Post>();
    }
}

和 POST.JAVA ---

    @Entity
    public class Post extends Model{

        @Id
        public Long id;

        @ManyToOne
        @JoinColumn(name = "user_id")
        public Users user;

        public String title;

        public String article;
}

当我搜索用户信息并显示如下:

@(users : List[Users])
@for(user <- users){
    @user.post</br>
    @user.username</br>
    @user.password</br>
    @user.email</a>
}

“BeanList deferred”出现了。(不是错误,不是异常,只是一个String

结果 :

BeanList deferred  // like this
Kenny
123456
kennybg@gmail.com

对我来说有任何帮助、任何理想或某种方式可以链接两个实体吗?

4

1 回答 1

1

即您需要执行以下操作:

@(users : List[Users])
@for(user <- users){
    for(post <- user.post) {
        @post.article<br/>
    }
    @user.post</br>
    @user.username</br>
    @user.password</br>
    @user.email</a>
}
于 2013-09-04T04:21:55.703 回答