BootStrap+Mybatis框架下实现表单提交数据重复验证

BootStrap+Mybatis框架下实现表单提交数据重复验证


BootStrap+Mybatis框架下实现表单提交数据重复验证

jsp页面:

<form method="post"> <div> <div> <!-- PAGE CONTENT BEGINS --> <div> <div></div> <div> <div> <div > 版本号<font color="red">*</font></div> <div> <input type="hidden" value="${list.id}" /> <input type="hidden" value="${list.versionCode}" /> <input type="text" value="${list.versionCode}" /> </div> </div> <div> <div > 版本名称<font color="red">*</font></div> <div> <input type="hidden" value="${list.versionName}" /> <input type="text" value="${list.versionName}"/> </div> </div> <div> <div > 上传应用程序<font color="red">*</font></div> <div> <input type="file" /> </div> </div> <div> <div> 下载地址<font color="red">*</font> </div> <div> <span> <input type="text" readonly="readonly" value="${list.downloadUrl}" /> </span> </div> </div> <div> <div > 更新备注<font color="red">*</font></div> <div> <textarea rows="5" >${list.updateLog}</textarea> </div> </div> </div> <div></div> <div> <div> <div> <button type="button"> <i></i>保存 </button> </div> <button type="reset"> <i></i> 重置 </button> </div> </div> </div> </div> </div> </form>

js:

ace.load_ajax_scripts(scripts, function () { jQuery(function ($) { //验证 $("#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: "<font color='#d16e6c'>必填</font>", remote:"<font color='#d16e6c'>版本号重复</font>", maxlength:"<font color='#d16e6c'>最大不能超过10位</font>" }, 'versionName':{ required: "<font color='#d16e6c'>必填</font>", remote:"<font color='#d16e6c'>版本名称重复</font>", maxlength:"<font color='#d16e6c'>最大不能超过40位</font>" }, 'updateLog':{ required: "<font color='#d16e6c'>必填</font>", maxlength:"<font color='#d16e6c'>最大不能超过120位</font>" } } }); }); });

controller控制层:

@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服务层

@Override public boolean validateversionCode(String versionCode){ int count = dbcAppVersionMapper.validateversionCode(versionCode); return (count>0)?false:true; } @Override public boolean validateversionName(String versionName){ int count = dbcAppVersionMapper.validateversionName(versionName); return (count>0)?false:true; }

dao 层

int validateversionCode(@Param("versionCode")String versionCode); int validateversionName(@Param("versionName")String versionName);

mapper.xml

<!-- APP版本名称验证--> <select resultType="java.lang.Integer"> select count(id) from dbc_app_version where VERSION_NAME=#{versionName} </select> <!-- APP版本号验证--> <select resultType="java.lang.Integer"> select count(id) from dbc_app_version where VERSION_CODE=#{versionCode} </select>

关于bootstrap专题大家可以参考下:

bootstrap 组件

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwypsw.html