Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map an URL having querystring parameters in urlmapping.groovy?

Tags:

grails

groovy

I am new to Grails/Groovy. Please bear with me if this is a silly question.

I am trying to map an URL having querystring parameters in urlmapping.groovy, something like,

"/rest/employees?empno=123&dept=delivery"(controller:"employees", action="emp")

The values 123 and delivery are dynamic values. In other words, this could be anything that the user can use.

Apparently this syntax is not correct. What is the right way to achieve this?

like image 609
Mike Avatar asked Sep 19 '25 07:09

Mike


2 Answers

Just leave /rest/employees"(controller:"employees", action="emp") and you'll get your query parameters as params.empno and params.dept in your action

like image 50
Igor Artamonov Avatar answered Sep 22 '25 21:09

Igor Artamonov


@splix answer is correct. If you want to use a restfull url, you could do something like

"/rest/employees/$empno/$dept"

instead. Otherwise just leave out the part after "?" as said. In your controller you will still get params.empno and params.dept

Read more here

like image 41
sbglasius Avatar answered Sep 22 '25 22:09

sbglasius