1. 项目背景与技术选型
宠物猫认养系统是一个典型的Web应用,旨在为爱猫人士提供一个线上认养平台。系统采用前后端分离架构,后端基于SpringBoot框架提供RESTful API服务,前端使用Vue3实现用户交互界面,数据持久层采用MyBatis框架与MySQL数据库交互。
为什么选择这个技术栈?SpringBoot的自动配置和起步依赖大大简化了后端开发复杂度,Vue3的Composition API提供了更好的代码组织和复用性,而MyBatis则以其灵活的SQL映射能力著称。这种组合在中小型Web应用中表现出色,既保证了开发效率,又能满足性能需求。
2. 系统架构设计
2.1 整体架构
系统采用经典的三层架构:
- 表现层:Vue3 + Element Plus构建的响应式前端
- 业务逻辑层:SpringBoot实现的核心业务服务
- 数据访问层:MyBatis + MySQL的数据持久化方案
前后端通过HTTP协议通信,数据格式采用JSON。这种分离架构使得前后端可以独立开发、部署和扩展。
2.2 数据库设计
核心数据表包括:
2.2.1 猫咪信息表(cat_info)
sql复制CREATE TABLE `cat_info` (
`cat_id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`age` int DEFAULT NULL,
`gender` tinyint DEFAULT NULL COMMENT '0-母 1-公',
`breed` varchar(50) DEFAULT NULL,
`health_status` varchar(20) DEFAULT NULL,
`description` text,
`avatar_url` varchar(255) DEFAULT NULL,
`is_adopted` tinyint DEFAULT '0' COMMENT '0-未认养 1-已认养',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`cat_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
2.2.2 用户表(user_info)
sql复制CREATE TABLE `user_info` (
`user_id` bigint NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`password` varchar(100) NOT NULL,
`phone` varchar(20) DEFAULT NULL,
`email` varchar(100) DEFAULT NULL,
`address` varchar(255) DEFAULT NULL,
`create_time` datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`user_id`),
UNIQUE KEY `idx_username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
2.2.3 认养记录表(adoption_record)
sql复制CREATE TABLE `adoption_record` (
`record_id` bigint NOT NULL AUTO_INCREMENT,
`cat_id` bigint NOT NULL,
`user_id` bigint NOT NULL,
`adoption_time` datetime DEFAULT CURRENT_TIMESTAMP,
`status` tinyint DEFAULT '0' COMMENT '0-申请中 1-已通过 2-已拒绝',
`remark` varchar(255) DEFAULT NULL,
PRIMARY KEY (`record_id`),
KEY `idx_cat_id` (`cat_id`),
KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
3. 后端实现细节
3.1 SpringBoot配置
核心依赖配置(pom.xml):
xml复制<dependencies>
<!-- SpringBoot Starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- MyBatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-
