This article mainly introduces how to implement the form submission Data repeat verification function under the BootStrap + Mybatis framework, which is very good and has reference value, for more information about how to use the BootStrap + Mybatis framework to verify data duplication in Form submission, see this article.
Effect:
Jsp page:
Js:
Ace. load_ajax_scripts (scripts, function () {jQuery (function ($) {// verification $ ("# dbc_code_add_form "). validate ({rules: {'versioncode': {required: true, maxlength: 20, remote: {type: "post", dataType: "json", data: {versionCode: function () {return $ ("# versionCode "). val () ;}, oldversionCode: function () {return $ ("# oldversionCode "). val () ;}, url: "$ {base}/admin/road/app/validateversionCode. do "}}, 'versionname': {required: true, maxlength: 40, remote: {type:" post ", dataType:" json ", data: {versionName: function () {return $ ("# versionName "). val () ;}, oldversionName: function () {return $ ("# oldversionName "). val () ;}, url: "$ {base}/admin/road/app/validateversionName. do "}}, 'updatelog ': {required: true, maxlength: 125 }}, messages: {'versioncode': {required:" required ", remote: "duplicate version numbers", maxlength: "Up to 10 characters"}, 'versionname': {required: "required", remote: "duplicate version names", maxlength: "Up to 40 BITs allowed"}, 'updatelog': {required: "required", maxlength: "up to 120 bits allowed "}}});});});
Controller control layer:
@RequestMapping(value="/validateversionCode",method=RequestMethod.POST) @ResponseBody public boolean validateversionCode(@RequestParam("versionCode")String versionCode, @RequestParam("oldversionCode")String oldversionCode){ if(!versionCode.equals(oldversionCode)||StringUtils.isEmpty(oldversionCode)){ boolean isOk = appversionService.validateversionCode(versionCode); return isOk; } return true; }
@RequestMapping(value="/validateversionName",method=RequestMethod.POST) @ResponseBody public boolean validateversionName(@RequestParam("versionName")String versionName, @RequestParam("oldversionName")String oldversionName){ if(!versionName.equals(oldversionName)||StringUtils.isEmpty(oldversionName)){ boolean isOk = appversionService.validateversionName(versionName); return isOk; } return true; }
Service Layer
@Overridepublic boolean validateversionCode(String versionCode){int count = dbcAppVersionMapper.validateversionCode(versionCode);return (count>0)?false:true;}@Overridepublic boolean validateversionName(String versionName){int count = dbcAppVersionMapper.validateversionName(versionName);return (count>0)?false:true;}
Dao Layer
int validateversionCode(@Param("versionCode")String versionCode);int validateversionName(@Param("versionName")String versionName);
Mapper. xml
Select count (id) from dbc_app_versionwhere VERSION_NAME =#{ versionName}
Select count (id) from dbc_app_versionwhere VERSION_CODE =#{ versionCode}
The above section details how to share code that implements form submission data duplication verification under the BootStrap + Mybatis framework. For more information, see other related articles in the first PHP community!