Here it is necessary to say that Bootstrapvalidator's help document is relatively simple to write, especially for remote validators, and after a multi-party test, it is not clear how to use this validator.
A typical Ajax validation code is as follows:
The server-side validation code (using spring MVC) is as follows:
/** Returns the result of string type * Check the legality of user name, return False if user already exists, otherwise return True (return JSON data, format {"Valid", true})*/@RequestMapping (Value= "/checknameexistsmethod1", produces = "Application/json;charset=utf-8") Public@ResponseBody string checkNameValidMethod1 (@RequestParam string name) {Booleanresult =true; List<Employee> lstemployees =employeeservice.getallemployees (); for(Employee employee:lstemployees) {if(Employee.getname (). Equals (name)) {result=false; Break; }} Map<string, boolean> map =NewHashmap<>(); Map.put ("Valid", result); Objectmapper Mapper=NewObjectmapper (); String resultstring= ""; Try{resultstring=mapper.writevalueasstring (map); } Catch(jsonprocessingexception e) {e.printstacktrace (); } returnresultstring; }
It is important to note that the bootstrap remote validator needs to return the result must be in JSON format data :
{"Valid":false// indicates illegal, validation does not pass {"valid":true// means valid, validation passed
If any other value is returned, the page validation will not get the validation result resulting in an inability to validate.
Remote verification experience with Bootstrapvalidator