
1. 项目概述134遇见宠爱宠物业务系统是一个基于SpringBootVue微信小程序技术栈开发的综合性宠物服务平台。这个系统主要面向宠物主人、宠物服务商家和宠物爱好者提供一站式的宠物相关服务解决方案。作为全栈开发项目系统采用前后端分离架构后端SpringBoot 2.7.18提供RESTful API管理前端Vue.js构建的响应式Web应用移动端微信小程序作为用户入口2. 技术架构解析2.1 后端技术选型SpringBoot作为后端框架具有以下优势自动配置简化了传统Spring项目的繁琐配置内嵌容器可直接打包成可执行JAR部署便捷丰富的Starter快速集成各种常用组件关键依赖配置示例pom.xmlparent groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-parent/artifactId version2.7.18/version /parent dependencies dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-web/artifactId /dependency !-- MyBatis Plus -- dependency groupIdcom.baomidou/groupId artifactIdmybatis-plus-boot-starter/artifactId version3.5.3.1/version /dependency !-- Redis -- dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-data-redis/artifactId /dependency /dependencies2.2 前端技术选型Vue.js作为管理端框架的优势组件化开发提高代码复用率响应式数据绑定简化DOM操作丰富的生态系统Vue Router、Vuex等配套工具典型项目结构src/ ├── api/ # 接口定义 ├── assets/ # 静态资源 ├── components/ # 公共组件 ├── router/ # 路由配置 ├── store/ # Vuex状态管理 ├── utils/ # 工具函数 └── views/ # 页面组件2.3 微信小程序开发小程序端技术特点双线程架构渲染层与逻辑层分离组件化开发类似Web但有自己的组件体系受限的API环境相比Web有更多限制开发注意事项页面路径需在app.json中显式声明网络请求需配置合法域名页面栈最多10层3. 核心功能实现3.1 用户系统设计采用JWT实现认证授权// SpringBoot中生成JWT的示例 public String generateToken(User user) { return Jwts.builder() .setSubject(user.getUsername()) .setExpiration(new Date(System.currentTimeMillis() EXPIRATION_TIME)) .signWith(SignatureAlgorithm.HS512, SECRET) .compact(); }权限控制方案基于注解的权限校验接口级别细粒度控制数据权限过滤3.2 宠物服务管理核心数据模型设计Entity public class PetService { Id GeneratedValue(strategy GenerationType.IDENTITY) private Long id; private String name; private String description; private BigDecimal price; ManyToOne private ServiceCategory category; // 其他字段和方法... }3.3 预约系统实现状态机设计[待支付] → [已支付] → [服务中] → [已完成] ↓ [已取消]关键代码片段Transactional public Appointment changeStatus(Long id, AppointmentStatus newStatus) { Appointment appointment repository.findById(id).orElseThrow(); if (!appointment.canTransferTo(newStatus)) { throw new IllegalStateException(状态转换不合法); } appointment.setStatus(newStatus); return repository.save(appointment); }4. 前后端交互设计4.1 API规范采用RESTful风格设计GET /api/pets - 获取宠物列表POST /api/pets - 创建宠物GET /api/pets/{id} - 获取特定宠物PUT /api/pets/{id} - 更新宠物DELETE /api/pets/{id} - 删除宠物响应格式统一{ code: 200, message: success, data: {...}, timestamp: 1630000000000 }4.2 文件上传处理SpringBoot处理文件上传PostMapping(/upload) public String handleUpload(RequestParam(file) MultipartFile file) { if (file.isEmpty()) { throw new IllegalArgumentException(请选择文件); } String filename fileStorageService.store(file); return String.format(/files/%s, filename); }微信小程序端上传示例wx.chooseImage({ success(res) { const tempFilePaths res.tempFilePaths wx.uploadFile({ url: https://example.com/api/upload, filePath: tempFilePaths[0], name: file, success(res) { const data JSON.parse(res.data) console.log(data) } }) } })5. 部署与运维5.1 多环境配置SpringBoot多环境支持# application-dev.yml server: port: 8080 spring: datasource: url: jdbc:mysql://localhost:3306/pet_dev username: devuser password: devpass # application-prod.yml server: port: 80 spring: datasource: url: jdbc:mysql://prod-db:3306/pet_prod username: ${DB_USER} password: ${DB_PASS}启动时指定环境java -jar pet-system.jar --spring.profiles.activeprod5.2 微信小程序部署发布流程开发版本开发者工具直接上传体验版本管理后台设置为体验版提交审核准备必要的资质材料正式发布审核通过后发布注意事项域名需备案接口必须HTTPS敏感权限需要申请6. 性能优化实践6.1 缓存策略多级缓存设计本地缓存Caffeine分布式缓存RedisHTTP缓存ETag/Last-Modified配置示例Configuration EnableCaching public class CacheConfig { Bean public CacheManager cacheManager() { CaffeineCacheManager cacheManager new CaffeineCacheManager(); cacheManager.setCaffeine(Caffeine.newBuilder() .expireAfterWrite(10, TimeUnit.MINUTES) .maximumSize(1000)); return cacheManager; } }6.2 数据库优化MyBatis Plus性能优化启用二级缓存合理使用索引避免N1查询问题示例配置mybatis-plus: configuration: cache-enabled: true default-executor-type: reuse log-impl: org.apache.ibatis.logging.stdout.StdOutImpl7. 安全防护措施7.1 常见漏洞防护安全配置示例Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { Override protected void configure(HttpSecurity http) throws Exception { http .csrf().disable() .headers() .xssProtection() .and() .contentSecurityPolicy(default-src self) .and() .authorizeRequests() .antMatchers(/api/**).authenticated() .anyRequest().permitAll(); } }7.2 微信安全机制小程序安全实践敏感数据加密传输接口调用频率限制用户信息脱敏处理完善的日志审计8. 项目总结与扩展8.1 技术难点解决微信支付集成需要处理异步通知签名验证要严格订单状态要幂等实时消息推送采用WebSocket协议心跳机制保持连接离线消息处理8.2 未来扩展方向宠物健康监测接入智能硬件数据社区功能增加用户互动智能推荐基于用户行为的服务推荐多端统一开发App版本在实际开发中最大的挑战是保持三端管理后台、小程序、API的一致性。我们通过Swagger API文档和契约测试来确保接口的稳定性同时建立了完善的前端组件库来提高UI一致性。