购物商城项目搭建与使用教程

购物商城项目搭建与使用教程

shoppingmall 这是一个购物商城的项目的服务端,仿照的是天猫网,项目主要用到的技术有 springmvc做前端控制和请求转发、spring整合mybatis做数据访问层、数据库使用的是mysql、使用maven对项目进行构建、搭建ftp服务器存储图片和文件静态资源、nginx做ftp上资源的代理、tomcat做web容器。项目目前只要有三种用户,买家、卖家和网站管理员;其中买家可以浏览商城的商品、添加购物车、下单购买商品;卖家开店添加自己的商品、对用户的订单进行处理、发货等,管理员管理整个网站。目前该服务端主要有1.用户模块 、2 .商品分类模块 、3.商品模块 、4.店铺模块、5 购物车模块 、6 .地址模块 、7.订单模块。每一个模块都是以restful的形式对外提供接口使用。 shoppingmall 项目地址: https://gitcode.com/gh_mirrors/sh/shoppingmall

1. 项目的目录结构及介绍

购物商城项目采用 Maven 构建,其目录结构如下:

shoppingmall
│
├── src
│   ├── main
│   │   ├── java
│   │   │   └── com
│   │   │       └── shoppingmall
│   │   │           ├── controller
│   │   │           ├── pojo
│   │   │           ├── service
│   │   │           └── dao
│   │   └── resources
│   │       ├── mapper
│   │       └── spring
│   └── test
│       ├── java
│       └── resources
├── pom.xml
└── README.md
  • src/main/java: 存放项目的 Java 源代码。
  • src/main/resources: 存放项目的资源文件,如 Spring 配置文件、MyBatis 映射文件等。
  • src/test/java: 存放测试代码。
  • pom.xml: Maven 项目的主要配置文件。
  • README.md: 项目说明文件。

2. 项目的启动文件介绍

项目的启动文件为 src/main/java/com/shoppingmall/Application.java,内容如下:

package com.shoppingmall;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

该文件定义了 Spring Boot 应用的入口类,通过调用 SpringApplication.run() 方法启动 Spring Boot 应用。

3. 项目的配置文件介绍

项目的配置文件位于 src/main/resources 目录下,主要包括以下几个文件:

  • application.properties: Spring Boot 应用的配置文件,可以定义各种属性,如数据库连接信息、服务器端口等。
# 数据库配置
spring.datasource.url=jdbc:mysql://localhost:3306/shoppingmall?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# 服务端口
server.port=8080
  • spring/spring-dao.xml: 数据访问层的配置文件,主要定义了数据源和 MyBatis 相关配置。
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- 数据源配置 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <!-- 数据库连接配置 -->
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/shoppingmall?useUnicode=true&characterEncoding=utf-8&useSSL=false" />
        <property name="username" value="root" />
        <property name="password" value="123456" />
    </bean>

    <!-- MyBatis 配置 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="typeAliasesPackage" value="com.shoppingmall.pojo" />
        <property name="mapperLocations" value="classpath:mapper/*.xml" />
    </bean>

    <!-- 扫描 Mapper 接口 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.shoppingmall.dao" />
    </bean>
</beans>
  • spring/spring-service.xml: 服务层的配置文件,主要定义了事务管理和 Service 层的 Bean。
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!-- 扫描 Service 接口 -->
    <context:component-scan base-package="com.shoppingmall.service" />

    <!-- 事务管理 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <!-- 注解事务 -->
    <tx:annotation-driven transaction-manager="transactionManager" />
</beans>
  • spring/spring-mvc.xml: Web 层的配置文件,主要定义了 Spring MVC 的相关配置。
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context.xsd
                           http://www.springframework.org/schema/mvc
                           http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!-- 扫描 Controller -->
    <context:component-scan base-package="com.shoppingmall.controller" />

    <!-- 注解驱动 -->
    <mvc:annotation-driven />

    <!-- 静态资源处理 -->
    <mvc:default-servlet-handler />

    <!-- 视图解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>

以上配置文件是项目运行的基础,确保正确配置后,项目方可正常运行。

shoppingmall 这是一个购物商城的项目的服务端,仿照的是天猫网,项目主要用到的技术有 springmvc做前端控制和请求转发、spring整合mybatis做数据访问层、数据库使用的是mysql、使用maven对项目进行构建、搭建ftp服务器存储图片和文件静态资源、nginx做ftp上资源的代理、tomcat做web容器。项目目前只要有三种用户,买家、卖家和网站管理员;其中买家可以浏览商城的商品、添加购物车、下单购买商品;卖家开店添加自己的商品、对用户的订单进行处理、发货等,管理员管理整个网站。目前该服务端主要有1.用户模块 、2 .商品分类模块 、3.商品模块 、4.店铺模块、5 购物车模块 、6 .地址模块 、7.订单模块。每一个模块都是以restful的形式对外提供接口使用。 shoppingmall 项目地址: https://gitcode.com/gh_mirrors/sh/shoppingmall

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

余伊日Estra

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值