简体   繁体   English

使用playframework如何列出值

[英]using playframework how to list values

get an error 得到一个错误

Cannot use a method returning Unit as an Handler 无法使用将Unit返回为Handler的方法

inside Application 内部应用

def listAllFriends(userId:Long){
    val myfriend:List[MyFriend]=MyFriend.listAllFriendByUser(userId)
    Ok(views.html.allFriends.render(myfriend))

  }

in views page 在视图页面

@(myFriends: List[MyFriend])

@for(myFriend <- myFriends){
    @myFriend.friend_Id <br>
}

In routes 在路线上

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

And in model 并在模型中

model have myfriend got 4 values id,userId,friendId and isAccept. 模型让myfriend获得4个值id,userId,friendId和isAccept。 userId and FriendId are the ForeignKey from table UserProfile.. 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
     }
   }

In routes, try : 在路线上,请尝试:

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

See Play 2.0 framework - POST parameters 请参阅Play 2.0框架-POST参数

And in Application, you have missed the 'Action' : 在Application中,您错过了“ Action”:

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

In your routes file you call the method listAllFriends() without argument, while it is defined as def listAllFriends(userId:Long). 在路由文件中,您将不带参数的方法调用listAllFriends(),而将其定义为def listAllFriends(userId:Long)。 You must pass it the userId parameter... 您必须向其传递userId参数...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM