在Grails中创建自定义标记库时出错

hae*_*des 4 grails taglib gsp

我正在尝试使用grails标签库.我创建了一个名为isowner的简单标记库

class AuthTagLib {
static defaultEncodeAs = 'html'

def springSecurityService

def isOwner = { attrs, body ->
    def loggedInUser = springSecurityService.currentUser
    def owner = attrs?.owner

    if(loggedInUser?.id == owner?.id) {
        out << body()
    }
}}
Run Code Online (Sandbox Code Playgroud)

然后尝试将其与gsp一起使用:

<g:isOwner owner="${leaveFormInstance.employee}">
                    <g:link class="edit" action="edit" resource="${leaveFormInstance}">
                        <g:message code="default.button.edit.label" default="Edit" />
                    </g:link>
</g:isOwner>
Run Code Online (Sandbox Code Playgroud)

现在它应该将用户对象作为输入并验证用户是否是帖子的所有者.

现在一切正常但在输出html中它将链接显示为文本. 在此输入图像描述

我对这些东西很新,必须缺少一些基础知识,你能帮忙吗?

Bur*_*ith 6

去掉

static defaultEncodeAs = 'html'
Run Code Online (Sandbox Code Playgroud)

因为那是逃避你的输出.