diff --git a/project/src/main/java/cyou/chenx221/controller/AdminController.java b/project/src/main/java/cyou/chenx221/controller/AdminController.java index bd75ff0..07eefe5 100644 --- a/project/src/main/java/cyou/chenx221/controller/AdminController.java +++ b/project/src/main/java/cyou/chenx221/controller/AdminController.java @@ -1,44 +1,53 @@ package cyou.chenx221.controller; - +import cyou.chenx221.modal.Admin; import cyou.chenx221.service.AdminService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +/** + * 用户登录和注销Controller + */ @Controller public class AdminController { - + @RequestMapping("/toMainPage") + public String toMainPage(){ + return "main"; + } + //注入userService @Autowired private AdminService adminService; - + /* + 用户登录 + */ @RequestMapping("/login") - public String login(@RequestParam("username") String username, - @RequestParam("password") String password) { - - // 进行用户名和密码的验证逻辑 - if (adminService.validateCredentials(username, password)) { - // 验证成功,进行相应的操作 - // 这里可以进行重定向或返回视图等操作 - return "redirect:/admin/dashboard"; - } else { - // 验证失败,返回登录页面或错误提示 - return "redirect:/admin/login?error"; + public String login(Admin admin, HttpServletRequest request){ + try { + Admin a = adminService.login(admin); + if(a!=null){ + request.getSession().setAttribute("USER_SESSION",a); + return "redirect:/main.jsp"; + } + request.setAttribute("msg","用户名或密码错误"); + return "forward:/login.jsp"; + }catch(Exception e){ + e.printStackTrace(); + request.setAttribute("msg","系统错误"); + return "forward:/login.jsp"; } } - @GetMapping("/dashboard") - public String dashboard() { - // 处理管理员登录后的仪表盘页面 - // 返回相应的视图页面 - return "admin/dashboard"; - } - - @GetMapping("/logout") - public String logout() { - // 执行登出操作,清除用户信息或会话信息 - return "redirect:/admin/login"; + @RequestMapping("/logout") + public String logout( HttpServletRequest request){ + try { + HttpSession session = request.getSession(); + session.invalidate(); + return "forward:/login.jsp"; + }catch(Exception e){ + e.printStackTrace(); + request.setAttribute("msg","系统错误"); + return "forward:/login.jsp"; + } } } diff --git a/project/src/main/java/cyou/chenx221/mapper/AdminMapper.java b/project/src/main/java/cyou/chenx221/mapper/AdminMapper.java index 8089c64..7186b68 100644 --- a/project/src/main/java/cyou/chenx221/mapper/AdminMapper.java +++ b/project/src/main/java/cyou/chenx221/mapper/AdminMapper.java @@ -1,13 +1,17 @@ package cyou.chenx221.mapper; import cyou.chenx221.modal.Admin; +import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Result; import org.apache.ibatis.annotations.Results; import org.apache.ibatis.annotations.Select; +import org.springframework.stereotype.Repository; +@Mapper +@Repository public interface AdminMapper { @Select("select * from user where username=#{username} AND password=#{password}") - @Results(id = "userMap",value = { + @Results(id = "adminMap",value = { @Result(id = true,column = "user_id",property = "id"), @Result(column = "username",property = "name"), @Result(column = "password",property = "password"), diff --git a/project/src/main/java/cyou/chenx221/service/impl/AdminServiceImpl.java b/project/src/main/java/cyou/chenx221/service/impl/AdminServiceImpl.java index bbb8e56..369ef4a 100644 --- a/project/src/main/java/cyou/chenx221/service/impl/AdminServiceImpl.java +++ b/project/src/main/java/cyou/chenx221/service/impl/AdminServiceImpl.java @@ -1,6 +1,18 @@ package cyou.chenx221.service.impl; +import cyou.chenx221.mapper.AdminMapper; +import cyou.chenx221.modal.Admin; +import cyou.chenx221.service.AdminService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + @Service public class AdminServiceImpl implements AdminService { + @Autowired + private AdminMapper adminMapper; + @Override + public Admin login(Admin admin) { + return null; + } } diff --git a/project/web/login.jsp b/project/web/login2.jsp similarity index 99% rename from project/web/login.jsp rename to project/web/login2.jsp index 4a71306..f810697 100644 --- a/project/web/login.jsp +++ b/project/web/login2.jsp @@ -55,7 +55,7 @@
-
+

用户登录

diff --git a/project2/.gitignore b/project2/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/project2/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/project2/.idea/.gitignore b/project2/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/project2/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/project2/.idea/artifacts/project2_war_exploded.xml b/project2/.idea/artifacts/project2_war_exploded.xml new file mode 100644 index 0000000..ae6b2a6 --- /dev/null +++ b/project2/.idea/artifacts/project2_war_exploded.xml @@ -0,0 +1,13 @@ + + + $PROJECT_DIR$/out/artifacts/project2_war_exploded + + + + + + + + + + \ No newline at end of file diff --git a/project2/.idea/encodings.xml b/project2/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/project2/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/project2/.idea/misc.xml b/project2/.idea/misc.xml new file mode 100644 index 0000000..463551f --- /dev/null +++ b/project2/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/project2/.idea/vcs.xml b/project2/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/project2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/project2/pom.xml b/project2/pom.xml new file mode 100644 index 0000000..f28af1a --- /dev/null +++ b/project2/pom.xml @@ -0,0 +1,152 @@ + + + 4.0.0 + + cyou.chenx221 + project2 + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + org.springframework + spring-context + 5.3.27 + + + org.springframework + spring-web + 5.3.27 + + + org.springframework + spring-webmvc + 5.3.27 + + + org.springframework + spring-tx + 5.3.27 + + + org.springframework + spring-jdbc + 5.3.27 + + + org.springframework + spring-test + 5.3.27 + + + + org.mybatis + mybatis + 3.5.7 + + + org.mybatis + mybatis-spring + 2.0.7 + + + + + javax.servlet + javax.servlet-api + 4.0.1 + + + javax.servlet.jsp + javax.servlet.jsp-api + 2.3.3 + + + + + org.apache.tomcat.embed + tomcat-embed-core + 9.0.73 + + + + + mysql + mysql-connector-java + 8.0.28 + + + + + org.apache.logging.log4j + log4j-core + 2.20.0 + + + + com.alibaba + druid + 1.1.20 + + + junit + junit + 4.12 + compile + + + com.github.pagehelper + pagehelper + 5.3.3 + + + jstl + jstl + 1.2 + + + taglibs + standard + 1.1.2 + + + + com.fasterxml.jackson.core + jackson-core + 2.9.2 + + + com.fasterxml.jackson.core + jackson-databind + 2.9.2 + + + com.fasterxml.jackson.core + jackson-annotations + 2.9.0 + + + org.slf4j + slf4j-log4j12 + 1.6.1 + + + + org.apache.logging.log4j + log4j-api + 2.10.0 + + + + org.apache.logging.log4j + log4j-core + 2.10.0 + + + \ No newline at end of file diff --git a/project2/src/main/resources/applicationContext.xml b/project2/src/main/resources/applicationContext.xml new file mode 100644 index 0000000..142def2 --- /dev/null +++ b/project2/src/main/resources/applicationContext.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/project2/src/main/resources/mybatis-config.xml b/project2/src/main/resources/mybatis-config.xml new file mode 100644 index 0000000..e69de29 diff --git a/project2/web/WEB-INF/web.xml b/project2/web/WEB-INF/web.xml new file mode 100644 index 0000000..d80081d --- /dev/null +++ b/project2/web/WEB-INF/web.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/project2/web/index.jsp b/project2/web/index.jsp new file mode 100644 index 0000000..9bc9f9e --- /dev/null +++ b/project2/web/index.jsp @@ -0,0 +1,16 @@ +<%-- + Created by IntelliJ IDEA. + User: chenx + Date: 6/6/2023 + Time: 8:33 AM + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + $Title$ + + + $END$ + +