grails - Grails-仅获取URL参数

标签 grails

我试图建立一个动态URL映射,您可以在URl中传递任何查询。因此,目前我想呈现查询的键/值,但不包含 Controller ,方法和操作信息。

所以当我通过人时?name = Mark&age = 60

它呈现[[name]:'Mark','age':'60','controller':'Person','method':'GET','action':'getPerson']

我如何才能仅在URL中获取查询,而不能获取有关 Controller 等的其他信息。

网址映射

"/person"{
        controller = "Person"
        method = 'GET'
        action = "getPerson"
    }

人员 Controller
def getPerson(){
    render params
}

通过执行以下操作,我将其从渲染中删除:
    HashMap search = params
    String action = "action"
    String controller = "controller"
    String method = "method"

    search.remove(action)
    search.remove(controller)
    search.remove(method)

    render search

最佳答案

我认为您能做的最好的就是删除您知道并且不希望看到的参数:

def getPerson(){    
    render params.findAll { !(it.key in ['action', 'controller', 'method']) }
}

关于grails - Grails-仅获取URL参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40217465/

相关文章:

部署在 Tomcat6 上时的 Grails 1.3.7 UTF-8 问题

grails - 虚假的MissingMethodException,Grails 2.2.5

regex - 键盘特殊字符的正则表达式验证

grails - 带有 grails 插件和 ProxyAwareMixedGrailsControllerHelper 的 Vaadin7

Grails GORM 自引用 belongsTo 删除与预期相反的方向

java - Grails:如何让 log.debug 语句显示在控制台中

grails - Grails FindWhere和BetweenDate

grails - 当 X-Forwarded-Proto 为 https 时,重定向位置包括 ":80"

grails - Grails上的Spring Security和带有领域的Tomcat Security

grails - 在插件中获取SpringSecurityService