BootStrap表单验证用户名重复
html:
<div class="form-group">
<label for="username" class="control-label col-md-3 col-sm-4">账号</label>
<div class="col-md-9 col-sm-8">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" class="form-control" id="username" name="username" placeholder="请输入昵称"/>
</div>
</div>
</div>
js:
<script type="text/javascript">
$(function () {
//alert(123)
$("#regist_form").bootstrapValidator({
live: 'enabled', //验证时机,enabled是内容有变化就验证(默认),disabled和submitted是提交再验证
excluded: [':disabled', ':hidden', ':not(:visible)', ':file'], //排除无需验证的控件,比如被禁用的或者被隐藏的
submitButtons: '#reg-btn', //指定提交按钮,如果验证失败则变成disabled,按钮变灰色
message: '通用的验证失败消息', //好像从来没出现过
feedbackIcons: { //根据验证结果显示的各种图标
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove', //小叉号
validating: 'glyphicon glyphicon-refresh'
},
fields: {
username: {
verbose: false, //代表验证按顺序验证。验证成功才会下一个(验证成功才会发最后一个remote远程验证)
validators: {
notEmpty: {
message: '账号不能为空'
},
stringLength: {
min: 6,
max: 30,
message: '账号长度必须在6到30之间'
},
threshold: 6,//有6字符以上才发送ajax请求 remote: { //ajax验证。server result:{"valid",true or false} (返回前台类型)
url: "stu-exist",
message: '用户名已存在,请重新输入',
delay: 500, //ajax刷新的时间是0.5秒一次
type: 'POST',
//自定义提交数据,默认值提交当前input value
/*data: function (validator) {
return {
userName: $("input[name=userName]").val(),
//method: "stuIsExist" //UserServlet判断调用方法关键字。 };
}*/
},
}
},
} });
})
</script>
StuService:
//验证账号是否存在(用户注册)
Boolean stuIsExist(String username);
StuServiceImpl:
/**
* @Description //验证账号是否存在
* @Date 2019-04-01 17:39
* @Param [username]
* @return java.lang.Boolean
**/
@Override
public Boolean stuIsExist(String username) { UserExample userExample = new UserExample();
UserExample.Criteria criteria = userExample.createCriteria();
criteria.andUsernameEqualTo(username);
List<User> userList = userMapper.selectByExample(userExample);
if (userList.isEmpty()) {
return true;
} else {
return false;
} }
RegisterController.java:
/**
* @Description //验证账号是否存在
* @Date 2019-04-01 17:43
* @Param [username]
* @return java.util.Map<java.lang.String,java.lang.Boolean>
**/
@PostMapping("stu-exist")
@ResponseBody
public Map<String,Boolean> stuIsExist(String username){
Boolean stuIsExist = stuService.stuIsExist(username);
Map<String,Boolean> map = new HashMap<String,Boolean>(); //map.put("valid",true);
if (stuIsExist){
map.put("valid",true);
}else {
map.put("valid",false);
} System.out.println(username+map);
return map;
}
BootStrap表单验证用户名重复的更多相关文章
- bootstrapValidator.js,最好用的bootstrap表单验证插件
前言:做Web开发的我们,表单验证是再常见不过的需求了.友好的错误提示能增加用户体验.博主搜索bootstrap表单验证,搜到的结果大部分都是文中的主题:bootstrapvalidator.今天就来 ...
- 基于Bootstrap表单验证
基于Bootstrap表单验证 GitHub地址:https://github.com/chentangchun/FormValidate 使用方式: 1.CSS样式 .valierror { bor ...
- bootstrapValidator.js,最好用的bootstrap表单验证插件 简单实用方法
实用方法 1.引入 在有jquery和bootstrap的页面里引入bootstrapValidator.js和bootstrapValidator.css文件 2. 按照bootstrap的表单组件 ...
- bootStrap表单验证插件的使用
bootStrapValidator插件的使用 1.插件的下载和引用 首先要引入bootstrapValidator插件.链接的地址:https://www.bootcdn.cn/jquery.boo ...
- Bootstrap表单验证插件bootstrapValidator使用方法整理
插件介绍 先上一个图: 下载地址:https://github.com/nghuuphuoc/bootstrapvalidator 使用方法:http://www.cnblogs.com/huangc ...
- Bootstrap表单验证
主要用过两个: jqBootstrapValidation: https://github.com/ReactiveRaven/jqBootstrapValidation bootstrapValid ...
- bootstrap 表单验证 dem
地址:http://www.jq22.com/yanshi522 一些api详解:http://blog.csdn.net/u013938465/article/details/53507109 ht ...
- 黄聪: Bootstrap之Form表单验证神器: BootstrapValidator(转)
前言:做Web开发的我们,表单验证是再常见不过的需求了.友好的错误提示能增加用户体验.博主搜索bootstrap表单验证,搜到的结果大部分都是文中的主题:bootstrapvalidator.今天就来 ...
- Bootstrap之Form表单验证神器: BootstrapValidator(转)
前言:做Web开发的我们,表单验证是再常见不过的需求了.友好的错误提示能增加用户体验.博主搜索bootstrap表单验证,搜到的结果大部分都是文中的主题:bootstrapvalidator.今天就来 ...
随机推荐
- nginx+keepalived高可用web负载均衡
一:安装环境 准备2台虚拟机,都安装好环境 centos 7keepalived:vip: 192.168.1.112192.168.1.110 nginxip 192.168.1.109 maste ...
- mysql同步复制异常的常见操作-传统复制方式
mysql同步复制异常的常见操作-传统复制方式 一.传统复制方式是基于非gtid的,常见的错误有1032和1062 1032是主键冲突,1062是从库中没有找到对应的记录. 可以查看出现错误的binl ...
- linux ssh 报错failed - POSSIBLE BREAK-IN ATTEMPT
linux ssh 报错failed - POSSIBLE BREAK-IN ATTEMPT 问题故障: 今天在新租的虚拟机上,发现ssh登陆机器的时候报错,如下: [root@pictures_ne ...
- python 发送邮件模板
##发送普通txt文件(与发送html邮件不同的是邮件内容设置里的type设置为text,下面代码为发送普通邮件的另一种方法) import smtplibimport stringfrom emai ...
- Kafka各个版本差异汇总
Kafka各个版本差异汇总 从0.8.x,0.9.x,0.10.0.x,0.10.1.x,0.10.2.x,0.11.0.x,1.0.x或1.1.x升级到2.0.0 Kafka 2.0.0引入了线 ...
- 面向对象【day07】:面向对象使用场景(十)
本节内容 1.概述 2.知识回顾 3.使用场景 一.概述 之前我们学了面向对象知识,那我们在什么时候用呢?不可能什么时候都需要用面向对象吧,除非你是纯的面向对象语言,好的,我们下面就来谈谈 二.知识回 ...
- Mastering Markdown
What is markdown? Markdown is a lightweight and easy-to-use syntax for styling all forms writing on ...
- golang 常量
介绍 常量使用const修改 常量在定义时必须初始化 常量定义后不能修改 常量只能修饰bool.数值类型(int.float).string类型 golang中没有硬性规定常量必使用大写字母,但仍然通 ...
- bzoj千题计划310:bzoj5285: [Hnoi2018]寻宝游戏(思维题+哈希)
https://www.lydsy.com/JudgeOnline/problem.php?id=5285 |0 和 &1 没有影响 若填‘|’,记为0,若填‘&’,记为1 先只考虑最 ...
- toString() 和 强制类型转换 (String)
转自https://www.cnblogs.com/yuxiaoqi/p/3562161.html 简述 在Java中,往往需要把一个类型的变量转换成String 类型.作为菜鸟,有时候我会使用(St ...