/QuickWeb

Build web application template, integrate Knife4j API documentation, customize error codes, global exception handlers, global logging (implemented using AOP), common response class and Logback logging

Primary LanguageJavaMIT LicenseMIT

English | 简体中文

quick

QuickWeb

Build web application template, integrate Knife4j API documentation, customize error codes, global exception handlers, global logging (implemented using AOP), common response class and Logback logging

Maven Version JDK Version Spring Boot Version Knife4j My Blog

QuickWeb is a web starting project based on SpringBoot that can be used as a template for new projects. It uses MyBatis and MyBatis Plus as the ORM framework, Druid as the data source, MySQL as the database, and Knife4j as the API document generator. Additionally, this project includes features such as custom business exceptions, global logging ( implemented using AOP), global exception handling, common response class, and Logback logging.

📌Technology Stack

  • java 11
  • Spring Boot 2.7.11: A fast development framework that simplifies the process of setting up a Spring application.
  • MyBatis & MyBatis Plus: A persistence framework that provides many convenient interfaces for CRUD operations.
  • Druid: Alibaba's open-source database connection pool and monitoring component.
  • MySQL: Open-source relational database.
  • Knife4j: An API document generation tool based on Swagger.

💪Features

  • Custom business exceptions: throw custom exceptions when business errors occur and catch and handle them through global exception handlers.
  • Global logging (implemented using AOP): Intercept all Controller methods through AOP and record relevant information about requests and responses before and after method execution.
  • Global exception handling: Capture global exceptions and handle them uniformly, returning friendly error messages.
  • Common response class: encapsulates some common response status codes and messages for quick construction of response bodies.
  • Knife4j API documentation generation: Generates API documentation through annotations and configuration, making it easy for developers to view and debug interfaces.

🏁Quick Start

  1. Install MySQL and create a database.

  2. Modify the database connection information in application-dev.yml.

  3. Run the main class MainApplication.

  4. Visit http://localhost:8080/api/doc.html to view the API documentation.

  5. Integrate into your own project

    1. Modify the project name in logback.xml to your own

    2. Modify the database configuration

    3. Modify knife4j configuration (see 🔧Configuration Item Description)

    4. Modify the port number and context-path as needed

📖Configuration File Description

  • application.yml: Application configuration file, including database connection information, log configuration, etc.
  • application-dev.yml: Development application configuration file, including database connection information, log configuration, etc.
  • application-prod.yml: Online application configuration file, including database connection information, log configuration, etc.
  • logback.xml: Logback configuration file, including parameters for logging file records, etc.

🔧Configuration Item Description

Complete configuration items:

knife4j:
  config:
    # Core configuration
    base-package: com.juzi.quickweb.controller
    # Secondary configuration
    title: QuickWeb API Document
    description: Helps to quickly build web applications
    version: 0.0.1
    contact-name: codejuzi
    contact-email: d1741530592@163.com
    contact-url: codejuzi.icu
    license: MIT
    license-url: https://mit-license.org/

🧾Directory Structure Description

.
├── Dockerfile
├── README.md
├── logs
│   └── myapp.log   
├── pom.xml
└── src
    ├── main
    │   ├── java
    │   │   └── com
    │   │       └── juzi
    │   │           └── quickweb
    │   │               ├── MainApplication.java
    │   │               ├── aspect
    │   │               │   └── LogAspect.java              # Controller layer logging AOP
    │   │               ├── common
    │   │               │   ├── BaseResponse.java           # Common response class
    │   │               │   └── StatusCode.java             # Custom status codes
    │   │               ├── configuration
    │   │               │   ├── CorsConfig.java             # Global cross-domain configuration
    │   │               │   ├── DataSourceConfig.java       # Data source configuration
    │   │               │   ├── Knife4jConfig.java
    │   │               │   └── MyBatisPlusConfig.java
    │   │               ├── controller
    │   │               ├── exception
    │   │               │   ├── BusinessException.java      # Custom business exceptions
    │   │               │   └── GlobalExceptionHandler.java # Global exception handler
    │   │               └── util
    │   │                   ├── ResultUtils.java
    │   │                   └── ThrowUtils.java
    │   └── resources
    │       ├── application-dev.yml
    │       ├── application-prod.yml
    │       ├── application.yml
    │       └── logback.xml
    └── test
        └── java
            └── com
                └── juzi
                    └── quickweb
                        └── MainApplicationTest.java

©️Copyright

Open-sourced under the MIT License.