Problem with URL expression

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with URL expression

rajkumar
I like to make RESTful service call using URI like

http://localhost:8088/Practice/rest/users/1

I tried with the following

@{http://localhost:8088/Practice/rest/users/${userDto.id}}

but getting following error

org.thymeleaf.exceptions.ExpressionParsingException: Could not parse as expression: "@{http://localhost:8088/Practice/rest/users/${userDto.id}}"

Some how I resolved using following :

@{http://localhost:8088/Practice/rest/users/} + ${userDto.id}

But in cases where more no. of path variables to be sent, this would not be good
So i feel there should be a provision in writing url expression as follows


@{http://localhost:8088/webapp/restfulservice/param1/${value2}/param2/${value2}/param3/${value3}}

this will be also helpful while writing javascripts
Reply | Threaded
Open this post in threaded view
|

Re: Problem with URL expression

Zemi
Administrator
Hi Rajkumar,

you could use "preprocessing" syntax, i.e.:

    @{/webapp/restfulservice/param1/__${value2}__/param2/__${value2}__/param3/__${value3}__}

> this will be also helpful while writing javascripts

For javascript you could be interested in reading the "inlining" chapter of the tutorial.

Reply | Threaded
Open this post in threaded view
|

Re: Problem with URL expression

rajkumar
thank u
Reply | Threaded
Open this post in threaded view
|

Re: Problem with URL expression

danielfernandez
Administrator
Hi,

Since Thymeleaf 1.1 there's another option: string literal concatenation.

In Thymeleaf's standard expressions, string literals are surrounded by ' (single quote) symbols. What you write inside a @{...} expression is in fact a string literal, but Thymeleaf allows you to skip the quotes:

@{'http://www.thymeleaf.org'} can be written --in fact, is usually wriiten-- as @{http://www.thymeleaf.org}

The '+' operator can be used to concatenate string literals with other expressions, like:

@{'http://www.thyme'+ 'leaf.org'}

...and could also be used for your URLs, concatenating string literals and variable expressions:

@{'http://localhost:8088/webapp/restfulservice/param1/' + ${value2} + '/param2/' + ${value2} + '/param3/ + ${value3}}


Regards,
Daniel.