【thymeleaf】 select默认值回传失效 th:selected失效

                            <div class="form-group">
                                <label>状态</label>
                                <div th:classappend="${#fields.hasErrors('status')} ? 'is-invalid' : ''">
                                    <select class="form-control" name="status" >
                                        <option th:selected="1 == ${status}" value="1">启用</option>
                                        <option th:selected="0==${status}" value="0">停用</option>
                                    </select>
                                </div>
                                <span class="invalid-feedback" role="alert" th:if="${#fields.hasErrors('status')}"><strong th:errors="*{status}"></strong></span>
                            </div>

上面是失效代码,试了很久,最后把${status}改成*{status}就好了

猜你喜欢

转载自blog.csdn.net/mudarn/article/details/118147754