Html Thymeleaf:th:在下拉列表中选择

Html Thymeleaf:th:在下拉列表中选择,html,spring,spring-mvc,spring-boot,thymeleaf,Html,Spring,Spring Mvc,Spring Boot,Thymeleaf,我想根据地区国家选择一个选择框选项,但没有办法。 我试过: <option value="AR" th:selected="${#locale.country.contains('AR')}" >Argentina</option> <option value="AR" th:selected="${#locale.contains('AR')}" >Argentina</option> <option value="AR" th:selec

我想根据地区国家选择一个选择框选项,但没有办法。 我试过:

<option value="AR" th:selected="${#locale.country.contains('AR')}" >Argentina</option>
<option value="AR" th:selected="${#locale.contains('AR')}" >Argentina</option>
<option value="AR" th:selected="${__${#locale}__.contains('AR')}" >Argentina</option>
<option value="AR" th:selected="${#{__${#locale}__}.contains('AR')}" >Argentina</option>
阿根廷
阿根廷
阿根廷
阿根廷
此选项显示国家(美国)

美国
但是未选择此选项。

表达式从请求返回
java.util.locale
对象,因此您应该使用for它:

或者,如果您愿意直接:

__${#locale}__=='es_AR'
默认情况下,此对象中没有包含的方法

如果您需要使用
th:call
,这也可能对您有所帮助

#locale.country == `AR`
__${#locale}__=='es_AR'