[JAVA] If you want to dynamically embed values & add text to attribute values in Thymeleaf 3

Overview

It's almost as written here, but because the JavaScript argument got stuck in a string pattern.

If you want to dynamically embed a value in an attribute value and add text with Thymeleaf3

For attributes related to JavaScript

Escape single quotes with a backslash.

<a href="#" th:attr="onclick='alert(\'aaaa' + ${page} + '\');'" >

Write. At this time, if you insert a space because it is easy to see before and after escaping, the entered space will be faithfully reflected, so be careful.

Recommended Posts

If you want to dynamically embed values & add text to attribute values in Thymeleaf 3
If you want to separate Spring Boot + Thymeleaf processing
When you want to dynamically replace Annotation in Java8
If you want to recreate the instance in cloud9
If you want to include the parent class in Lombok's @builder
Add SameSite attribute to cookie in Java
If you want to use Oracle JDK 11 from September (add Amazon Corretto)
What to do if you get a groovy warning in Thymeleaf Layout
If you want to satisfy the test coverage of private methods in JUnit
If you want to modify database columns etc.
When you want to bind InputStream in JDBI3
What to do if you can't get the text of an element in Selenium
How to embed JavaScript variables in HTML with Thymeleaf
I want to embed any TraceId in the log
If you want to use Mockito with Kotlin, use mockito-kotlin
I want to Flash Attribute in Spring even if I set a reverse proxy! (do not do)
What to do if you get a java.io.IOException in GlassFish
[# 3 Java] Read this if you want to study Java! ~ Carefully selected ~
[Swift] When you want to know if the number of characters in a String matches a certain number ...
If you just want to run your containers in the cloud, Azure Container Instances is easy
If you want to mock a method in RSpec, you should use the allow method for mock and the singleton method.
Refer to enum in Thymeleaf
What to do if you get a gcc error in Docker
ProxyFactory is convenient when you want to test AOP in Spring!
[PostgreSQL] If you want to delete the Rails app, delete the database first!
If you want to change the Java development environment from Eclipse
What to do if you get a DISPLAY error in gym.render ()
I want to add devise in Rails, but I can't bundle install
When you have introduced devise but want to add more columns
I want to change the value of Attribute in Selenium of Ruby
What to do if you forget the root password in CentOS7