我尝试显示图库的一部分照片=>这是我search action
时的结果。此结果为avatar
,如picture
和infomation
,如username or email
。
我在关系Photo.java
中创建了child
Users.java
@ManytoOne
这是我的代码:
Photo.java ----
@Entity
public class Photo extends Model{
@Id
public Long id;
public String path;
@ManyToOne
@JoinColumn(name = "user_id")
public Users user;
}
Users.java -----
@Entity
public class Users extends Model{
@Id
public Long id;
@Constraints.Required
public String username;
@Constraints.Required
public String email;
@Constraints.Required
public String password;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
public List<Photo> photo = new ArrayList<Photo>();
public Users(){}
public Users(String username,String email,String password){
this.username=username;
this.email=email;
this.password=password;
}
}
Search.java -----
public static Result search(){
DynamicForm form = form().bindFromRequest();
String name = form.get("name");
Finder<Long, Users> find = new Finder<Long, Users>(Long.class, Users.class);
List<Users> users = find.where().like("username", '%'+ name +'%').findList();
if (form.get("name")=="" || users.isEmpty() || users==null){
return ok(search_again.render());
}
else{
return ok (search_result.render(users));
}
}
search_result.scala.html ----
@(users : List[Users])
@main(nav= "search"){
<h3>Result</h3>
<a href="@routes.Search.blank"><input class="button" type="button" value="Back to Search"></a>
<a href="@routes.Application.index"><input class="button" type="button" value="Back to Home"></a>
<p>Found @users.size() result(s) : </p>
<div class="sresult">
@for(user <- users){
<div id="sresult">
<div id="haha"><img src="@routes.Assets.at("upload/"+user.photo.path)"></div>
//Error here. Why "user.photo.path" not working ?
<p>
@user.username</a></br>
@user.password</a></br>
@user.email</a>
</p>
</div>
}
</div>
}
为什么“user.photo.path”无效?在我的情况下任何理想?