System Overview
The personal blog system described in this guide consists of several key pages: registration, login, article listing, article detail view, article editing, article creation, and user profile management.
Initial Setup
Environment Requirements
- Packet capture tool: Fiddler Classic
- Runtime environment: JDK 1.8, Spring Boot 2.7.8
- Backend development tools: IntelliJ IDEA 2021, MySQL 5.7.x
- Frontend development tools: VS Code (maximum version 1.70.3 for Windows 7)
- Deployment environment: Linux (CentOS 7.6)
Project Configuration
1. Create a new project structure
2. Add necessary dependencies in pom.xml (Spring Web, MyBatis, MySQL, Lombok, Redis, etc.)
3. Import frontend pages and static resources into resources/static/
4. Implement layered architecture (common, config, controller, entity, mapper, service, etc.)
5. Configure application.yml with database connections, MyBatis XML paths, Redis settings, etc.
Database Design
The blog system utilizes three main tables:
- userinfo (id, username, password, photo, createtime, updatetime, state)
- articleinfo (id, title, content, createtime, updatetime, uid, rcount, state)
- commentinfo (id, articleid, uid, content, createtime, replyid, parentid)
After designing the database structure, create the initialization script (db1.sql) for deployment.
Entity Classes
Create corresponding entity classes for each database table with matching attributes.
Unified Response Format and Exception Handling
Implement a standardized response format to ensure consistency between frontend and backend communication. Create a unified response entity class with utility methods for data validation and packaging. Implement centralized exception handling to manage runtime errors gracefully.
Interceptors
Three custom interceptors are implemented:
1. AuthenticationInterceptor: Validates user login status
2. DeduplicationInterceptor: Prevents duplicate requests within short timeframes
3. RateLimitInterceptor: Controls API access frequency per IP
AuthenticationInterceptor
This interceptor checks for user authentication by verifying session existence and user information. Unauthenticated users are redirected to the login page.
DeduplicationInterceptor
Prevents duplicate requests by creating a unique MD5 hash from request parameters and checking Redis for recent identical requests.
RateLimitInterceptor
Implements sliding window algorithm to limit API access frequency per IP. Uses Redis sorted sets for request timestamps and sets for blacklisting IPs that exceed limits.
Core Functionality Implementation
Registration Page
User Registration
The registration endpoint validates input parameters, checks for existing usernames, verifies CAPTCHAs, and implements password salting for security. Rate limiting prevents excessive registration attempts from the same IP.
Password Salting
Passwords are secured using salt-based hashing with random salt generation and MD5 encryption.
Login Page
CAPTCHA Generation
The login page includes CAPTCHA verification with image generation and Redis-based storage with expiration.
User Authentication
Validates user credentials against the database with CAPTCHA verification and implements login attempt limiting to prevent brute force attacks.
Article Listing
User Information Display
Shows current user's profile information including username, avatar, and article count.
Paginated Article List
Displays articles with pagination support, calculating total pages based on article count and page size.
Article Creation
Draft Saving
Allows users to save article drafts with a state flag of -1 to distinguish from published articles.
Article Publishing
Publishes articles by updating the state to 1 and setting the publication timestamp.
Article Editing
Article Retrieval
Fetches article details for editing, including title, content, timestamps, and metadata.
Article Updates
Updates existing articles with new content and timestamps.
Article Detail Page
Article Display
Shows full article content with metadata and increments view count on each access.
Comment System
Implements a two-level comment structure with support for nested replies. Retrieves and displays comments with proper attribution.
Comment Management
Allows users to add, view, and delete comments with validation for content and reply targets.
User Profile Management
Avatar Upload
Enables users to upload and manage profile avatars with file validation and size restrictions.
Article Management
Provides interfaces for viewing, editing, and deleting user's articles with proper authorization checks.
Comment Management
Allows users to view and delete their own comments with proper validation.
Automated Testing
Test Approach
The system implements automated testing using black box testing methodology to verify core functionality across all components.
Test Implementation
Test cases are written using Selenium WebDriver with Java, covering:
- Registration functionality (success and failure scenarios)
- Login process (various validation scenarios)
- Article listing and pagination
- Article creation and editing
- Comment system operations
- User profile management
Test Environment
- Operating System: Windows 7
- Browser: Google Chrome 109.0.5414.120 (64-bit)
- WebDriver: ChromeDriver 109.0.5414.74
- Testing Framework: Selenium 3.141.59
Test Results
The automated test suite executed 119 test cases in 2 minutes and 34 seconds, covering all major system functionalities.
Wait Strategies
Three types of waits are implemented in the test suite:
1. Explicit waits: For specific conditions (element visibility, clickability)
2. Implicit waits: Global timeout settings for element discovery
3. Fluent waits: Customizable wait conditions with polling intervals