Skip to content

Latest commit

ย 

History

History
229 lines (180 loc) ยท 7.32 KB

File metadata and controls

229 lines (180 loc) ยท 7.32 KB

SpringBoot AI Blog

License Stars Issues PRs Welcome

A personal blog system built with Spring Boot + MyBatis, featuring AI-powered content assistance, Redis caching, and a clean admin dashboard.

English | ็ฎ€ไฝ“ไธญๆ–‡


Features

AI Integration

  • Smart Summary - Auto-generate article summaries via AI
  • Tag Suggestions - AI-recommended tags based on content
  • Article Scoring - Quality assessment with improvement suggestions
  • Smart Search - Keyword extraction and related article recommendations

Content Management

  • Rich Editor - Markdown editor with live preview
  • Draft System - Save unpublished articles as drafts
  • Category & Tags - Flexible content organization
  • Friend Links - Blogroll management
  • Comment System - Valine-based serverless comments
  • Message Board - Visitor guestbook

Admin Dashboard

  • Statistics Overview - Article count, views, tags, categories at a glance
  • AI Status Monitor - Check AI service availability from dashboard
  • Quick Actions - One-click shortcuts for common operations
  • Recent Articles - Latest published posts table

Performance

  • Redis Caching - Accelerated page loading
  • Database Indexing - Optimized query performance
  • HikariCP - High-performance connection pool

Security

  • BCrypt Encryption - Secure password hashing (Spring Security Crypto)
  • SQL Injection Protection - MyBatis parameterized queries
  • Login Interceptor - Admin route protection
  • Input Validation - Bean Validation (JSR-380)

Additional Features

  • SEO Optimization - Sitemap generation, meta tags, structured data
  • Markdown Support - CommonMark parser with GFM tables and heading anchors
  • Exception Monitoring - WeChat Work webhook notifications for system errors
  • Global Exception Handling - Custom error pages with detailed logging
  • AOP Logging - Request/response logging with aspect-oriented programming
  • Scheduled Tasks - Automatic cache refresh and maintenance

Tech Stack

Layer Technology
Framework Spring Boot 2.7.x
ORM MyBatis
Database MySQL 8.0
Cache Redis
Template Engine Thymeleaf
Pagination PageHelper
Password Encryption BCrypt
Connection Pool HikariCP

Quick Start

Prerequisites

  • JDK 8+ (tested with JDK 21)
  • MySQL 5.7+ (recommended MySQL 8.0)
  • Redis 5.0+
  • Maven 3.6+

Installation

  1. Clone the repository
git clone https://github.com/tangredtea/Spring-Blog.git
cd Spring-Blog
  1. Initialize the database
mysql -u root -p < blog.sql
  1. Configure environment variables (recommended)
export DB_USERNAME=root
export DB_PASSWORD=your_password
export REDIS_PASSWORD=your_redis_password  # if applicable
export AI_API_KEY=your_openai_api_key      # optional, for AI features
  1. Run the application
mvn spring-boot:run
  1. Access the application

Docker Compose Deployment

# 1. Copy config
cp .env.example .env

# 2. Edit config
vim .env

# 3. Start all services
docker-compose up -d

Project Structure

