|
@@ -1,65 +1,107 @@
|
|
|
-# SSM_template
|
|
|
|
|
|
|
+# SSM_template — 甜蜜时光蛋糕坊
|
|
|
|
|
|
|
|
-SSM框架快速开发模板,整合 Spring + Spring MVC + MyBatis。
|
|
|
|
|
|
|
+基于 Spring + Spring MVC + MyBatis 的蛋糕商城系统。
|
|
|
|
|
|
|
|
## 技术栈
|
|
## 技术栈
|
|
|
|
|
|
|
|
-- **Spring**: 5.3.31
|
|
|
|
|
-- **Spring MVC**: 5.3.31
|
|
|
|
|
-- **MyBatis**: 3.5.6
|
|
|
|
|
-- **Druid**: 1.2.8
|
|
|
|
|
-- **Thymeleaf**: 3.0.12.RELEASE
|
|
|
|
|
-- **MySQL**: 8.0.25
|
|
|
|
|
|
|
+| 层 | 技术 |
|
|
|
|
|
+|---|------|
|
|
|
|
|
+| 前端 | JSP + JSTL + Bootstrap 4.3.1 CDN + jQuery CDN + Font Awesome |
|
|
|
|
|
+| 控制层 | Spring MVC 5.3.31 |
|
|
|
|
|
+| 业务层 | Spring 5.3.31 + @Transactional |
|
|
|
|
|
+| 持久层 | MyBatis 3.5.6 + MyBatis-Spring 2.0.6 |
|
|
|
|
|
+| 连接池 | Druid 1.2.8 |
|
|
|
|
|
+| 数据库 | MySQL 8.0 |
|
|
|
|
|
+| 构建 | Maven (Java 8, war 打包) |
|
|
|
|
|
+| 容器 | Tomcat 7+ |
|
|
|
|
|
|
|
|
-## 项目结构
|
|
|
|
|
|
|
+## 快速开始
|
|
|
|
|
|
|
|
-```
|
|
|
|
|
-SSM_template
|
|
|
|
|
-├── src
|
|
|
|
|
-│ └── main
|
|
|
|
|
-│ ├── java/space/anyi # Java源码
|
|
|
|
|
-│ │ ├── controller/ # 控制层
|
|
|
|
|
-│ │ ├── entity/ # 实体类
|
|
|
|
|
-│ │ └── mapper/ # Mapper接口
|
|
|
|
|
-│ ├── resources/ # 配置文件
|
|
|
|
|
-│ │ ├── mapper/ # MyBatis XML映射文件
|
|
|
|
|
-│ │ ├── spring-*.xml # Spring配置文件
|
|
|
|
|
-│ │ └── jdbc.properties # 数据库配置
|
|
|
|
|
-│ └── webapp/ # Web资源
|
|
|
|
|
-│ └─��� WEB-INF/
|
|
|
|
|
-├── pom.xml
|
|
|
|
|
-└── target/ # 编译输出目录
|
|
|
|
|
-```
|
|
|
|
|
|
|
+### 1. 数据库
|
|
|
|
|
|
|
|
-## 配置说明
|
|
|
|
|
|
|
+执行 `sql/init.sql` 创建数据库 `ssm` 及 21 张表,并插入模拟数据。
|
|
|
|
|
|
|
|
-### 数据库配置
|
|
|
|
|
|
|
+默认管理员:`admin` / `123456`
|
|
|
|
|
+默认用户:`zhangsan` / `123456`、`lisi` / `123456`、`wangwu` / `123456`
|
|
|
|
|
|
|
|
-编辑 `src/main/resources/jdbc.properties`:
|
|
|
|
|
|
|
+### 2. 配置
|
|
|
|
|
|
|
|
-```properties
|
|
|
|
|
-jdbc.driver=com.mysql.cj.jdbc.Driver
|
|
|
|
|
-jdbc.url=jdbc:mysql://localhost:3306/your_database
|
|
|
|
|
-jdbc.username=root
|
|
|
|
|
-jdbc.password=your_password
|
|
|
|
|
-```
|
|
|
|
|
|
|
+编辑 `src/main/resources/jdbc.properties`,修改数据库连接信息。
|
|
|
|
|
|
|
|
-### 运行
|
|
|
|
|
|
|
+### 3. 运行
|
|
|
|
|
|
|
|
```bash
|
|
```bash
|
|
|
-# 打包
|
|
|
|
|
-mvn clean package
|
|
|
|
|
|
|
+mvn compile # 编译
|
|
|
|
|
+mvn clean package # 打包 war
|
|
|
|
|
+mvn tomcat7:run # 开发服务器 → http://localhost:8080/SSM_template
|
|
|
|
|
+mvn test # 运行测试
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
|
|
+## 项目结构
|
|
|
|
|
+
|
|
|
|
|
+```
|
|
|
|
|
+src/main/java/space/anyi/
|
|
|
|
|
+├── controller/
|
|
|
|
|
+│ ├── front/ # 用户端控制器 (10)
|
|
|
|
|
+│ └── admin/ # 管理端控制器 (8)
|
|
|
|
|
+├── entity/ # 实体类 (21) + dto/ (12) + vo/ (12)
|
|
|
|
|
+├── mapper/ # MyBatis Mapper 接口 (21)
|
|
|
|
|
+├── service/ # 业务接口 (19)
|
|
|
|
|
+│ └── impl/ # 业务实现 (18)
|
|
|
|
|
+├── interceptor/ # 登录拦截器 (LoginInterceptor, AdminLoginInterceptor)
|
|
|
|
|
+├── util/ # 工具类 (MD5Util, OrderNoGenerator, Converter)
|
|
|
|
|
+└── constant/ # 常量 (OrderStatus)
|
|
|
|
|
+
|
|
|
|
|
+src/main/resources/
|
|
|
|
|
+├── mapper/ # MyBatis XML 映射文件 (21)
|
|
|
|
|
+├── spring-context.xml # Spring 核心配置
|
|
|
|
|
+├── spring-mvc.xml # Spring MVC 配置
|
|
|
|
|
+├── mybatis-config.xml # MyBatis 配置
|
|
|
|
|
+├── logback.xml # 日志配置
|
|
|
|
|
+└── jdbc.properties # 数据库连接
|
|
|
|
|
|
|
|
-# 部署到Tomcat或直接运行
|
|
|
|
|
-mvn tomcat7:run
|
|
|
|
|
|
|
+src/main/webapp/WEB-INF/views/
|
|
|
|
|
+├── index.jsp
|
|
|
|
|
+├── common/ # header.jsp, footer.jsp
|
|
|
|
|
+├── cake/ # 蛋糕列表、详情、定制
|
|
|
|
|
+├── cart/ # 购物车
|
|
|
|
|
+├── order/ # 订单结算、列表、详情
|
|
|
|
|
+├── user/ # 登录、注册、个人资料、地址管理
|
|
|
|
|
+├── favorite/ # 收藏
|
|
|
|
|
+├── coupon/ # 优惠券
|
|
|
|
|
+├── message/ # 留言
|
|
|
|
|
+├── activity/ # 活动
|
|
|
|
|
+└── admin/ # 后台管理 (16 个 JSP)
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-## 主要配置文件
|
|
|
|
|
|
|
+## 核心配置文件
|
|
|
|
|
|
|
|
| 文件 | 用途 |
|
|
| 文件 | 用途 |
|
|
|
|------|------|
|
|
|------|------|
|
|
|
-| `spring-context.xml` | Spring核心配置 |
|
|
|
|
|
-| `spring-mvc.xml` | Spring MVC配置 |
|
|
|
|
|
-| `mybatis-config.xml` | MyBatis配置 |
|
|
|
|
|
-| `logback.xml` | 日志配置 |
|
|
|
|
|
-| `web.xml` | Web应用配置 |
|
|
|
|
|
|
|
+| `spring-context.xml` | 数据源、MyBatis、事务、AOP |
|
|
|
|
|
+| `spring-mvc.xml` | 控制器扫描、拦截器、视图解析、文件上传 |
|
|
|
|
|
+| `mybatis-config.xml` | 驼峰映射、SQL 日志、二级缓存关闭 |
|
|
|
|
|
+| `logback.xml` | 按级别分离日志 (debug/info/error),滚动策略 |
|
|
|
|
|
+| `web.xml` | DispatcherServlet、编码过滤器 |
|
|
|
|
|
+
|
|
|
|
|
+## 权限控制
|
|
|
|
|
+
|
|
|
|
|
+| 拦截器 | Session Key | 保护路径 | 排除 |
|
|
|
|
|
+|--------|-------------|----------|------|
|
|
|
|
|
+| LoginInterceptor | `user` | `/user/*` `/cart/*` `/order/*` `/favorite/*` `/coupon/*` | `/user/login` `/user/register` |
|
|
|
|
|
+| AdminLoginInterceptor | `admin` | `/admin/**` | `/admin/login` |
|
|
|
|
|
+
|
|
|
|
|
+## 测试
|
|
|
|
|
+
|
|
|
|
|
+测试位于 `src/test/java/space/anyi/`,包含 6 个 Service 测试和 3 个 Mapper 测试。
|
|
|
|
|
+- 基类 `BaseMapperTest` 使用 `spring-test.xml`(独立配置,数据库 `ssm_test`)
|
|
|
|
|
+- `@Transactional` 自动回滚
|
|
|
|
|
+
|
|
|
|
|
+## 注意事项
|
|
|
|
|
+
|
|
|
|
|
+- Java 8 编译目标,war 打包方式
|
|
|
|
|
+- Druid 数据源在 XML 中配置(非 Spring Boot 方式)
|
|
|
|
|
+- 文件上传最大 5MB(CommonsMultipartResolver)
|
|
|
|
|
+- PageHelper 5.3.3 分页插件已启用
|
|
|
|
|
+- MyBatis `mapUnderscoreToCamelCase=true`(数据库下划线 → Java 驼峰)
|
|
|
|
|
+- 图片存储于 `./upload` 目录,路径由 `jdbc.properties` 中的 `upload.path` 配置
|