How to escape single quote (') in Thymeleaf

后端 未结 3 1072
旧巷少年郎
旧巷少年郎 2021-01-04 01:54

I want this to output

What\'s up?

But I get an

相关标签:
3条回答
  • 2021-01-04 02:33

    maybe use htm ascii code : '

    <h1 th:text="${'What&#39;s up&#63;'}"></h1>
    
    0 讨论(0)
  • 2021-01-04 02:49

    To escape a single quote you just escape it with a \'

    <p th:text="'What\'s up?'"></p>
    <p th:text="${myVar} + 'What\'s up?'"></p>
    
    0 讨论(0)
  • 2021-01-04 02:51

    Double single quote. Like this:

    <h1 th:text="${'What''s up?'}" />
    
    0 讨论(0)
提交回复
热议问题