中文说明请见这里 (Chinese README here)
This project is a user management system based on Spring Boot 3, supporting user registration, login, information management, role-based access control, and data export. The backend uses PostgreSQL as the main database and Redis for caching and distributed scenarios. JWT is used for stateless authentication and role-based authorization.
- Java 17
- Spring Boot 3.5.4
- MyBatis
- PostgreSQL 17.x
- Redis
- Spring Security
- EasyExcel (Alibaba Excel export)
- Lombok
- JJWT (JWT token)
- Maven 3.9.x
src/
main/
java/com/bryan/system/
config/ # Configuration classes (security, Redis, MyBatis-Plus, etc.)
controller/ # RESTful controllers
domain/ # Entities, request/response objects, VO
filter/ # JWT authentication filter
handler/ # MyBatis auto-fill, global exception handler
mapper/ # MyBatis mapper interfaces
service/ # Service layer
util/ # Utility classes (JWT, HTTP, etc.)
resources/
application.yaml
application-dev.yaml
mapper/ # MyBatis mapper xmls
sql/ # Database schema scripts
test/
java/com/bryan/system/
UserSystemApplicationTests.java
- JDK 17+
- Maven 3.9.9+
- PostgreSQL 17.x
- Redis 6.x or above
- Update database and Redis settings in
src/main/resources/application-dev.yaml
. - General settings (logging, MyBatis-Plus logic delete, etc.) are in
src/main/resources/application.yaml
. - Database schema scripts are in
src/main/resources/sql/create_table.sql
.
-
Initialize the PostgreSQL database by running the schema script:
psql -U postgres -d postgres -f src/main/resources/sql/create_table.sql
-
Start the Redis service.
-
Build and run the project with Maven:
./mvnw spring-boot:run
Or run the packaged jar:
mvn clean package java -jar target/user-system-0.0.1-SNAPSHOT.jar
This project supports containerized deployment with Docker and Docker Compose.
Make sure you have Docker and Docker Compose installed, then build the JAR:
mvn clean package -DskipTests
In the project root, create a file named Dockerfile
:
# Use official OpenJDK 17 as base image
FROM eclipse-temurin:17-jdk-alpine
# Set working directory
WORKDIR /app
# Copy the built jar into container
COPY target/user-system-0.0.1-SNAPSHOT.jar app.jar
# Expose default Spring Boot port
EXPOSE 8080
# Start the application
ENTRYPOINT ["java", "-jar", "app.jar"]
In the project root, create docker-compose.yml
:
version: "3.9"
services:
postgres:
image: postgres:17
container_name: user-postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: user_system
volumes:
- postgres_data:/var/lib/postgresql/data
- ./src/main/resources/sql/create_table.sql:/docker-entrypoint-initdb.d/create_table.sql
ports:
- "5432:5432"
redis:
image: redis:6
container_name: user-redis
ports:
- "6379:6379"
app:
build: .
container_name: user-system
depends_on:
- postgres
- redis
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/user_system
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: postgres
SPRING_REDIS_HOST: redis
SPRING_REDIS_PORT: 6379
ports:
- "8080:8080"
volumes:
postgres_data:
Edit src/main/resources/application-dev.yaml
to use container hostnames instead of localhost
:
spring:
datasource:
url: jdbc:postgresql://postgres:5432/user_system
username: postgres
password: postgres
redis:
host: redis
port: 6379
Run the following command to build and start all services:
docker-compose up -d --build
- Application API: http://localhost:8080/api
- PostgreSQL:
localhost:5432
(user:postgres
, password:postgres
) - Redis:
localhost:6379
- User registration:
POST /api/auth/register
- User login:
POST /api/auth/login
- Get all users:
GET /api/user/all
(admin only) - Search users:
POST /api/user/search
- User update, role change, password update, ban/unban, logical delete, etc. are detailed in
UserController
- Export user data:
GET /api/user/export/all
,POST /api/user/export/field
(admin only)
- For production, inject JWT secret via configuration file instead of hardcoding.
- Global exception handling is in
GlobalExceptionHandler
. - Logical delete field is
deleted
: 0 means active, 1 means deleted.
This project is licensed under the MIT License. See LICENSE for details.