如何在 Thymeleaf 中设置默认选中的单选按钮

Ant*_*ony 3 spring thymeleaf

我有一组 3 个单选按钮。用户只能选择 3 个中的 1 个。我想设置一个单选按钮作为默认选择。我试过这段代码,但检查属性似乎被忽略了。

    <div>
        <input type="radio" th:field="*{genre}" th:value="Strategy" checked="true">
        <label th:for="${#ids.prev('genre')}">Strategy</label>
    </div>
    <div>
        <input type="radio" th:field="*{genre}" th:value="RPG">
        <label th:for="${#ids.prev('genre')}">RPG</label>
    </div>
    <div>
        <input type="radio" th:field="*{genre}" th:value="Stealth">
        <label th:for="${#ids.prev('genre')}">Stealth</label>
    </div>
Run Code Online (Sandbox Code Playgroud)
public class Game
{
    private String genre;
    //Constructor
    //Getter & Setter
}
Run Code Online (Sandbox Code Playgroud)

Met*_*ids 5

在您的控制器中,设置genre = "Strategy"何时Game添加到模型中。