Grails GSP if test在检查具有Spring Security核心插件的登录用户是否是域类实例的创建者时返回false

Grails GSP if test在检查具有Spring Security核心插件的登录用户是否是域类实例的创建者时返回false,grails,spring-security,gsp,Grails,Spring Security,Gsp,我正在使用 我想测试登录的用户是否是便笺的创建者。注意是Grails域类。creator是User,它是我的Spring Security核心插件的用户域类 下一个代码不起作用 <g:set var="loggedUserId"><sec:loggedInUserInfo field="id"/></g:set> <g:if test="${note.creator.id == loggedUserId}"> Never jumps here

我正在使用

我想测试登录的用户是否是便笺的创建者。注意是Grails域类。creator是User,它是我的Spring Security核心插件的用户域类

下一个代码不起作用

<g:set var="loggedUserId"><sec:loggedInUserInfo field="id"/></g:set>
<g:if test="${note.creator.id == loggedUserId}">
   Never jumps here
</g:if>
知道我错过了什么吗?提前感谢


<g:if test="${note.creator.id.toString() == loggedUserId.toString()}">
像这样试试吧,loggedInUserInfo返回一个字符串,creatorId应该是一个长的,所以没有强制转换的等式是不正确的

不过,您应该将这样的逻辑放入标记库。


像这样试试吧,loggedInUserInfo返回一个字符串,creatorId应该是一个长的,所以没有强制转换的等式是不正确的

但是,您应该将这样的逻辑放入标记库。

标记
不是您期望的
Long
的实例,而是
类org.codehaus.groovy.grails.web.util.StreamCharBuffer
的实例。按如下方式获取控制器中的当前用户:

class YourController{    
    def springSecurityService //Inject the Spring Security Service dependency
    //...
    def yourAction ={
        //...
        def currentUser = springSecurityService.getCurrentUser()
        //...
        [currentUser:currentUser] //Make sure to map everything else that needs to be mapped too.
    }
}
<g:if test="${note.creator == currentUser}">
   Never jumps here <!--Now it will get in here just fine.-->
</g:if>
然后检查视图中的当前用户,如下所示:

class YourController{    
    def springSecurityService //Inject the Spring Security Service dependency
    //...
    def yourAction ={
        //...
        def currentUser = springSecurityService.getCurrentUser()
        //...
        [currentUser:currentUser] //Make sure to map everything else that needs to be mapped too.
    }
}
<g:if test="${note.creator == currentUser}">
   Never jumps here <!--Now it will get in here just fine.-->
</g:if>

从不在这里跳
标记
不是您期望的
Long
的实例,而是
类org.codehaus.groovy.grails.web.util.StreamCharBuffer的实例。按如下方式获取控制器中的当前用户:

class YourController{    
    def springSecurityService //Inject the Spring Security Service dependency
    //...
    def yourAction ={
        //...
        def currentUser = springSecurityService.getCurrentUser()
        //...
        [currentUser:currentUser] //Make sure to map everything else that needs to be mapped too.
    }
}
<g:if test="${note.creator == currentUser}">
   Never jumps here <!--Now it will get in here just fine.-->
</g:if>
然后检查视图中的当前用户,如下所示:

class YourController{    
    def springSecurityService //Inject the Spring Security Service dependency
    //...
    def yourAction ={
        //...
        def currentUser = springSecurityService.getCurrentUser()
        //...
        [currentUser:currentUser] //Make sure to map everything else that needs to be mapped too.
    }
}
<g:if test="${note.creator == currentUser}">
   Never jumps here <!--Now it will get in here just fine.-->
</g:if>

从不在这里跳