Integrating Sa-Token-Quick-Login with SpringBoot for Rapid Zero‑Code Login Page Injection
This article explains how to quickly add a secure login page to a simple SpringBoot application using the Sa-Token-Quick-Login plugin, covering Maven dependencies, configuration parameters, controller implementation, and testing steps with code examples.
Sa-Token-Quick-Login provides a zero‑code way to inject a login page into any system, allowing developers to protect publicly exposed pages such as a server performance monitor.
Without authentication, such pages are vulnerable to attacks, so a login mechanism is required.
Normally you would need to write a frontend login page, choose an AJAX library (jQuery, Axios, etc.), select a template engine (JSP, Thymeleaf, FreeMarker, Velocity), implement backend intercept logic, and handle template context paths, which can take days.
Sa-Token-Quick-Login solves this problem by offering a ready‑made solution; the official documentation is at https://sa-token.cc/doc.html#/plugin/quick-login .
SpringBoot Integration
1. Add Maven dependencies
<!-- web support -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Sa-Token-Quick-Login plugin -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-quick-login</artifactId>
<version>1.29.0</version>
</dependency>2. Configure parameters
server:
port: 8080
# Sa-Token-Quick-Login configuration
sa:
# login username
name: admin
# login password
pwd: 123456
# auto‑generate account (if true, name and pwd are ignored)
auto: false
# enable global authentication (disable to stop forced interception)
auth: true
# login page title
title: Asurplus 登录
# show footer copyright
copr: true
# include paths to intercept
include: /**
# exclude paths from interception
exclude: /testTesting
1. Write a controller
@RestController
public class TestController {
/**
* No authentication required
*/
@GetMapping("test")
public String test() {
return "test";
}
/**
* Authentication required
*/
@GetMapping("test1")
public String test1() {
return "test1";
}
}2. Access http://localhost:8080/test
Response is normal.
3. Access http://localhost:8080/test1
The request is intercepted and redirected to the login page because the user is not authenticated.
4. Log in with the configured credentials (admin / 123456)
After successful login, the original request returns the expected response data.
Source: lizhou.blog.csdn.net/article/details/123571910
Note: The author encourages readers to like, follow, share, and collect the article, and mentions a knowledge‑sharing community with additional Spring and micro‑service tutorials.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Code Ape Tech Column
Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
