Thymeleaf - 使用条件设置属性值

mty*_*urt 2 java spring thymeleaf

我需要做类似的事情:

<div style="${flag ? 'block' : 'none'}"></div>
Run Code Online (Sandbox Code Playgroud)

我已经调查th:if但找不到合适的方法来做到这一点.这可能吗?

snw*_*snw 6

你需要th:style代替style,条件应该是${flag} ? 'val1' : 'val2'.这应该做的伎俩:

<div th:style="${flag} ? 'block' : 'none'"></div>
Run Code Online (Sandbox Code Playgroud)