如何以模式显示验证输入(春季启动)

时间:2019-07-28 06:02:59

标签: jquery html ajax spring-boot thymeleaf

我使用百里香和弹簧靴,我想在输入为空且不关闭模式时显示验证请求输入, 我认为它必须使用Ajax,但我不了解Ajax。 ................................................... ................................................... ................................................... HTML

<!-- AddStore Modal -->
<div class="modal fade" id="AddUserModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="AddUserModalLabel">Add Store Form</h5>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">
                <form autocomplete="off" action="#" th:action="@{/stores/add_store}"
                      th:object="${store}" method="post" class="form-horizontal"
                      role="form" id="addModalForm">
                    <div class="form-row">
                        <div class="form-group col-md-6">
                            <label for="addstoreName">Store Name</label>
                            <input type="text" class="form-control" id="addstoreName" th:field="*{storeName}">
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-group col-md-6">
                            <label for="addStatus">Status</label>
                            <select id="addStatus" class="form-control" th:field="*{status}">
                                <option th:value="Ready_to_service">Ready to service</option>
                                <option th:value="Temporarily_closed">Temporarily closed</option>
                                <option th:value="Closed">Closed</option>
                            </select>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                        <button class="btn btn-success" type="submit" th:text="Save"></button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

控制器

@RequestMapping(value = "/stores/add_store", method = RequestMethod.POST)
public ModelAndView AddStore(@Valid Store store, BindingResult bindingResult, RedirectAttributes redirectAttributes) {
    ModelAndView modelAndView = new ModelAndView();
    if (bindingResult.hasErrors()) {
        redirectAttributes.addFlashAttribute("message_error", bindingResult.getAllErrors());
    } else {
        storeService.saveStore(store);
        redirectAttributes.addFlashAttribute("message", "Store has been Added Successful!");
    }
    modelAndView.setViewName("redirect:/stores/manage-stores");
    return modelAndView;
}

0 个答案:

没有答案