up
This commit is contained in:
parent
e80af33075
commit
dac59b9ff0
@ -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";
|
||||
@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";
|
||||
}
|
||||
|
||||
@GetMapping("/logout")
|
||||
public String logout() {
|
||||
// 执行登出操作,清除用户信息或会话信息
|
||||
return "redirect:/admin/login";
|
||||
}
|
||||
}
|
||||
|
@ -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"),
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@
|
||||
<div class="container d-flex align-items-center justify-content-center h-100">
|
||||
<div style="background-color: rgba(255,255,255,0.7);backdrop-filter: blur(30px)"
|
||||
class="rounded-5 shadow-5-strong p-5">
|
||||
<form action="${pageContext.request.contextPath}/admin/login" method="POST">
|
||||
<form action="${pageContext.request.contextPath}/login" method="POST">
|
||||
<h1 class="text-center mb-4" style="font-family: 'Noto Sans SC Light',serif">用户登录</h1>
|
||||
<div class="form-outline mb-4">
|
||||
<input type="text" id="form1Example1" class="form-control" name="username"/>
|
38
project2/.gitignore
vendored
Normal file
38
project2/.gitignore
vendored
Normal file
@ -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
|
8
project2/.idea/.gitignore
vendored
Normal file
8
project2/.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
13
project2/.idea/artifacts/project2_war_exploded.xml
Normal file
13
project2/.idea/artifacts/project2_war_exploded.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="exploded-war" name="project2:war exploded">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/project2_war_exploded</output-path>
|
||||
<root id="root">
|
||||
<element id="javaee-facet-resources" facet="project2/web/Web" />
|
||||
<element id="directory" name="WEB-INF">
|
||||
<element id="directory" name="classes">
|
||||
<element id="module-output" name="project2" />
|
||||
</element>
|
||||
</element>
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
7
project2/.idea/encodings.xml
Normal file
7
project2/.idea/encodings.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
14
project2/.idea/misc.xml
Normal file
14
project2/.idea/misc.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="temurin-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
6
project2/.idea/vcs.xml
Normal file
6
project2/.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
152
project2/pom.xml
Normal file
152
project2/pom.xml
Normal file
@ -0,0 +1,152 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>cyou.chenx221</groupId>
|
||||
<artifactId>project2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>5.3.27</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>5.3.27</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>5.3.27</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
<version>5.3.27</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
<version>5.3.27</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>5.3.27</version>
|
||||
</dependency>
|
||||
<!-- MyBatis -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.5.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
<version>2.0.7</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JSP -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>4.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>javax.servlet.jsp-api</artifactId>
|
||||
<version>2.3.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Tomcat -->
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-core</artifactId>
|
||||
<version>9.0.73</version>
|
||||
</dependency>
|
||||
|
||||
<!-- MySQL Connector -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.28</version>
|
||||
</dependency>
|
||||
|
||||
<!-- log4j -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.20.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.1.20</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper</artifactId>
|
||||
<version>5.3.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jstl</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>taglibs</groupId>
|
||||
<artifactId>standard</artifactId>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
<!--jackson坐标-->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>2.9.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
<!-- 日志工具包 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.10.0</version>
|
||||
</dependency>
|
||||
<!--日志核心包-->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.10.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
6
project2/src/main/resources/applicationContext.xml
Normal file
6
project2/src/main/resources/applicationContext.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
</beans>
|
0
project2/src/main/resources/mybatis-config.xml
Normal file
0
project2/src/main/resources/mybatis-config.xml
Normal file
6
project2/web/WEB-INF/web.xml
Normal file
6
project2/web/WEB-INF/web.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
||||
version="4.0">
|
||||
</web-app>
|
16
project2/web/index.jsp
Normal file
16
project2/web/index.jsp
Normal file
@ -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" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>$Title$</title>
|
||||
</head>
|
||||
<body>
|
||||
$END$
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user