我正在尝试将键值映射呈现到模板,然后以这种方式显示:
@(twittsIfollow: Map[String, String])
.....
@if(twittsIfollow != null) {
@for((key, value) <- twittsIfollow) {
@key
@value
}
}
它说,这是错误的。映射键值是否有 scala 标签?
这是我的方法:
public static Map<String, String> alltwitts(List<Long> otherIDs) {
Map<String, String> results=new HashMap<String, String>();
for (Long id: otherIDs) {
Query selected_twitt = JPA.em().createQuery("select u.twitt from Twitt u where " + " u.whose = ?").setParameter(1, id);
String twOwner = User.getOneUser(id);
String twitt = (String) selected_twitt.getSingleResult();
results.put(twOwner, twitt);
}
return results;
}
然后我在这个地方渲染到模板:
Map<String, String> twittsIfollow = Twitt.alltwitts(IDusersIamFollowing);
return ok(microblog.render(twittsIfollow));
现在它说:[NonUniqueResultException: result returns more than one elements]
谢谢