我创建了两个Entity
:User
和Post
一个用户可以有很多帖子,所以我添加@OnetoMany
了 forUser
和@ManytoOne
forPost
用户.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
对我来说有任何帮助、任何理想或某种方式可以链接两个实体吗?