Thymeleaf错误消息绑定结果未在客户端显示

时间:2019-07-24 15:23:17

标签: spring-boot thymeleaf

当描述字段超过300个字符时,我想在客户端(HTML页)上显示错误消息。结果现在发生的是 当字符超过300个单词时,系统不接受正确的表单(按提交按钮后),但我看不到错误消息。

标记文件

<div class="form-group">
                                            <label th:text="#{tankLorryPlan.editor.otherReason}">Other reasons</label>
                                            <span th:if="${#fields.hasErrors('tankLorryCheckErrorDescription')}" class="text-danger"
                                                  th:errors="*{tankLorryCheckErrorDescription}">Suggestion description cannot be null</span>
                                            <textarea class="form-control" rows="3" th:field="*{tankLorryCheckErrorDescription}"
                                                      th:placeholder="#{tankLorryPlan.editor.otherReason.freeText.placeholder}"></textarea>
                                        </div>

控制器类

 @PutMapping(path = "/edit-tkw/{id}")
    public String editTankLorryPlanList(Model model, @PathVariable int id,
                                        @Valid TankLorryPlanForBatch tankLorryPlanForBatchEdit,
                                        BindingResult bindingResult) {
        TankLorryPlanForBatch tlp = tankLorryPlanForBatchRepo.findById(id).get();

        if (bindingResult.hasErrors()) {
            tankLorryPlanForBatchEdit.setBatch(tlp.getBatch());
            log.error("bindingResult for tkw, " + bindingResult);
            model.addAttribute("tankLorryPlanForBatchEdit", tankLorryPlanForBatchEdit);

            return "sb-admin-2/tank-lorry-plan-for-batch/edit-tkw";
        }
 .......
 .......

模型类

@Size(max = 300,  message = "{tankLorryPlan.validation.info.size}")
    private String tankLorryCheckErrorDescription; 

控制台错误日志消息快照

https://imgur.com/PzhWG5N

在图像中的红色框显示的位置,我希望错误消息出现,但超过300个字符。 https://imgur.com/qV8lUDl

0 个答案:

没有答案