专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

springboot的thymeleaf模板中input, select, radio回显

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来完成,虽然文档没有,有时确能使用。

文章永久链接:https://tech.souyunku.com/24772

未经允许不得转载:搜云库技术团队 » springboot的thymeleaf模板中input, select, radio回显

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们