时间:2020-10-11 10:48:01 | 栏目:JavaScript代码 | 点击:次
1.前台页面
<div class="layui-form-item"> <label class="layui-form-label">BOM编号</label> <div class="layui-input-block"> <input type="text" class="layui-input" name='code' lay-verify="required|unique"> </div> </div>
2.前台Js
需要引用layui.js文件
<script type="text/javascript"> var form = layui.form; form.verify({ 'unique' : function(value, item) { var checkValue = value.trim(); var checkResult=''; $.ajax({ url : '/bomManage/checkBomCode', type : 'POST', data : { "newBomCode" : checkValue }, datatype : 'json', async : false, success : function(result) { if (!result) { checkResult='BOM编号重复' } }, error : function() { kok.message("BOM编号验证失败") } }); return checkResult } }) </script>
3.后台逻辑处理
@Override public boolean checkBomCode(String newBomCode) { BdBomVersionExample example=new BdBomVersionExample(); Criteria criteria = example.createCriteria(); criteria.andCodeEqualTo(newBomCode.trim()); List<BdBomVersion> checks = bdBomVersionMapper.selectByExample(example); boolean checkValue=true; if(checks.size()>0){ checkValue=false; } return checkValue; }