Scala 使用playframework如何列出值
出错 无法将返回单元的方法用作处理程序 内部应用程序Scala 使用playframework如何列出值,scala,playframework,Scala,Playframework,出错 无法将返回单元的方法用作处理程序 内部应用程序 def listAllFriends(userId:Long){ val myfriend:List[MyFriend]=MyFriend.listAllFriendByUser(userId) Ok(views.html.allFriends.render(myfriend)) } 在视图页面中 @(myFriends: List[MyFriend]) @for(myFriend <- myFriends){
def listAllFriends(userId:Long){
val myfriend:List[MyFriend]=MyFriend.listAllFriendByUser(userId)
Ok(views.html.allFriends.render(myfriend))
}
在视图页面中
@(myFriends: List[MyFriend])
@for(myFriend <- myFriends){
@myFriend.friend_Id <br>
}
在模型中
模型让myfriend获得4个值id、userId、friendId和isAccept。userId和FriendId是表UserProfile中的ForeignKey
def listAllFriendByUser(user_Id:Long):List[MyFriend]={
DB.withConnection { implicit connection =>
val friendByUser= SQL(
"""
select * from MY_FRIEND where USER_ID ={user_Id}
""").on(
'user_Id -> user_Id).as(MyFriend.simple.*)
friendByUser
}
}
在路由文件中,调用方法listalfriends(),不带参数,而将其定义为def listalfriends(userId:Long)。您必须向其传递userId参数…在routes中,请尝试:
POST /allFriends controllers.Application.listAllFriends(userId:Long)
看
在应用程序中,您错过了“操作”:
def listAllFriends(userId:Long) = Action {...}
我试图让GET编译不能使用返回单元的方法作为句柄错误消失了,我得到了操作没有找到任何其他代码节我错过了DIMPORT play.api.mvc.Action?如果你想在路由文件中使用GET、put GET和not POST,我想listSomething方法就是GET,不是POST。我尝试了一下,GET编译不能使用返回单元的方法作为处理程序
def listAllFriends(userId:Long) = Action {...}