[英]Parameter to String in thymeleaf
When the parameter *{mydata.value}
is enum then how to transform it into String in thymeleaf? 当参数*{mydata.value}
是枚举时,如何在百里香中将其转换为String?
I want to compare 我想比较
if:*{mydata.value == "aaa"}
It gives error. 它给出了错误。 I think it is because I should do something like: 我认为这是因为我应该这样做:
if:*{mydata.value.toString() == "aaa"}
. if:*{mydata.value.toString() == "aaa"}
。
Try using 尝试使用
if:*{mydata.value.toString().equals("aaa")}
I'm not very familiar with thymeleaf, however that is a common issue in Java. 我对百里香不是很熟悉,但是这是Java中的一个常见问题。 Using '==' will compare the reference to the object, but the .equals() will compare the contents of the string. 使用'=='将比较对象的引用,但是.equals()将比较字符串的内容。
If 'mydata.value' is already a string, you can remove the '.toString()'. 如果“ mydata.value”已经是字符串,则可以删除“ .toString()”。
If it isn't a string already, you can also use: 如果还不是字符串,则还可以使用:
if:*{String.valueOf(mydata.value).equals("aaa")}
See more examples of why this happens here 在此查看为什么发生这种情况的更多示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.