Spring-Blog/
โ”œโ”€โ”€ src/main/java/com/blog/
โ”‚   โ”œโ”€โ”€ controller/      # Controllers (admin + frontend + common)
โ”‚   โ”‚   โ”œโ”€โ”€ admin/       # Admin panel controllers
โ”‚   โ”‚   โ”œโ”€โ”€ blog/        # Frontend blog controllers
โ”‚   โ”‚   โ”œโ”€โ”€ common/      # Common controllers
โ”‚   โ”‚   โ””โ”€โ”€ SitemapController.java  # SEO sitemap
โ”‚   โ”œโ”€โ”€ service/         # Business logic & AI services
โ”‚   โ”‚   โ””โ”€โ”€ impl/        # Service implementations
โ”‚   โ”œโ”€โ”€ dao/             # Data access layer (MyBatis mappers)
โ”‚   โ”œโ”€โ”€ entity/          # Entity classes (Blog, User, Tag, etc.)
โ”‚   โ”œโ”€โ”€ pojo/            # Plain Old Java Objects (DTOs)
โ”‚   โ”œโ”€โ”€ config/          # Configuration (Redis, WebMvc, Settings)
โ”‚   โ”œโ”€โ”€ interceptor/     # Login interceptor
โ”‚   โ”œโ”€โ”€ aspect/          # AOP logging
โ”‚   โ”œโ”€โ”€ scheduled/       # Scheduled tasks (cache refresh)
โ”‚   โ”œโ”€โ”€ exception/       # Global exception handling
โ”‚   โ”œโ”€โ”€ enums/           # Enumerations (BlogStatus, etc.)
โ”‚   โ””โ”€โ”€ util/            # Utilities (Password, SEO, Markdown, etc.)
โ”œโ”€โ”€ src/main/resources/
โ”‚   โ”œโ”€โ”€ mapper/          # MyBatis XML mappers
โ”‚   โ”œโ”€โ”€ templates/       # Thymeleaf templates
โ”‚   โ”‚   โ”œโ”€โ”€ admin/       # Admin panel pages
โ”‚   โ”‚   โ”œโ”€โ”€ fragments/   # Reusable fragments
โ”‚   โ”‚   โ””โ”€โ”€ error/       # Error pages (404, 500)
โ”‚   โ”œโ”€โ”€ static/          # Static resources (CSS/JS/images)
โ”‚   โ”‚   โ”œโ”€โ”€ css/         # Stylesheets
โ”‚   โ”‚   โ”œโ”€โ”€ js/          # JavaScript files
โ”‚   โ”‚   โ”œโ”€โ”€ images/      # Images
โ”‚   โ”‚   โ”œโ”€โ”€ fonts/       # Web fonts
โ”‚   โ”‚   โ””โ”€โ”€ lib/         # Third-party libraries
โ”‚   โ”œโ”€โ”€ application.yml  # Main configuration
โ”‚   โ”œโ”€โ”€ application-dev.yml   # Development config
โ”‚   โ”œโ”€โ”€ application-pro.yml   # Production config
โ”‚   โ””โ”€โ”€ messages.properties   # i18n messages
โ”œโ”€โ”€ src/test/            # Unit tests
โ”œโ”€โ”€ blog.sql             # Database schema & seed data
โ”œโ”€โ”€ Dockerfile           # Docker build
โ”œโ”€โ”€ docker-compose.yml   # Docker Compose
โ”œโ”€โ”€ nginx.conf           # Nginx configuration
โ””โ”€โ”€ .env.example         # Environment variables template

Configuration

AI Configuration (Optional)

AI features are optional. To enable them, set the following in application-dev.yml or via environment variables:

ai:
  api:
    key: ${AI_API_KEY:}         # OpenAI API key
    url: ${AI_API_URL:https://api.openai.com/v1/chat/completions}
  model: ${AI_MODEL:gpt-3.5-turbo}

When AI is not configured, the system gracefully falls back to default behavior (no errors).

Site Settings

Edit src/main/resources/messages.properties to customize your blog:

# Basic Info
web_Name=Your Blog Name
web_Description=Your blog description
web_Keywords=Java Blog, Tech Blog

# Social Links
web_Github=https://github.com/yourusername
web_Csdn=https://blog.csdn.net/yourusername

# Comment System (Valine)
valine_AppID=your_leancloud_appid
valine_AppKey=your_leancloud_appkey

# WeChat Work Webhook (Optional - for error notifications)
wx_Webhook=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=your_key
# Set to "0" to disable webhook notifications

Contributing

Contributions are welcome! Feel free to open issues and pull requests.

  1. Fork the repository
  2. Create your branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

Apache License 2.0 - tangredtea