Using Thymeleaf to create links that open in a new window/tab
html, java, thymeleaf
Solution
Thymeleaf overwrites the `a` tag. Use `th:target="_blank"`.
Problem
In basic HTML, a link can have the `target="_blank"` property to force it to open in a new window or tab. But if when I put that in an `<a href>` tag that also includes a `th:href` for Thymeleaf, Thymeleaf overwrites the whole tag and wipes out my `target="_blank`. I've considered the brute force method of adding `target="_blank"` to every link as it is stored in my database so that it is already part of the link when Thymeleaf writes it out. But I would prefer a way to have Thymeleaf write the `target="_blank"` property as it is writing the `<a>` tag.