播放框架if else case不工作

Pra*_*A R 0 scala playframework

播放框架,如果其他情况不在这里工作

如果userprofile.useraccountid,useraccount.id具有相同的值,则不在视图页面上查看id用户

我在视图中的代码..

@(userprofiles: List[UserProfile],myFriend:models.MyFriend,userprofile:models.UserProfile,useraccount:models.UserAccount)
 @helper.form(action = routes.Application.createMyFriend) {
    <br/><br/><br/>
    @for(userprofile <- userprofiles){
        @if(userprofile.useraccountid != useraccount.id) {
            <img src="@routes.Assets.at("images/img2.png")" width="200" height="200" />
            <br>
            <h5>@userprofile.name</h5>
            <h5>@userprofile.useraccountid</h5>=<h5>@useraccount.id</h5>
            <h6>@userprofile.gender</h6>
            <h6>@userprofile.date_of_birth</h6>
            <div class="actions">
                <input type="submit" class="btn primary" value="+1 Add As Friend" title="Send Friend Request">
            </div>
            <br/>
        }
    } 
}  
Run Code Online (Sandbox Code Playgroud)

检查条件时,数据库值是视图页面中的视图

@if(userprofile.useraccountid != useraccount.id)
Run Code Online (Sandbox Code Playgroud)

如果改变条件

 @if(userprofile.useraccountid == useraccount.id)
Run Code Online (Sandbox Code Playgroud)

视图页面中没有任何内容.

在此代码中运行程序代码部分

 <h5>@userprofile.useraccountid</h5>=<h5>@useraccount.id</h5>
Run Code Online (Sandbox Code Playgroud)

id在这里是相同的,并且在视图中显示然后该想法不是假的...例如15 = 15.

这里的2 id是相同的,但是在if情况下的检查不能正常工作......或者编码不正确.

编辑这是在申请中

 def listMyFriend = Action { implicit request =>
    var cid=request.session.get("userId")
    println("aa",cid)
   if (request.session.get("userId") == None) {
      Results.Redirect("/")
    }
   else {
        val userprofiles:UserProfile=null
        val userprofileId = request.session.get("userId").get.toLong//userProfileId
        val userprofile = UserProfile.findUserByAccountId(userprofileId).get
        println(userprofile)
       /*   val myfriendId = request.session.get("myFriendId").get.toLong//myFriendId
        val myfriend = MyFriend.friendidByUserIsAccepted(myfriendId,true)
        println(myfriend)*/
        myFriendForm.bindFromRequest.fold(
        errors => BadRequest(views.html.myFriend(errors, userprofile,myfriend,myfrnd)),
   myFriend => {
          println("errors")
          val myFriendOpt = UserProfile.myFriend(userprofile.id.get)
          println(myFriendOpt)
   myFriendOpt match {
   case None =>
     }
          Results.Redirect("/myFriend")
        })  
        }
    }  
Run Code Online (Sandbox Code Playgroud)

gou*_*ama 5

您的代码中存在阴影问题:userprofile既定义为模板的参数,又定义为您从for理解中获得的变量.

@(userprofiles: List[UserProfile],myFriend:models.MyFriend,userprofile:models.UserProfile,useraccount:models.UserAccount)
                                                    here ---^
 @helper.form(action = routes.Application.createMyFriend) {
    <br/><br/><br/>
    @for(userprofile <- userprofiles){
and here ---^
Run Code Online (Sandbox Code Playgroud)

尝试重命名两个中的一个,并在你的中找出你想要引用的那个if.