How to get resource URI in Grails?

Very simple question. I want to provide a URI for some objects in my application. For example, a resource is available at:

http://localhost:8080/myapp/user/1

However, I would like to serialize such a User object. This serialization must contain the public URI of the object itself. So, for example, the model has a new method serializeToSomethingthat will be serialized:

id: 1
username: JohnDoe
email: johndoe@example.com
publicURI: http://localhost:8080/myapp/user/1

How can I let a model instance know its URL?

Some notes:This should happen within the model, controller, or service, and not in the view. Also I do not want to do this.

+3
source share
3 answers

See the related question. Can I use the grails tag outside of the GSP?

g.createLink , . - :

def uri = g.createLink(controller: 'user', action: 'show', id: user.id, absolute: true)
+4

3 : controller name, action name ( "show" ) id. g.createLink .

, , .

0

You can get the url in the controller using

request.forwardURI

A similar question was asked before

0
source

All Articles