Mike
Mike

Reputation: 41

How to map an URL having querystring parameters in urlmapping.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?

Upvotes: 4

Views: 14233

Answers (2)

sbglasius
sbglasius

Reputation: 3124

@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

Upvotes: 3

Igor Artamonov
Igor Artamonov

Reputation: 35961

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

Upvotes: 8

Related Questions