spring - How to Change Controller Name and function name URL in Grails 2.2.2? -
i trying change controller name , method name in grails
e.g :abc.com/newuser/viewuser/4
i want convert in below format e.g :abc.com/new-user/view-user/4
or
e.g :abc.com/new_user/view_user/4
for wrote code :
package customize import grails.web.urlconverter import org.apache.commons.lang.stringutils class customurlconverter implements urlconverter { private static final string grails_extension = '_' string tourlelement(string propertyorclassname) { if (stringutils.isblank(propertyorclassname)) { return propertyorclassname } else { string[] r = propertyorclassname.split("(?=\\p{upper})"); string lowerpropertyorclassname = propertyorclassname.tolowercase(); println r.length + "size()"; string extendedpropertyorclassname=""; if(r.length > 1){ for(int i=0; < r.length;i++){ extendedpropertyorclassname = extendedpropertyorclassname + r[i].tolowercase() if(i+1 < r.length ){ extendedpropertyorclassname =addgrailsextension(extendedpropertyorclassname); } } }else{ extendedpropertyorclassname = propertyorclassname.tolowercase() } return extendedpropertyorclassname } } private string addgrailsextension(string propertyorclassname) { if (propertyorclassname.endswith(grails_extension)) { return propertyorclassname } else { return propertyorclassname + grails_extension } } }
in config.groovy
grails.web.url.converter = 'hyphenated'
// grails-app/conf/spring/resources.groovy
beans = { "${grails.web.urlconverter.bean_name}"(com.myapplication.myurlconverterimpl) }
in when trying character in small letter below url
e.g :abc.com/newuser/viewuser/4
its working fine
but when add underscore in between 2 character below url
e.g :abc.com/new_user/view_user/4
its gives error 404.. please me out. if have other option change url welcome..
thank
one of easiest way achieve requirement urlmappings.groovy
"/new_user/view_user/$id"(controller: 'newuser', action: 'viewuser')
Comments
Post a Comment