Search code examples
springthymeleafhtml-escape-characters

Inline javascript with thymeleaf escaping character


I use thymeleaf and spring. I try to do inline javascript.

<script th:inline="javascript">

    $("#genericTable").bootstrapTable({
        url: /*[[${url}]]*/ 'generic',
        ...
     });    

On the server side I do

 model.addAttribute("url", "/rest/vehicles");

I get

url: "\/rest\/vehicles",

Why some caracters are added to the string?

Edit

with

url: /*[[@{${url}}]]*/ 'generic',

first / is like removed, so it's invalid to call...


Solution

  • You can try something like this:

    <script type="text/javascript" th:inline="javascript">
      /*<![CDATA[*/
        $("#genericTable").bootstrapTable({
            url: /*[[${url}]]*/ 'generic',
            ...
        });  
      /*]]>*/
    </script>