diff --git a/pom.xml b/pom.xml index f758f59..ac1cedd 100644 --- a/pom.xml +++ b/pom.xml @@ -61,6 +61,11 @@ org.apache.ant ant + + + org.projectlombok + lombok + diff --git a/src/main/java/com/fjy/spring/controller/RegisterController.java b/src/main/java/com/fjy/spring/controller/RegisterController.java index 9c7eaf4..0073e55 100644 --- a/src/main/java/com/fjy/spring/controller/RegisterController.java +++ b/src/main/java/com/fjy/spring/controller/RegisterController.java @@ -20,6 +20,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import java.math.BigInteger; +import java.util.Optional; @Controller public class RegisterController { @@ -72,4 +73,18 @@ public class RegisterController { return false; } + /** + * 查询用户名是否存在 + * @param name + * @return + */ + @GetMapping("/CheckUserName") + @ResponseBody + public boolean doUserName(@RequestParam(value = "name") String name){ + Optional user = userService.findByColname(name); + if (user.isPresent()) + return false; + return true; + } + } diff --git a/src/main/java/com/fjy/spring/service/StudentService.java b/src/main/java/com/fjy/spring/service/StudentService.java index 04c827c..701e342 100644 --- a/src/main/java/com/fjy/spring/service/StudentService.java +++ b/src/main/java/com/fjy/spring/service/StudentService.java @@ -26,4 +26,6 @@ public class StudentService { return tbStudentListRepository.findByColstudentnoAndColrealname(studentno,realname); } + + } diff --git a/src/main/java/com/fjy/spring/service/UserService.java b/src/main/java/com/fjy/spring/service/UserService.java index 0331266..b3c17e2 100644 --- a/src/main/java/com/fjy/spring/service/UserService.java +++ b/src/main/java/com/fjy/spring/service/UserService.java @@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; @Service @@ -23,7 +24,15 @@ public class UserService { public TbUser doLoginService(String name,String password){ - TbUser user = (TbUser)tbUserRepository.findByColname(name).get(); + //TbUser user = (TbUser)tbUserRepository.findByColname(name).get(); + Optional tbUser = tbUserRepository.findByColname(name); + TbUser user = new TbUser(); + if (tbUser.isPresent()){ + user = (TbUser)tbUser.get(); + }else { + throw new UserException(ResultEnum.EMPTY_DATA); + } + if (user!=null){ if (password.equals(user.getColpassword())){ return user; @@ -53,4 +62,8 @@ public class UserService { return vUserinfoRepository.findById(coluserid).get(); } + public Optional findByColname(String name){ + return tbUserRepository.findByColname(name); + } + } diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..4488451 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,58 @@ + + + + + + + + + ERROR + DENY + ACCEPT + + + + %d - %msg%n + + utf8 + + + + + F:\JAVA Workspace\Temp\log\info.%d.log + + + + + + + ERROR + + + + %d - %msg%n + + utf8 + + + + + F:\JAVA Workspace\Temp\log\error.%d.log + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/static/js/LoginStyle.js b/src/main/resources/static/js/LoginStyle.js index 432e034..046874c 100644 --- a/src/main/resources/static/js/LoginStyle.js +++ b/src/main/resources/static/js/LoginStyle.js @@ -1,6 +1,30 @@ var Main = { data() { var checkName = (rule, value, callback) => { + if (!value) { + return callback(new Error('用户名不能为空')); + }else { + //判断用户名是否已存在 + axios.get(getRootPath_web() + '/CheckUserName', { + params: { + name: 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 checkName1 = (rule, value, callback) => { if (!value) { return callback(new Error('用户名不能为空')); } else { @@ -76,6 +100,10 @@ var Main = { } }; return { + ruleForm1: { + colname: '', + colpassword: '', + }, ruleForm2: { colname: '', colpassword: '', @@ -84,6 +112,14 @@ var Main = { colrealname: '', colemail: '' }, + rules1: { + colpassword: [ + {required: true,validator: validatePass, trigger: 'blur'} + ], + colname: [ + {required: true,validator: checkName1, trigger: 'blur'} + ], + }, rules2: { colpassword: [ {required: true, validator: validatePass, trigger: 'blur'} diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html index 69da4ba..f73760f 100644 --- a/src/main/resources/templates/login.html +++ b/src/main/resources/templates/login.html @@ -22,20 +22,20 @@ @tab-click="handleClick"> - + v-model="ruleForm1.colname" name="colname"> + v-model="ruleForm1.colpassword" auto-complete="off" name="colpassword">