From a81c31f116e4e29ba3bb5d32a925c488c4e76dfc Mon Sep 17 00:00:00 2001 From: gitee-bot Date: Wed, 29 Apr 2026 03:36:23 +0000 Subject: [PATCH] Add README.md --- README.en.md | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 324 insertions(+) create mode 100644 README.en.md create mode 100644 README.md diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..500a25d --- /dev/null +++ b/README.en.md @@ -0,0 +1,161 @@ +# My Program + +A user management system based on Spring Boot, providing user registration, login, and JWT authentication features. + +## Project Overview + +This project is a lightweight backend user management service developed using the Spring Boot framework, integrating Spring Security and JWT for authentication, and supporting user registration and login functionality. + +## Technology Stack + +- **Framework**: Spring Boot 3.x +- **Security**: Spring Security + JWT +- **Database**: MyBatis +- **Build Tool**: Maven + +## Project Structure + +``` +com.dmw +├── Entity/ # Entity classes +│ ├── DTO/ # Data Transfer Objects +│ ├── User.java # User entity +│ └── VO/ # View Objects +├── ExceptionHandler/ # Exception handling +├── config/ # Configuration classes +├── controller/ # Controllers +├── service/ # Business logic +├── mapper/ # Data access layer +├── filter/ # Filters +└── common/ # Common components + ├── constant/ # Constant definitions + ├── properties/ # Configuration properties + ├── result/ # Unified response format + └── util/ # Utility classes +``` + +## Key Features + +### User Registration +- Supports regular user registration +- Automatically encrypts and stores passwords + +### User Login +- Username and password verification +- Returns a JWT token + +### API Protection +- Regular user endpoints (`/api/user`) +- Admin endpoints (`/api/admin`) require admin role permission + +## Quick Start + +### Environment Requirements + +- JDK 17+ +- Maven 3.6+ + +### Configuration + +Configure database and JWT settings in `application.yml`: + +```yaml +server: + port: 8080 + +spring: + datasource: + url: jdbc:mysql://localhost:3306/your_database + username: your_username + password: your_password + +dmw: + jwt: + user-secret-key: your-secret-key + user-ttl: 3600000 + user-token-name: token +``` + +### Running the Project + +```bash +./mvnw spring-boot:run +``` + +Or using Maven: + +```bash +mvn spring-boot:run +``` + +## API Endpoints + +### User Endpoints + +| Endpoint | Method | Description | Permission | +|----------|--------|-------------|------------| +| `/user/login` | POST | User login | Public | +| `/user/register` | POST | User registration | Public | +| `/api/user` | GET | Regular user access | Logged in | +| `/api/admin` | GET | Admin access | Admin role | + +### Login Request Example + +```json +POST /user/login +{ + "username": "testuser", + "password": "123456" +} +``` + +### Login Response Example + +```json +{ + "code": 1, + "msg": "success", + "data": { + "id": 1, + "username": "testuser", + "role": "user", + "token": "eyJhbGc..." + } +} +``` + +## Unified Response Format + +```json +{ + "code": 1, + "msg": "success", + "data": {} +} +``` + +- `code`: Status code (1 = success) +- `msg`: Message prompt +- `data`: Returned data + +## Additional Notes + +### Adding an Admin User + +Manually insert a user record into the database and set the `role` field to `admin`. + +### Modifying JWT Configuration + +Adjust settings in `application.yml`: + +```yaml +dmw: + jwt: + user-secret-key: your-secret-key + user-ttl: 3600000 # in milliseconds + user-token-name: token +``` + +## License + +This project is for learning and communication purposes only. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..50bcc5a --- /dev/null +++ b/README.md @@ -0,0 +1,163 @@ + + +# 我的程序 (My Program) + +一个基于 Spring Boot 的用户管理系统,提供用户注册、登录和 JWT 认证功能。 + +## 项目简介 + +本项目是一个轻量级的用户管理后端服务,采用 Spring Boot 框架开发,集成了 Spring Security 和 JWT 进行身份认证,支持用户的注册和登录功能。 + +## 技术栈 + +- **框架**: Spring Boot 3.x +- **安全**: Spring Security + JWT +- **数据库**: MyBatis +- **构建工具**: Maven + +## 项目结构 + +``` +com.dmw +├── Entity/ # 实体类 +│ ├── DTO/ # 数据传输对象 +│ ├── User.java # 用户实体 +│ └── VO/ # 视图对象 +├── ExceptionHandler/ # 异常处理 +├── config/ # 配置类 +├── controller/ # 控制器 +├── service/ # 业务逻辑 +├── mapper/ # 数据访问层 +├── filter/ # 过滤器 +└── common/ # 公共组件 + ├── contant/ # 常量定义 + ├── properties/ # 配置属性 + ├── result/ # 统一返回结果 + └── util/ # 工具类 +``` + +## 主要功能 + +### 用户注册 +- 支持普通用户注册 +- 自动加密存储密码 + +### 用户登录 +- 用户名密码验证 +- 返回 JWT Token + +### 接口保护 +- 普通用户接口 (`/api/user`) +- 管理员接口 (`/api/admin`) 需 admin 角色权限 + +## 快速开始 + +### 环境要求 + +- JDK 17+ +- Maven 3.6+ + +### 配置说明 + +在 `application.yml` 中配置数据库和 JWT 相关参数: + +```yaml +server: + port: 8080 + +spring: + datasource: + url: jdbc:mysql://localhost:3306/your_database + username: your_username + password: your_password + +dmw: + jwt: + user-secret-key: your-secret-key + user-ttl: 3600000 + user-token-name: token +``` + +### 运行项目 + +```bash +./mvnw spring-boot:run +``` + +或使用 Maven: + +```bash +mvn spring-boot:run +``` + +## API 接口 + +### 用户接口 + +| 接口 | 方法 | 说明 | 权限 | +|------|------|------|------| +| `/user/login` | POST | 用户登录 | 公开 | +| `/user/register` | POST | 用户注册 | 公开 | +| `/api/user` | GET | 普通用户访问 | 登录 | +| `/api/admin` | GET | 管理员访问 | admin 角色 | + +### 登录请求示例 + +```json +POST /user/login +{ + "username": "testuser", + "password": "123456" +} +``` + +### 登录响应示例 + +```json +{ + "code": 1, + "msg": "success", + "data": { + "id": 1, + "username": "testuser", + "role": "user", + "token": "eyJhbGc..." + } +} +``` + +## 统一返回格式 + +```json +{ + "code": 1, + "msg": "success", + "data": {} +} +``` + +- `code`: 状态码 (1=成功) +- `msg`: 消息提示 +- `data`: 返回数据 + +## 扩展说明 + +### 添加管理员用户 + +在数据库中手动插入用户记录,设置 `role` 为 `admin`。 + +### 修改 JWT 配置 + +可在 `application.yml` 中调整: + +```yaml +dmw: + jwt: + user-secret-key: 你的密钥 + user-ttl: 3600000 # 毫秒 + user-token-name: token +``` + +## 许可证 + +本项目仅供学习交流使用。 \ No newline at end of file -- Gitee