Dynamic Grails Url Mapping config

后端 未结 4 1672
醉酒成梦
醉酒成梦 2020-12-15 10:13

How can I dynamically build a list of mappings - instead of:

class UrlMappings {
static mappings = {
   \"/helpdesk/user/$action?/$id?\" (controller=\"helpde         


        
4条回答
  •  再見小時候
    2020-12-15 11:15

    You can embed the $controller variable, see the documentation.

    static mappings = {
       "/helpdesk/$controller/$action?/$id?"()
    }
    

    BTW, the mappings to controllers and, optional, their views are enclosed by normal brackets (), not curly ones {}.

    Such Groovy Scripts (as UrlMappings.groovy) are parsed by a ConfigSlurper instance, which finally converts them to a ConfigObject that implements Map. Admittedly, I'm either not sure how this parsing is accomplished in detail.

    EDIT:

    Here's an UrlMappings.groovy that comes somewhat near to what you want. (Search for "/$_ctrl/$_action/$id?".) The code, BTW, gets evaluated at runtime. Nevertheless, I haven't been able to put the grailsApplication to work.

    Another idea was to add a javax.servlet.Filter to the web application, i.e., by subclassing Grails' UrlMappingsFilter.

提交回复
热议问题