How spricoder/spring-basic works
Purpose and startup
A minimal Spring Boot learning project implementing user-oriented operations with a conventional controller → service → DAO persistence stack. The application starts from src/main/java/com/njuzhy/demo/DemoApplication.java; Maven wrapper files and pom.xml define its Java/Spring runtime.
HTTP/API boundary
src/main/java/com/njuzhy/demo/controller/UserController.java is the inbound web boundary. It accepts user/login request models, delegates business work rather than querying persistence directly, and returns view-oriented user data. Request payload shapes are represented by:
• src/main/java/com/njuzhy/demo/form/LoginForm.java
• src/main/java/com/njuzhy/demo/form/UserForm.java
Application service layer
src/main/java/com/njuzhy/demo/service/UserService.java defines the user-use-case contract, while src/main/java/com/njuzhy/demo/service/UserServiceImpl.java provides its implementation. This is the primary control boundary between HTTP handling and database access, where request data can be validated, transformed, and mapped into response models.
Persistence and SQL mapping
src/main/java/com/njuzhy/demo/dao/UserDao.java is the persistence-facing interface. SQL mapping is externalized in src/main/resources/mapper/UserMapper.xml, indicating a mapper-based ORM/data-access integration (likely MyBatis). The DAO/mapper boundary isolates SQL and database-specific concerns from services.
Domain and transfer models
The persisted user record is modeled by src/main/java/com/njuzhy/demo/data/User.java. API-facing output is separated into src/main/java/com/njuzhy/demo/vo/UserVO.java; inbound forms remain distinct from the domain/data object. Expected flow is:
UserForm / LoginForm → controller → service → UserDao / UserMapper.xml → User, then service/controller → UserVO.
Database and runtime configuration
Database schema/bootstrap SQL is supplied at schema/springbasic.sql. Runtime application and datasource/mapper configuration resides in src/main/resources/application.yml; mapper XML resources are packaged from src/main/resources/mapper/UserMapper.xml. The material external dependency is the relational database configured there, accessed through the mapper layer.
Verification and extension points
Tests mirror the architectural layers: controller tests under src/test/java/com/njuzhy/demo/controller/UserControllerTest.java, service tests under src/test/java/com/njuzhy/demo/service/UserServiceImplTest.java, and DAO tests under src/test/java/com/njuzhy/demo/dao/UserDaoTest.java. New user capabilities should preserve the existing boundary sequence: add request/response models as needed, extend UserService, implement in UserServiceImpl, and add mapper/DAO operations backed by the schema.
Main entry points: UserController.java UserController · UserServiceImpl.java UserServiceImpl · UserMapper.xml UserMapper.xml · DemoApplication.java DemoApplication
Components 13
HTTP API
- UserController · Inbound boundary for user and login operations.
src/main/java/com/njuzhy/demo/controller/UserController.java - UserForm
src/main/java/com/njuzhy/demo/form/UserForm.java - LoginForm
src/main/java/com/njuzhy/demo/form/LoginForm.java - UserVO
src/main/java/com/njuzhy/demo/vo/UserVO.java
Application
- UserService · Defines user use cases.
src/main/java/com/njuzhy/demo/service/UserService.java - UserServiceImpl · Validates and maps between API and persistence models.
src/main/java/com/njuzhy/demo/service/UserServiceImpl.java
Persistence
- UserDao · Persistence-facing user operations.
src/main/java/com/njuzhy/demo/dao/UserDao.java - UserMapper.xml · Externalized SQL mappings for user persistence.
src/main/resources/mapper/UserMapper.xml - User
src/main/java/com/njuzhy/demo/data/User.java - Relational database · Stores user records.
- springbasic.sql · Bootstraps the database schema.
schema/springbasic.sql
Other components
- DemoApplication · Starts the application runtime.
src/main/java/com/njuzhy/demo/DemoApplication.java - application.yml · Configures datasource and mapper resources.
src/main/resources/application.yml
Connections 14
- DemoApplication → UserController: boots web layer
- DemoApplication → application.yml: loads
- application.yml → Relational database: configures datasource
- UserForm → UserController: user request
- LoginForm → UserController: login request
- UserController → UserService: delegates use cases
- UserService → UserServiceImpl: implemented by
- UserServiceImpl → UserDao: accesses persistence
- UserServiceImpl → UserVO: maps response
- UserDao → UserMapper.xml: mapped by
- UserMapper.xml → Relational database: executes SQL
- UserMapper.xml → User: maps records
- springbasic.sql → Relational database: initializes
- UserVO → UserController: returned by