An open API service indexing awesome lists of open source software.

https://github.com/yoyocraft/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
https://github.com/yoyocraft/quickweb

java11 knife4j maven spring-boot web

Last synced: 5 months ago
JSON representation

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

Awesome Lists containing this project

README

          


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](#๐Ÿ”ง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:

```yaml
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.