单用户登录的实现比较简单,只要在session上动动手脚就行了
单用户登录有两种实现方式
1)当前用户登录验证成功时,如果该用户的账号已经登录,则挤掉已登录的账号,由该用户登录
2)当前用户登录验证成功时,如果该用户的账号已经登录,则提示当前用户该账号已登录,并且不允许当前用户登录
环境
系统:win10
IDE:sts4
springboot2.2.2.RELEASE、 jdk8、 maven3.3.9
挤掉已登录用户
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
server.port=8081
spring.mvc.view.prefix=/templates/
spring.mvc.view.suffix=.html
登录页是Bootstrap框架中的
<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="images/favicon.ico">
<title>Signin Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/signin.css" rel="stylesheet">
</head>
<body class="text-center">
<form class="form-signin" action="/login" method="post">
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
<p style="color:red;" th:text="${failMsg}" th:if="${not #strings.isEmpty(failMsg)}"></p>
<label for="inputEmail" class="sr-only">Email address</