实现前端对学号和用户名的异步判断,核心技术为axios
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
package com.fjy.spring.controller;
|
||||
|
||||
import com.fjy.spring.domain.TbStudentlist;
|
||||
import com.fjy.spring.domain.TbUser;
|
||||
import com.fjy.spring.enums.ResultEnum;
|
||||
import com.fjy.spring.exception.UserException;
|
||||
import com.fjy.spring.properties.ServerProperties;
|
||||
import com.fjy.spring.service.StudentService;
|
||||
import com.fjy.spring.service.UserService;
|
||||
import com.fjy.spring.untils.CodingUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -22,6 +27,9 @@ public class RegisterController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private StudentService studentService;
|
||||
|
||||
@Autowired
|
||||
private ServerProperties serverProperties;
|
||||
|
||||
@@ -45,4 +53,23 @@ public class RegisterController {
|
||||
throw new UserException(ResultEnum.UNKOWN_ERROR);
|
||||
}
|
||||
|
||||
@GetMapping("/CheckStudentNo")
|
||||
@ResponseBody
|
||||
public boolean doCheckStudentNo(@RequestParam(value = "studentno") String studentno){
|
||||
TbStudentlist studentlist = studentService.findStudentByNo(studentno);
|
||||
if (studentlist!=null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@GetMapping("/CheckStudent")
|
||||
@ResponseBody
|
||||
public boolean doCheckStudent(@RequestParam(value = "studentno") String studentno,
|
||||
@RequestParam(value = "realname") String realname){
|
||||
TbStudentlist studentlist = studentService.findByColstudentnoAndColrealname(studentno,realname);
|
||||
if (studentlist!=null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.fjy.spring.repository;
|
||||
|
||||
import com.fjy.spring.domain.TbStudentlist;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface TbStudentListRepository extends JpaRepository<TbStudentlist,Integer> {
|
||||
|
||||
public TbStudentlist findByColstudentno(String colstudentno);
|
||||
|
||||
public TbStudentlist findByColstudentnoAndColrealname(String colstudentno,String colrealname);
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.fjy.spring.service;
|
||||
|
||||
import com.fjy.spring.domain.TbStudent;
|
||||
import com.fjy.spring.domain.TbStudentlist;
|
||||
import com.fjy.spring.domain.TbUser;
|
||||
import com.fjy.spring.repository.TbStudentListRepository;
|
||||
import com.fjy.spring.repository.TbStudentRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -13,4 +15,15 @@ public class StudentService {
|
||||
@Autowired
|
||||
private TbStudentRepository tbStudentRepository;
|
||||
|
||||
@Autowired
|
||||
private TbStudentListRepository tbStudentListRepository;
|
||||
|
||||
public TbStudentlist findStudentByNo(String studentno){
|
||||
return tbStudentListRepository.findByColstudentno(studentno);
|
||||
}
|
||||
|
||||
public TbStudentlist findByColstudentnoAndColrealname(String studentno,String realname){
|
||||
return tbStudentListRepository.findByColstudentnoAndColrealname(studentno,realname);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,22 +3,57 @@ var Main = {
|
||||
var checkName = (rule, value, callback) => {
|
||||
if (!value) {
|
||||
return callback(new Error('用户名不能为空'));
|
||||
}else {
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
};
|
||||
var checkNo = (rule, value, callback) => {
|
||||
if (!value) {
|
||||
return callback(new Error('学号不能为空'));
|
||||
}else {
|
||||
callback()
|
||||
} else {
|
||||
//判断是否为指定班级的合法用户
|
||||
axios.get(getRootPath_web() + '/CheckStudentNo', {
|
||||
params: {
|
||||
studentno: value
|
||||
}
|
||||
})
|
||||
.then(function (response) {
|
||||
console.log(response.data);
|
||||
if (response.data === true) {
|
||||
callback()
|
||||
} else {
|
||||
return callback(new Error('学号非法'));
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
this.errorNotify(error.message);
|
||||
});
|
||||
}
|
||||
};
|
||||
var checkRealName = (rule, value, callback) => {
|
||||
if (!value) {
|
||||
return callback(new Error('真实姓名不能为空'));
|
||||
}else {
|
||||
callback()
|
||||
} else {
|
||||
//判断用户名与学号是否匹配
|
||||
axios.get(getRootPath_web() + '/CheckStudent', {
|
||||
params: {
|
||||
realname: value,
|
||||
studentno: this.ruleForm2.colstudentno
|
||||
}
|
||||
})
|
||||
.then(function (response) {
|
||||
console.log(response.data);
|
||||
if (response.data === false) {
|
||||
return callback(new Error('姓名与学号不匹配'));
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
this.errorNotify(error.message);
|
||||
});
|
||||
}
|
||||
};
|
||||
var validatePass = (rule, value, callback) => {
|
||||
@@ -44,17 +79,17 @@ var Main = {
|
||||
ruleForm2: {
|
||||
colname: '',
|
||||
colpassword: '',
|
||||
checkPass:'',
|
||||
checkPass: '',
|
||||
colstudentno: '',
|
||||
colrealname: '',
|
||||
colemail: ''
|
||||
},
|
||||
rules2: {
|
||||
colpassword: [
|
||||
{required: true,validator: validatePass, trigger: 'blur'}
|
||||
{required: true, validator: validatePass, trigger: 'blur'}
|
||||
],
|
||||
checkPass: [
|
||||
{required: true,validator: validatePass2, trigger: 'blur'}
|
||||
{required: true, validator: validatePass2, trigger: 'blur'}
|
||||
],
|
||||
colstudentno: [
|
||||
{
|
||||
@@ -71,13 +106,19 @@ var Main = {
|
||||
}
|
||||
],
|
||||
colname: [
|
||||
{required: true,validator: checkName, trigger: 'blur'}
|
||||
{required: true, validator: checkName, trigger: 'blur'}
|
||||
],
|
||||
},
|
||||
activeName:'login',
|
||||
activeName: 'login',
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
errorNotify(content) {
|
||||
this.$notify.error({
|
||||
title: '错误',
|
||||
message: content
|
||||
})
|
||||
},
|
||||
submitForm(formName) {
|
||||
this.$refs[formName].validate((valid) => {
|
||||
if (valid) {
|
||||
|
||||
Reference in New Issue
Block a user