Spring Boot - Проверка загрузочного ремешка - удаленная проверка всегда показывает ошибку даже для правильного результата - PullRequest
0 голосов
/ 08 декабря 2018

У меня есть файл .js для проверки моей формы.Мне нужно проверить базу данных, чтобы найти это поле является дубликатом или нет.Для этого я использую пульт.Это всегда отображает сообщение об ошибке. Также я не знаю, как проверить ответ.

Поле:

<input required="true" th:field="*{deptCode}" id="code" type="text" maxlength="3" class="form-control" name="deptCode" placeholder="Example: 014" />

JS:

    $('#registrationForm').bootstrapValidator({
    fields: {
        deptCode: {
            message: 'The Department Code is not valid',
            validators: {
                notEmpty: {
                    message: 'The Department Code is required and cannot be empty'
                },
                remote: {
                    message: 'This Department Code Already Exist',
                    url: '/path/existingdepartmentcode',
                    data: function(validator) {
                        return {
                            deptcode: validator.getFieldElements('deptCode').val()
                        };
                    }
                },
                callback: {
                    message: 'The Department Code should not start or end with empty spaces.',
                    callback: function(value, validator, $field) {
                        console.log(validator);
                        if (value === '') {
                            return true;
                        }
                        return true;
                    }
                }
            }
        }
    }
}
});

Метод класса моего контроллера:

@RequestMapping(value = "/path/existingdepartmentcode", method = RequestMethod.GET)
    public @ResponseBody boolean checkCompanyHRIS(@RequestParam("deptcode") String deptcode,
            RedirectAttributes redirectAttributes, Model model) {
        LOGGER.info("existingdepartment" + deptrepo.getDepartmentByCode(deptcode));
        return deptrepo.getDepartmentByCode(deptcode) != null;

    }

Но это не работает.Пожалуйста, помогите мне!

...