groovy - 是否可以在GSP中声明一个函数?

标签 groovy jsp-tags gsp

如何在GSP中声明函数?我需要类似taglib的东西,但需要在GSP中声明-外部无关紧要

最佳答案

您无法在GSP中定义方法。但是,如果需要,您可以具有匿名功能:D

例子:

<%
    def prettify = { "***$it***" }
%>
<h1>${prettify(someText)}</h1>

尽管此示例没有太大意义,但可以内嵌少量格式。对于 View 的任何其他逻辑,我将遵循OverZealous recommendation并使用taglib。

关于groovy - 是否可以在GSP中声明一个函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9172803/

相关文章:

file - Groovy 重命名文件

grails - 为什么我的Groovy对象初始化程序无法设置属性?

unit-testing - 单元测试 Controller 时无法模拟 Grails 服务方法 - MissingMethodException

java - 属性编辑器未注册自定义验证标记上的 PropertyEditorManager 错误 (java)

javascript - ajax 加载中拒绝访问 (Grails)

grails - 图片未在.doc文件中呈现

grails - <g:checkBox>单击调用 Controller 功能

hibernate - Grails( hibernate )条件查询

spring-mvc - org.springframework.expression.spel.SpelEvaluationException : EL1027E:(pos 4): Indexing into type 'com.test.domain.Employee' is not supported

spring - 如何在 Spring 中以编程方式解析属性占位符