# demo-springboot **Repository Path**: devbigapp/demo-springboot ## Basic Information - **Project Name**: demo-springboot - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: demo-用户登录 - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-21 - **Last Updated**: 2025-06-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Spring Boot 用户登录系统 基于Spring Boot + MySQL 5.7实现的简单用户登录系统。 ## 功能特性 - 用户登录 - 用户注册 - RESTful API接口 - 简单的Web登录页面 ## 技术栈 - Spring Boot 2.6.13 - MySQL 5.7 - MyBatis - Gradle ## 快速开始 ### 1. 环境准备 - JDK 1.8+ - MySQL 5.7+ - Gradle 或 IDE ### 2. 数据库配置 1. 启动MySQL服务 2. 执行SQL脚本创建数据库和表: ```sql -- 执行 src/main/resources/sql/init.sql 文件 ``` 3. 修改数据库连接配置(`src/main/resources/application.properties`): ```properties spring.datasource.url=jdbc:mysql://localhost:3306/demo_user?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai spring.datasource.username=你的MySQL用户名 spring.datasource.password=你的MySQL密码 ``` ### 3. 启动应用 ```bash # 使用Gradle ./gradlew bootRun # 或使用IDE直接运行主类 ``` ### 4. 访问应用 - 登录页面:http://localhost:8080/login.html - 注册页面:http://localhost:8080/register.html - API测试:http://localhost:8080/api/user/test ## API文档 ### 用户登录 **接口地址:** `POST /api/user/login` **请求参数:** ```json { "username": "admin", "password": "admin123" } ``` **响应示例:** ```json { "success": true, "message": "登录成功", "user": { "id": 1, "username": "admin", "email": "admin@example.com", "name": "管理员", "age": 30, "createTime": "2024-01-01 10:00:00", "updateTime": "2024-01-01 10:00:00" }, "token": "uuid-token-string" } ``` ### 用户注册 **接口地址:** `POST /api/user/register` **请求参数:** ```json { "username": "newuser", "password": "password123", "email": "newuser@example.com", "name": "新用户", "age": 25 } ``` **响应示例:** ```json { "success": true, "message": "注册成功", "user": { "id": 4, "username": "newuser", "email": "newuser@example.com", "name": "新用户", "age": 25, "createTime": "2024-01-01 10:00:00", "updateTime": "2024-01-01 10:00:00" }, "token": "uuid-token-string" } ``` ### 测试接口 **接口地址:** `GET /api/user/test` **响应:** ``` 用户服务正常运行 ``` ## 测试账号 系统预置了以下测试账号: | 用户名 | 密码 | 邮箱 | 姓名 | |--------|------|------|------| | admin | admin123 | admin@example.com | 管理员 | | user1 | user123 | user1@example.com | 用户1 | | user2 | user123 | user2@example.com | 用户2 | ## 项目结构 ``` src/main/java/com/demo/demospringboot/ ├── DemoSpringbootApplication.java # 应用程序启动类 ├── controller/ # 控制器层 │ └── UserController.java # 用户控制器 ├── service/ # 服务层 │ └── UserService.java # 用户业务逻辑服务 ├── repository/ # 数据访问层 │ └── UserRepository.java # 用户数据访问接口 ├── entity/ # 实体类 │ └── User.java # 用户实体类 └── dto/ # 数据传输对象 ├── LoginRequest.java # 登录请求DTO ├── LoginResponse.java # 登录响应DTO └── RegisterRequest.java # 注册请求DTO src/main/resources/ ├── application.properties # 应用配置文件 ├── sql/init.sql # 数据库初始化脚本 └── static/ # 静态资源 ├── login.html # 登录页面 └── register.html # 注册页面 ``` ## 注意事项 1. 密码在数据库中明文存储,实际项目中应该使用加密存储 2. Token使用UUID生成,实际项目中应该使用JWT等更安全的方式 3. 数据库连接配置需要根据实际情况修改 4. 建议在生产环境中添加更多的安全措施 ## 开发说明 - 使用MyBatis注解方式编写SQL - 采用RESTful API设计规范 - 支持跨域请求 - 包含基本的参数验证