1. 项目背景与环境搭建必要性第一次接触苍穹外卖这类餐饮管理系统时很多新手开发者容易陷入直接写代码的误区。去年我带团队重构某连锁餐厅订单系统时就吃过亏——当时没统一开发环境导致后期联调时出现数据库版本冲突、接口文档缺失等连环问题。这个项目我们将采用标准化开发流程从零搭建可协作的工程环境。现代软件开发早已不是单兵作战需要同时考虑环境隔离开发、测试、生产环境独立配置团队协作Git版本控制规范化接口文档效率工具自动生成文档的Swagger框架以苍穹外卖为例其技术栈分为前端管理端采用VueElementUI用户端使用微信小程序后端SpringBootMyBatisPlusMySQL辅助工具Nginx反向代理、Knife4j接口文档2. 开发环境搭建实战2.1 前端环境配置管理端和用户端分别需要不同的运行环境# 管理端依赖安装 npm install -g vue/cli vue create admin-web cd admin-web npm run serve # 小程序开发工具 需下载微信开发者工具导入项目时选择dist/build目录常见踩坑点Node版本建议16.x最新版可能不兼容老项目小程序开发需要配置合法域名后期联调时需要Nginx配置注意worker_processes数量建议等于CPU核心数2.2 后端工程结构解析采用Maven多模块设计这是我优化过的结构sky-take-out ├── sky-common # 公共模块 │ ├── constant # 常量类 │ ├── utils # 工具包 ├── sky-pojo # 数据模型 │ ├── entity # 数据库映射 │ ├── dto # 数据传输对象 ├── sky-server # 业务模块 │ ├── config # 配置类 │ ├── interceptor # 拦截器关键配置技巧父pom.xml中锁定SpringBoot版本parent groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-parent/artifactId version2.7.0/version /parent数据库连接池建议配置spring: datasource: hikari: maximum-pool-size: 20 connection-timeout: 300003. 接口文档管理进阶3.1 Swagger与Knife4j整合传统接口文档的三大痛点维护不及时格式不统一测试不方便Knife4j的配置步骤添加依赖dependency groupIdcom.github.xiaoymin/groupId artifactIdknife4j-spring-boot-starter/artifactId version3.0.3/version /dependency配置Docket BeanBean public Docket createRestApi() { return new Docket(DocumentationType.OAS_30) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage(com.sky.controller)) .paths(PathSelectors.any()) .build(); }调试技巧使用ApiOperation注解描述接口通过ApiModelProperty标注字段说明开启生产环境屏蔽knife4j.productiontrue3.2 接口版本管理方案推荐两种实践方式方案一路径版本控制/api/v1/user/create /api/v2/user/create方案二Header版本控制GET /api/user/create X-API-Version: 1.0在苍穹外卖中我们采用Swagger的Group分组功能实现多版本文档共存// V1版本配置 Bean public Docket v1Api() { return new Docket(DocumentationType.OAS_30) .groupName(1.0版本) .apiInfo(v1Info()) .select() .apis(input - { ApiVersion apiVersion input.getHandlerMethod() .getMethodAnnotation(ApiVersion.class); return apiVersion ! null apiVersion.value().equals(1.0); }) .build(); }4. 开发协作规范4.1 Git分支策略采用改良版Git Flowmain - 生产环境代码 release/* - 预发布分支 feature/* - 功能开发分支 hotfix/* - 紧急修复分支实操命令# 新建功能分支 git checkout -b feature/user_login # 合并到release分支 git checkout release/1.0 git merge --no-ff feature/user_login4.2 数据库变更管理使用Flyway进行版本化迁移添加依赖dependency groupIdorg.flywaydb/groupId artifactIdflyway-core/artifactId /dependency创建SQL文件resources/db/migration/ ├── V1__Initial_schema.sql ├── V2__Add_user_table.sql注意事项文件名必须遵循V版本号双下划线描述.sql已执行的迁移文件不可修改生产环境建议开启验证flyway.validate-on-migratetrue5. 联调与部署优化5.1 Nginx高级配置反向代理配置示例server { listen 80; server_name api.takeout.com; location /admin/ { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; } location /miniapp/ { proxy_pass http://127.0.0.1:8081; } }性能调优参数worker_processes auto; events { worker_connections 1024; multi_accept on; } http { keepalive_timeout 65; gzip on; gzip_types text/plain application/json; }5.2 安全加固措施密码加密存储// 使用Spring Security的BCrypt String encodedPwd new BCryptPasswordEncoder().encode(rawPassword);接口权限控制PreAuthorize(hasAuthority(admin)) PostMapping(/employee) public Result addEmployee(RequestBody EmployeeDTO dto) { // ... }XSS防护配置Configuration public class WebSecurityConfig extends WebSecurityConfigurerAdapter { Override protected void configure(HttpSecurity http) throws Exception { http.headers() .xssProtection() .and() .contentSecurityPolicy(script-src self); } }在完成基础环境搭建后建议先用Postman测试核心接口链路。我通常会创建测试集合共享给团队包含用户登录鉴权菜品分页查询购物车操作订单创建流程每个接口测试用例应该包含正常场景参数边界情况错误码验证
苍穹外卖-项目启航:从零搭建开发环境与接口文档管理
1. 项目背景与环境搭建必要性第一次接触苍穹外卖这类餐饮管理系统时很多新手开发者容易陷入直接写代码的误区。去年我带团队重构某连锁餐厅订单系统时就吃过亏——当时没统一开发环境导致后期联调时出现数据库版本冲突、接口文档缺失等连环问题。这个项目我们将采用标准化开发流程从零搭建可协作的工程环境。现代软件开发早已不是单兵作战需要同时考虑环境隔离开发、测试、生产环境独立配置团队协作Git版本控制规范化接口文档效率工具自动生成文档的Swagger框架以苍穹外卖为例其技术栈分为前端管理端采用VueElementUI用户端使用微信小程序后端SpringBootMyBatisPlusMySQL辅助工具Nginx反向代理、Knife4j接口文档2. 开发环境搭建实战2.1 前端环境配置管理端和用户端分别需要不同的运行环境# 管理端依赖安装 npm install -g vue/cli vue create admin-web cd admin-web npm run serve # 小程序开发工具 需下载微信开发者工具导入项目时选择dist/build目录常见踩坑点Node版本建议16.x最新版可能不兼容老项目小程序开发需要配置合法域名后期联调时需要Nginx配置注意worker_processes数量建议等于CPU核心数2.2 后端工程结构解析采用Maven多模块设计这是我优化过的结构sky-take-out ├── sky-common # 公共模块 │ ├── constant # 常量类 │ ├── utils # 工具包 ├── sky-pojo # 数据模型 │ ├── entity # 数据库映射 │ ├── dto # 数据传输对象 ├── sky-server # 业务模块 │ ├── config # 配置类 │ ├── interceptor # 拦截器关键配置技巧父pom.xml中锁定SpringBoot版本parent groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-parent/artifactId version2.7.0/version /parent数据库连接池建议配置spring: datasource: hikari: maximum-pool-size: 20 connection-timeout: 300003. 接口文档管理进阶3.1 Swagger与Knife4j整合传统接口文档的三大痛点维护不及时格式不统一测试不方便Knife4j的配置步骤添加依赖dependency groupIdcom.github.xiaoymin/groupId artifactIdknife4j-spring-boot-starter/artifactId version3.0.3/version /dependency配置Docket BeanBean public Docket createRestApi() { return new Docket(DocumentationType.OAS_30) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage(com.sky.controller)) .paths(PathSelectors.any()) .build(); }调试技巧使用ApiOperation注解描述接口通过ApiModelProperty标注字段说明开启生产环境屏蔽knife4j.productiontrue3.2 接口版本管理方案推荐两种实践方式方案一路径版本控制/api/v1/user/create /api/v2/user/create方案二Header版本控制GET /api/user/create X-API-Version: 1.0在苍穹外卖中我们采用Swagger的Group分组功能实现多版本文档共存// V1版本配置 Bean public Docket v1Api() { return new Docket(DocumentationType.OAS_30) .groupName(1.0版本) .apiInfo(v1Info()) .select() .apis(input - { ApiVersion apiVersion input.getHandlerMethod() .getMethodAnnotation(ApiVersion.class); return apiVersion ! null apiVersion.value().equals(1.0); }) .build(); }4. 开发协作规范4.1 Git分支策略采用改良版Git Flowmain - 生产环境代码 release/* - 预发布分支 feature/* - 功能开发分支 hotfix/* - 紧急修复分支实操命令# 新建功能分支 git checkout -b feature/user_login # 合并到release分支 git checkout release/1.0 git merge --no-ff feature/user_login4.2 数据库变更管理使用Flyway进行版本化迁移添加依赖dependency groupIdorg.flywaydb/groupId artifactIdflyway-core/artifactId /dependency创建SQL文件resources/db/migration/ ├── V1__Initial_schema.sql ├── V2__Add_user_table.sql注意事项文件名必须遵循V版本号双下划线描述.sql已执行的迁移文件不可修改生产环境建议开启验证flyway.validate-on-migratetrue5. 联调与部署优化5.1 Nginx高级配置反向代理配置示例server { listen 80; server_name api.takeout.com; location /admin/ { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; } location /miniapp/ { proxy_pass http://127.0.0.1:8081; } }性能调优参数worker_processes auto; events { worker_connections 1024; multi_accept on; } http { keepalive_timeout 65; gzip on; gzip_types text/plain application/json; }5.2 安全加固措施密码加密存储// 使用Spring Security的BCrypt String encodedPwd new BCryptPasswordEncoder().encode(rawPassword);接口权限控制PreAuthorize(hasAuthority(admin)) PostMapping(/employee) public Result addEmployee(RequestBody EmployeeDTO dto) { // ... }XSS防护配置Configuration public class WebSecurityConfig extends WebSecurityConfigurerAdapter { Override protected void configure(HttpSecurity http) throws Exception { http.headers() .xssProtection() .and() .contentSecurityPolicy(script-src self); } }在完成基础环境搭建后建议先用Postman测试核心接口链路。我通常会创建测试集合共享给团队包含用户登录鉴权菜品分页查询购物车操作订单创建流程每个接口测试用例应该包含正常场景参数边界情况错误码验证