目录
<form id="jangleEditForm" name="jangleEditForm" class="formJ" >
<div class="form-group" >
<label for="code">账户:</label>
<input type="text" class="form-control" id="code" name="code" placeholder="请输入账户">
</div>
<div class="form-group" >
<label for="password">密码:</label>
<input type="text" class="form-control" id="password" name="password" placeholder="请输入密码">
</div>
</form>
/*!
* demo专用js
*
*/
// 校验的渲染
$("#jangleEditForm").bootstrapValidator({
message : 'This value is not valid',
feedbackIcons : {
valid : 'glyphicon glyphicon-ok',
invalid : 'glyphicon glyphicon-remove',
validating : 'glyphicon glyphicon-refresh'
},
fields : {
code : {
validators : {
notEmpty : {
message : "请输入账户,用于登录"
},
remote:{
message :"账户已被注册",
url:'/bsUserCtrl/valid',
delay:1000,
type:"POST"
}
}
}
}
});
@Controller
@RequestMapping("/bsUserCtrl")
public class BsUserCtrl {
@Autowired
private BsUserService bsUserService;
@RequestMapping("valid")
@ResponseBody
Map<String, Object> valid(@RequestParam(required = false) String code) {
return bsUserService.valid(code);
}
}
@Service
public class BsUserServiceImpl implements BsUserService {
@Autowired
private BsUserMapper bsUserMapper;
@Override
public Map<String, Object> valid(String code) {
Map<String, Object> map = new HashMap<String, Object>();
// 根据账号查询是否存在用户
BsUser user = bsUserMapper.selectByCode(code);
if(user == null) {
map.put("valid", true);
}else {
map.put("valid", false);
}
return map;
}
}