简体   繁体   中英

how to differentiate grails url mappings

I have the mappings:

"/$controller/$action?/$id?"{
            constraints {
                // apply constraints here
            }
        } // i used scaffolding and i think this is required by the generated stuff
'/'(controller:'home') //for the home page
'/$param1?/$param2?'(controller:'search') //for a search page 

The required url to be displayed in the browser is:
www.site.com/ - for home

www.site.com/keyword1/keyword2 - for a search by these optional keywords

This seems to work but my question is: Can I expect this to be correct or in some situation grails will get things mixed up?

It will not. Grails will sort your url mappings based on a given set of precedence rules ( from specific to general ).

Your urls will always be the same and return the same page.

However, because your mappings are ambigous, sometimes it might return a page that you don't expect. A better design is to have search be mapped to:

/search/params1?/params2?

this way it is unambigous.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM