diff --git a/src/main/java/cn/edu/cqwu/repair/controller/StuController.java b/src/main/java/cn/edu/cqwu/repair/controller/StuController.java
index ef4e9af..3b05f6b 100644
--- a/src/main/java/cn/edu/cqwu/repair/controller/StuController.java
+++ b/src/main/java/cn/edu/cqwu/repair/controller/StuController.java
@@ -4,7 +4,9 @@ import cn.edu.cqwu.repair.dao.StuDao;
import cn.edu.cqwu.repair.entity.Stu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.SessionAttribute;
import javax.servlet.http.HttpServletRequest;
@@ -24,34 +26,74 @@ public class StuController {
@Autowired
StuDao stuDao;
- @RequestMapping("/regist.do")
- public String Register(String userNo, String username, String password, String gender, HttpServletRequest request){
- Stu stu = new Stu();
- stu.setUserNo(userNo);
- stu.setUsername(username);
- stu.setPassword(password);
- stu.setStatus(0);
- stu.setGender(gender);
- String localAddr = request.getLocalAddr();
- stu.setRegip(localAddr);
- stuDao.add(stu);
+ @PostMapping("/sturegist.do")
+ public String Register(String userNo, String username, String password , HttpServletRequest request){
+ Stu byUsername = stuDao.findByUsername(username);
+ if(byUsername==null) {
+ Stu stu = new Stu();
+ stu.setUserNo(userNo);
+ stu.setUsername(username);
+ stu.setPassword(password);
+ stu.setStatus(0);
+ String localAddr = request.getLocalAddr();
+ stu.setRegip(localAddr);
+ int add = stuDao.add(stu);
+ if(add==1) {
+ request.setAttribute("stuRegistMess", "注册成功");
+ return "redirect:/student/index.jsp";
+ }
+ request.setAttribute("stuRegistMess", "注册失败");
+ return "/student/register";
+ }else{
+ return "/student/register";
+ }
- return "/student/success";
}
-@RequestMapping("/stulogin.do")
-
+@PostMapping("/stulogin.do")
public String login( String username, String password, HttpServletRequest request){
Stu stu = stuDao.validateLogin(username, password);
- request.getSession().setAttribute("student",stu);
+ if(stu!=null) {
+ request.getSession().setAttribute("stu", stu);
+ request.setAttribute("stuLoginMess","登陆成功");
+ return "/student/edit";
+ }else{
+ request.setAttribute("stuLoginMess","登陆失败");
- return "/student/success";
+ return "index";
+ }
}
+ @RequestMapping("/stueditpassword.do")
+ public String edit(String password, String oldpassword,HttpServletRequest request, @SessionAttribute Stu stu){
+ if(oldpassword.equals(stu.getPassword())) {
+ int i = stuDao.passModify(stu.getUsername(), password);
+ if(i!=0) {
+ stu.setPassword(password);
+ request.getSession().setAttribute("student", stu);
+ request.setAttribute("stuEditMess","修改成功");
+
+ return "/student/edit";
+ }else{
+ request.setAttribute("stuEditMess","修改失败");
+
+ return "/student/edit";
+ }
+ }
+ request.setAttribute("stuEditMess","修改失败");
+ return "/student/edit";
+
+ }
+
+
+
+
+
+
}
diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp
index afd6580..2869087 100644
--- a/src/main/webapp/index.jsp
+++ b/src/main/webapp/index.jsp
@@ -1,10 +1,4 @@
-<%--
- Created by IntelliJ IDEA.
- User: xtaod
- Date: 2023/12/9
- Time: 10:18
- To change this template use File | Settings | File Templates.
---%>
+
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
@@ -12,19 +6,22 @@
<%@ page isELIgnored="false" %>