问题
I am novice to the Play and currently working Play 2.2.1
I am trying to acheive case insensitive routing for my endpoints which are defined in "routes"
e.g. I have define an route say /accessLicense in routes file, it would look like below
GET /accessLicense controller.MyController.accessLicense()
Now, if I fire /accessLicense it woks great; as expected, but if try to fir /AccessLicense, /AcCeSSLicenSe or any other combination of upper/lower case letter which spell exact same word, it doesn't work.
Thanks in advance for guidance and support!!!
回答1:
Unfortunately, AFAIK, there is no way to magically turn on a switch that will do what you want. Thankfully, there's a workaround, inferior IMHO but its the best that can be done.
GET /[aA][cC][cC][eE][sS][sS].....
EDIT: I did the following, which matches my specific requirement of lower-casing only the first part of URL. So GET /AbCdE/XyZ will become GET /abcde/XyZ and if this has an action in the routes than it will be handled appropriately.
override def onRouteRequest( request: RequestHeader ) = {
val path = request.path
val split = path.split( "/" ).toList
val lowerCasePath = split match{
case ""::Nil => ""::Nil
case ""::x::y => ""::x.toLowerCase::y
}
logger.error( lowerCasePath.toString )
super.onRouteRequest( request.copy( path = lowerCasePath.mkString( "/" ) ) )
}
EDIT See here: https://jazzy.id.au/2013/05/08/advanced_routing_in_play_framework.html
来源:https://stackoverflow.com/questions/22015902/play-framework-2-2-1-case-insensitive-routing