我创建了两个Entity
:User
和Post
一个用户可以有很多帖子,所以我为User
添加@OnetoMany
,为Post
添加@ManytoOne
USER.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
对我来说,任何帮助、任何理想或某种方式都可以将两个实体联系起来?
即,您需要执行以下操作:
@(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>
}