簡體   English   中英

Spring驗證,表單不顯示錯誤消息

[英]Spring Validation, form doesn't show error message

為什么我的“ addcar”視圖中的表單不顯示消息?

My Controller method

@RequestMapping(value = "/add-car", method = RequestMethod.POST)
public String addCar(@ModelAttribute("carDto") @Valid CarDto carDto, 
BindingResult bindingResult, ModelMap modelMap) {

    if (bindingResult.hasErrors()) {
        if (carDto.isDealerCar() == false) {
            String status = "userCession";
            boolean dealerCar = false;
            boolean accepted = false;
            int numberOfTestDrives = 0;
            modelMap.addAttribute("carDto", new CarDto());
            modelMap.addAttribute("status", status);
            modelMap.addAttribute("dealerCar", dealerCar);
            modelMap.addAttribute("accepted", accepted);
            modelMap.addAttribute("numberOfTestDrives", numberOfTestDrives);
            return "car/addcar";
        }

我的表單示例(addcar視圖)

        <div class="form-group">
            <h3>
                <span class="label label-default">Numer VIN</span>
            </h3>
            <input type="text" class="form-control" th:field="*{vin}" />
            <div class="alert alert-warning" 
                 th:if="${#fields.hasErrors('vin')}">
                <span th:errors="*{vin}">Error</span>
            </div>
        </div>

當我只是返回到我的addcar視圖時,它起作用了,但是沒有我的設置值就通過了,並且我無法提交表單。 如上所示,新表單通過但沒有錯誤消息。

你可以試試:

public String addCar(@requestParam(Map)){

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM