# example **Repository Path**: li_juejie/example ## Basic Information - **Project Name**: example - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-21 - **Last Updated**: 2026-07-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # server-example 单体应用模板 从微服务拆解而成的单体应用模板示例,展示统一分层架构: **Controller → Manager → Service → Mapper**,配套 common 基础设施(统一响应 `Result`、全局异常、Jackson/Web/MyBatis 配置、Redisson、分页/通用 VO 等)。 ## 环境要求 - **JDK 21** - Maven 3.9+ - MySQL 8(库名 `lemonpig_cloud`) - Redis ## 初始化数据库 1. 在 MySQL 创建库:`CREATE DATABASE IF NOT EXISTS lemonpig_cloud DEFAULT CHARSET utf8mb4;` 2. 执行 `src/main/resources/schema.sql` 建 `example` 表(脚本为 `CREATE TABLE IF NOT EXISTS`,可安全重复执行)。 ## 配置数据源密码 `src/main/resources/application.yml` 中 `spring.datasource.password` 默认为空。请按本地 MySQL 的 root 密码修改后再启动。 > 另:JDBC URL 使用 `characterEncoding=UTF-8`(Java charset 名),不要用 MySQL 的 `utf8mb4`,否则 mysql-connector-j 9.x 启动报 `UnsupportedEncodingException`。 ## 构建与运行 切换到 JDK 21 后: ```bash mvn -gs clean compile # 编译 mvn -gs test # 运行测试(ExampleControllerTest) mvn -gs spring-boot:run # 启动(默认端口 10003) ``` ## Profile 由 Maven `` 动态管理,`application.yml` 用 `@profiles.active@` 占位: - `dev`(默认)/ `test` / `prod` - 切换:`mvn -P prod spring-boot:run` ## 示例接口 | 方法 | 路径 | 说明 | |---|---|---| | GET | `/api/example/{id}` | 示例查询,返回统一 `Result` | | GET | `/actuator/health` | 健康检查 | ## 分层示例(Example) ``` controller/api/ExampleController 入口,GET /api/example/{id} → provider/manager/ExampleManager 业务编排(PO→VO 转换) → provider/service/ExampleService 单表领域服务(继承 MyBatis-Plus IService) → provider/mapper/ExampleMapper 数据访问(继承 CommonMapper) ``` ## 目录结构 ``` com.superstone.example ├── ServerPsApplication 启动类 ├── common 基础设施(config/core/entity/enums/exception/...) ├── controller/api Controller 层 └── provider 业务层(manager/service/mapper/entity) ```