开发者

URL with hyphens in Grails 1.1.1 or Grails 1.2 M4

开发者 https://www.devze.com 2022-12-12 01:39 出处:网络
Is there a way to configure Grails 1.1.1 or Grails 1.2 M4 to map a multi-word controller or action written in PascalCase or camelCase to automatically map to a URI with hyphens separating the words?

Is there a way to configure Grails 1.1.1 or Grails 1.2 M4 to map a multi-word controller or action written in PascalCase or camelCase to automatically map to a URI with hyphens separating the words?

For example, if I have a controller named MoreInformation with a function named boardOfDirectors, I would like t开发者_如何学编程he URI to resemble:

http://domain.com/more-information/board-of-directors

Is this possible? Thank you.


Assuming you have a method transformURL which converts hyphenated case to CamelCase, something like this should do it.

class UrlMappings {
static mappings = { 
  "/$initialController/$initialAction?/$id?"{
            controller = transformUrl(initialController)
            action = transformUrl(initialAction)
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消