使用play框架如何列出值

时间:2013-05-31 10:20:02

标签: scala playframework

收到错误

无法使用将Unit作为处理程序返回的方法

内部应用程序

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>
}

路线

GET  /allFriend     controllers.Application.listAllFriends(postId:Long)

在模特中

模型让我的朋友得到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
     }
   }

2 个答案:

答案 0 :(得分:1)

在路线中,尝试:

  POST /allFriends        controllers.Application.listAllFriends(userId:Long)

请参阅Play 2.0 framework - POST parameters

在应用程序中,你错过了'动作':

def listAllFriends(userId:Long) = Action {...}

答案 1 :(得分:0)

在您的路径文件中,您可以在不使用参数的情况下调用方法listAllFriends(),而将其定义为def listAllFriends(userId:Long)。您必须传递userId参数...