input的:
<input type="text" class="form-control1" id="name" name="name" th:value="${user.name}">
select的:
<label class="col-sm-2 control-label">类别</label>
<div class="col-sm-8">
<select name="cId" id="cId" class="form-control1" >
<option value="1" th:field="*{book.cId}">目录1</option>
<option value="2" th:field="*{book.cId}">目录2</option>
<option value="3" th:field="*{book.cId}">目录3</option>
<option value="4" th:field="*{book.cId}">目录4</option>
</select>
</div>
radio的:
<label for="isBoy" class="col-sm-2 control-label">是否男生</label>
<div id="isBoy" class="col-sm-8">
<div class="radio-inline">
<label><input name="isBoy" type="radio" value="1" th:field="*{book.isBoy}"/> 否</label>
</div>
<div class="radio-inline">
<label><input name="isBoy" type="radio" value="0" th:field="*{book.isBoy}"/> 是</label>
</div>
</div>
总之好像不用自己去写checked=”checked” selected=”selected”这种代码,他自己会选。
上面这句是解题的精髓啊精髓。
这也是常用模式selectd的
<div class="form-group">
<label class="col-sm-4 control-label is-required">性别:</label>
<div class="col-sm-8">
<select class="form-control m-b" name="sex" th:field="*{sex}" th:value="*{sex}" >
<option value='0' th:selected="${user.sex == '0'}">男</option>
<option value='1' th:selected="${user.sex == '1'}">女</option>
<option value='2' th:selected="${user.sex == '2'}">未知</option>
</select>
</div>
</div>
checkBox的
<form action="/system/user/userRole/doRoleAuth.html" method="post">
<input name="userId" type="hidden" th:value="${user.userId}" />
<div th:each="roleCheck : ${rolesCheck}" class="form-check form-check-inline">
<input class="form-check-input" name="roleVal" type="checkbox" th:id="inlineCheckbox+${roleCheck.id}" th:value="${roleCheck.id}" th:attr="checked=${roleCheck.checked}">
<label class="form-check-label" th:for="inlineCheckbox+${roleCheck.id}" th:text="${roleCheck.name}"></label>
</div>
<button id="btn1" class="btn btn-success" type="submit" >修改</button>
</form>
配备几个th:text, th:value, th:id, th:name, th:attr, th:for, th:src, th:ref, th:each [th:selected, th:checked]这2个在文档里没有,可以考虑用th:attr来完成,虽然文档没有,有时确能使用。