This project demonstrates a layered architecture implementation of a user management system using Spring Boot, MyBatis, and H2 database.
src/main/java/com/example/demo/
├── Application.java
├── common/
│ └── exception/
│ └── GlobalExceptionHandler.java
├── model/
│ ├── bo/
│ │ └── user/
│ │ └── UserBO.java
│ ├── po/
│
7632
│ └── user/
│ │ └── UserPO.java
│ └── vo/
│ └── user/
│ └── UserVO.java
├── manager/
│ └── business/
│ └── user/
│ ├── UserManager.java
│ └── UserManagerImpl.java
├── repository/
│ └── mapper/
│ └── UserMapper.java
├── service/
│ └── business/
│ └── user/
│ ├── UserService.java
│ └── UserServiceImpl.java
└── web/
└── user/
├── command/
│ ├── UserCommandController.java
│ ├── UserCreateCommand.java
│ └── UserUpdateCommand.java
└── query/
└── UserQueryController.java
- User CRUD operations
- Layered architecture (Web, Service, Manager, Repository)
- Input validation and error handling
- Swagger API documentation
- H2 in-memory database
- MyBatis ORM integration
- Unit tests
- JDK 11 or later
- Maven 3.6 or later
- Clone the repository
- Navigate to the project directory
- Run
mvn spring-boot:run
- Access the application at http://localhost:8080
- Access Swagger UI at http://localhost:8080/swagger-ui/
mvn test
POST /api/v1/users
- Create a new userPUT /api/v1/users/{id}
- Update an existing userDELETE /api/v1/users/{id}
- Delete a userGET /api/v1/users/{id}
- Get user by IDGET /api/v1/users/username/{username}
- Get user by username
- Web Layer: Controllers handle HTTP requests/responses
- Service Layer: Business logic and transaction management
- Manager Layer: Domain operations and object transformations
- Repository Layer: Database access using MyBatis
The application uses H2 in-memory database with the following schema:
CREATE TABLE users (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
password VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL
);