# ai_coding **Repository Path**: shaoyn/ai_coding ## Basic Information - **Project Name**: ai_coding - **Description**: No description available - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-11 - **Last Updated**: 2026-08-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ai_coding A Spring Boot web project with MyBatis-Plus, Sa-Token authentication and Redis caching, providing a complete example of user login and authorized access control. ## Technology Stack | Category | Technology | Version | | --------- | --------------------------------------- | -------- | | Framework | Spring Boot | 2.7.18 | | JDK | OpenJDK | 8 / 21 | | ORM | MyBatis-Plus | 3.5.5 | | Auth | Sa-Token | 1.37.0 | | Database | MySQL | 8.0 | | Cache | Redis (Lettuce pool) | 6.0+ | | Frontend | Thymeleaf + HTML + CSS + Vanilla JS | — | | Security | BCrypt (Spring Security Crypto) | — | | Build | Maven | 3.9+ | ## Project Structure ``` src/main/java/com/example/demo/ ├── DemoApplication.java # Bootstrap + auto-create db/table ├── config/ │ ├── AppStartupRunner.java # Create admin user on first start │ └── SaTokenConfig.java # Sa-Token route interceptor ├── controller/ │ ├── HealthController.java # Health check /health │ └── LoginController.java # Login / Home / Logout ├── entity/ │ └── User.java # User entity (t_user) ├── mapper/ │ └── UserMapper.java # MyBatis-Plus BaseMapper └── service/ └── UserService.java # BCrypt verify + Sa-Token login src/main/resources/ ├── application.yml # Main config (MySQL / Redis / Sa-Token) ├── templates/ │ ├── login.html # Login page │ └── home.html # Home page (authenticated) ├── static/ │ ├── css/login.css # Login page styles │ └── js/login.js # Client-side login (fetch API) └── sql/ └── schema.sql # DDL reference ``` ## Quick Start ### Requirements - JDK 8 or 21 - Maven 3.9+ - MySQL 8.0 running on localhost:3306 - Redis 6.0+ running on 127.0.0.1:6379 ### Database Setup On first startup the application auto-creates the `ai_coding` database, the `t_user` table and a default admin account: - **Username**: admin - **Password**: admin123 ### Launch ```bash # Build mvn clean package -DskipTests # Run java -jar target/demo-0.0.1-SNAPSHOT.jar ``` Visit: http://localhost:8080/login ### API | Method | Path | Description | | ------ | ------------- | -------------------------------------------- | | GET | `/login` | Login page | | POST | `/api/login` | Login `{username, password}` | | GET | `/home` | Home (protected by Sa-Token interceptor) | | GET | `/api/logout` | Logout | | GET | `/health` | Health check (no auth required) | ### Authentication Flow ```text ┌──────────┐ POST /api/login ┌──────────┐ StpUtil.login() ┌───────┐ │ Browser │ ─────────────────→ │ Backend │ ─────────────────→ │ Redis │ │ login.js │ ←────── token ──────│ BCrypt │ ←────── ok ────────│ Token │ └──────────┘ Cookie: satoken └──────────┘ └───────┘ │ ▼ Visit /home With satoken cookie → SaInterceptor.checkLogin → Read Redis token ``` ## Development Conventions ### Package Convention - `controller` — HTTP endpoints returning views or JSON. No business logic. - `service` — Business logic layer. May call multiple mappers. - `mapper` — Data access. Must extend `BaseMapper`. No XML. - `entity` — Entity classes annotated with `@TableName`. snake_case → camelCase mapping. - `config` — Only `@Configuration` classes and startup runners. ### Database Convention - Table names prefixed with `t_` (enforced by `table-prefix: t_`) - Primary key: `id INT AUTO_INCREMENT` - Timestamp columns: `create_time DATETIME DEFAULT CURRENT_TIMESTAMP` - Default charset: `utf8mb4` ### Dependency Management - Pin third-party library versions in `pom.xml` - No SNAPSHOT versions - Prefer Spring Boot Parent–managed dependencies ### Git Convention - `master` branch for stable releases only - `dev` branch for active development - Follow [Conventional Commits](https://www.conventionalcommits.org/) ### Security - Never log credentials (database, Redis) - Passwords stored BCrypt-hashed, never plain-text - Do not reuse expired auth tokens ## License MIT