<div class="col-sm-8"> <select data-placeholder="请选择实验室" id="laboratoryId" name="laboratoryId" class="form-control chosen-select" style=" 100%; " required > <option value="" selected>请选择</option> <option th:each="laboratoryDO:${laboratoryDOList}" th:value="${laboratoryDO.laboratoryId}" th:text="${laboratoryDO.labName}" ></option> </select> </div>
js
<script type="text/javascript" th:inline="javascript"> $().ready(function() { var single = [[${laboratoryId}]]; $("#laboratoryId option[value= " + single + "]").prop("selected",true); }); </script>
后台
model.addAttribute("laboratoryId",laboratoryId);