springBoot + Thymeleaf:比较模板中的值

问题描述 投票:0回答:1
javascript html spring-boot thymeleaf spring-thymeleaf
1个回答
0
投票

看起来

#locale
不是一个字符串,而是一个
java.util.Locale
——而且由于您将
String
Object
进行比较,所以它总是错误的。这对我有用:

<form action="" class="language-picker__form" th:with="language=${#locale.language}">
    <select th:id="language-picker-select" name="language-picker-select">
        <option th:value="es" th:selected="${language=='es'}">Español</option>
        <option th:value="fr" th:selected="${language=='fr'}">Français</option>
        <option th:value="pt" th:selected="${language=='pt'}">Português</option>
        <option th:value="en" th:selected="${language=='en'}">English</option>
    </select>
</form>
© www.soinside.com 2019 - 2024. All rights reserved.