SSM框架构建商铺系统01

134 阅读12分钟

前言

总结自慕课网《Java主流技术栈SSM+SpringBoot商铺系统(升级更新)

如有需要请自行去购买。

目前采用的是SSM框架。

一、采用的技术

后端采用:SSM + MySQL + Redis等,并且在阿里云中部署。

后面会进一步更新成SpringBoot框架。

二、环境准备

1、所要用到的技术版本

Java8、Maven3.3.9、MySQL5.8、Tomcat。

2、创建maven项目

选择webapp模块:

image.png

设置以下内容:

image.png

修改pom文件:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.imooc</groupId>
  <artifactId>o2o</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>o2o Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <spring.version>5.1.8.RELEASE</spring.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.2.3</version>
    </dependency>
    <!-- Spring -->
    <!-- 1)包含Spring 框架基本的核心工具类。Spring 其它组件要都要使用到这个包里的类,是其它组件的基本核心 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- 2)这个jar 文件是所有应用都要用到的,它包含访问配置文件、创建和管理bean 以及进行Inversion of Control
      / Dependency Injection(IoC/DI)操作相关的所有类。如果应用只需基本的IoC/DI 支持,引入spring-core.jar
      及spring-beans.jar 文件就可以了。 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- 3)这个jar 文件为Spring 核心提供了大量扩展。可以找到使用Spring ApplicationContext特性时所需的全部类,JDNI
      所需的全部类,instrumentation组件以及校验Validation 方面的相关类。 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- 4) 这个jar 文件包含对Spring 对JDBC 数据访问进行封装的所有类。 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- 5) 为JDBC、Hibernate、JDO、JPA等提供的一致的声明式和编程式事务管理。 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- 6)Spring web 包含Web应用开发时,用到Spring框架时所需的核心类,包括自动载入WebApplicationContext特性的类、Struts与JSF集成类、文件上传的支持类、Filter类和大量工具辅助类。 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- 7)包含SpringMVC框架相关的所有类。 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- 8)Spring test 对JUNIT等测试框架的简单封装 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>${spring.version}</version>
      <scope>test</scope>
    </dependency>
    <!-- Servlet web -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.1</version>
    </dependency>
    <!-- json解析 -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.9.9</version>
    </dependency>
    <!-- Map工具类 对标准java Collection的扩展 spring-core.jar需commons-collections.jar -->
    <dependency>
      <groupId>commons-collections</groupId>
      <artifactId>commons-collections</artifactId>
      <version>3.2.2</version>
    </dependency>
    <!-- DAO: MyBatis -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.5.1</version>
    </dependency>
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>2.0.1</version>
    </dependency>
    <!-- 数据库 -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.16</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.mchange/c3p0 -->
    <dependency>
      <groupId>com.mchange</groupId>
      <artifactId>c3p0</artifactId>
      <version>0.9.5.4</version>
    </dependency>

    <!-- 图片处理 -->
    <!-- https://mvnrepository.com/artifact/net.coobird/thumbnailator -->
    <dependency>
      <groupId>net.coobird</groupId>
      <artifactId>thumbnailator</artifactId>
      <version>0.4.8</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.github.penggle/kaptcha -->
    <dependency>
      <groupId>com.github.penggle</groupId>
      <artifactId>kaptcha</artifactId>
      <version>2.3.2</version>
    </dependency>
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.3.2</version>
    </dependency>
    <!-- redis客户端:Jedis -->
    <dependency>
      <groupId>redis.clients</groupId>
      <artifactId>jedis</artifactId>
      <version>2.9.0</version>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.16.18</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>o2o</finalName>
    <plugins>
      <plugin>
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.6.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <encoding>UTF8</encoding>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

创建相关文件夹:

img

修改web.xml,不再用IDEA生成的老版本了,使用web4.0版本的。

IDEA左侧按CTRL + ALT + SHIFT + S,然后点击facet。

先点击-号去掉原来的,然后+上现在的新版本,如果替换不成功,建议web.xml改成web1.xml生成后再改回来。

img

注意格式变成下面这样就对了:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
</web-app>

运行工程前,首先要设置tomcat:

img img

可以设置欢迎页:

<welcome-file-list>
  <welcome-file>index.html</welcome-file>
</welcome-file-list>

启动测试一下。

三、项目细节

1、系统介绍

前端系统:

image.png

店家系统:

image.png

超级管理员系统:

image.png

2、各个模块细节

实体类的解析:

image.png

区域部分设计:

image.png

创建实体类,看看在com.imooc.o2o包下创建了entity包,用来存放各各个实体类:

1、Area类

package com.imooc.o2o.entity;

import java.util.Date;

/**
 * @author :Oliver
 * @description :
 * @create :2022-08-21 09:05:00
 */
public class Area {
    private Integer areaId;
    private String areaName;
    //权重,区域用来做排序的
    private Integer priority;
    private Date createTime;
    private Date updateTime;

    public Integer getAreaId() {
        return areaId;
    }

    public void setAreaId(Integer areaId) {
        this.areaId = areaId;
    }

    public String getAreaName() {
        return areaName;
    }

    public void setAreaName(String areaName) {
        this.areaName = areaName;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}

创建数据库o2o:

image.png

数据库表tb_area的sql语句:

DROP TABLE IF EXISTS `tb_area`;
CREATE TABLE `tb_area`(
    `area_id` INT(2) NOT NULL AUTO_INCREMENT,
    `area_name` VARCHAR(200) NOT NULL,
    `priority` INT(2) NOT NULL DEFAULT '0',
    `create_time` DATETIME DEFAULT NULL,
    `last_edit_time` DATETIME DEFAULT NULL,
    PRIMARY KEY(`area_id`),
    UNIQUE KEY `UK_AREA`(`area_name`)
)ENGINE=INNODB auto_increment=1 DEFAULT CHARSET=utf8

2、用户信息类

image.png

创建实体类:

package com.imooc.o2o.entity;

import java.util.Date;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 09:22:00
 */
public class PersonInfo {
    private Long userId;
    private String name;
    //头像图片
    private String profileImg;
    private String email;
    private String gender;
    //查看用户是否被禁用
    private Integer enableStatus;
    //1.顾客   2.店家   3.超级管理员
    private Integer userType;
    private Date createTime;
    private Date lastEditTime;

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getProfileImg() {
        return profileImg;
    }

    public void setProfileImg(String profileImg) {
        this.profileImg = profileImg;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Integer getEnableStatus() {
        return enableStatus;
    }

    public void setEnableStatus(Integer enableStatus) {
        this.enableStatus = enableStatus;
    }

    public Integer getUserType() {
        return userType;
    }

    public void setUserType(Integer userType) {
        this.userType = userType;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getLastEditTime() {
        return lastEditTime;
    }

    public void setLastEditTime(Date lastEditTime) {
        this.lastEditTime = lastEditTime;
    }
}

tb_person_info表:

DROP TABLE IF EXISTS `tb_person_info`;
CREATE TABLE `tb_person_info`(
    `user_id` INT(10) NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(32) DEFAULT NULL,
    `profile_img` VARCHAR(1024) DEFAULT NULL,
    `email` VARCHAR(1024) DEFAULT NULL,
    `gender` VARCHAR(2) DEFAULT NULL,
    `enable_status` INT(2) NOT NULL DEFAULT '0' COMMENT '0:禁止使用本商城,1:允许使用本商城',
    `user_type` INT(2) NOT NULL DEFAULT '1' COMMENT '1:顾客,2:店家,3:超级管理员',
    `create_time` DATETIME DEFAULT NULL,
    `last_edit_time` DATETIME DEFAULT NULL,
    PRIMARY KEY(`user_id`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

微信账号类和本地账号类:

image.png

3、微信账号类

package com.imooc.o2o.entity;

import java.util.Date;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 09:44:00
 */
public class WechatAuth {
    private Long wechatAuthId;
    private String openId;
    private Date createTime;
    private PersonInfo personInfo;

    public Long getWechatAuthId() {
        return wechatAuthId;
    }

    public void setWechatAuthId(Long wechatAuthId) {
        this.wechatAuthId = wechatAuthId;
    }

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public PersonInfo getPersonInfo() {
        return personInfo;
    }

    public void setPersonInfo(PersonInfo personInfo) {
        this.personInfo = personInfo;
    }
}

4、本地账号类

package com.imooc.o2o.entity;

import java.util.Date;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 09:45:00
 */
public class LocalAuth {
    private Long localAuthId;
    private String username;
    private String password;
    private Date createTime;
    private Date lastEditTime;
    private PersonInfo personInfo;

    public Long getLocalAuthId() {
        return localAuthId;
    }

    public void setLocalAuthId(Long localAuthId) {
        this.localAuthId = localAuthId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getLastEditTime() {
        return lastEditTime;
    }

    public void setLastEditTime(Date lastEditTime) {
        this.lastEditTime = lastEditTime;
    }

    public PersonInfo getPersonInfo() {
        return personInfo;
    }

    public void setPersonInfo(PersonInfo personInfo) {
        this.personInfo = personInfo;
    }
}

sql语句:

DROP TABLE IF EXISTS `tb_wechat_auth`;
CREATE TABLE `tb_wechat_auth`(
	`wechat_auth_id` INT(10) NOT NULL AUTO_INCREMENT,
	`user_id` INT(10) NOT NULL,
	`open_id` VARCHAR(1024) NOT NULL,
	`create_time` DATETIME DEFAULT NULL,
	PRIMARY KEY(`wechat_auth_id`),
	CONSTRAINT `fk_wechatauth_profile` FOREIGN KEY(`user_id`) REFERENCES `tb_person_info`(`user_id`),
	UNIQUE KEY(`open_id`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `tb_local_auth`;
CREATE TABLE `tb_local_auth`(
	`local_auth_id` INT(10) NOT NULL AUTO_INCREMENT,
	`user_id` INT(10) NOT NULL,
	`username` VARCHAR(128) NOT NULL,
	`password` VARCHAR(128) NOT NULL,
	`create_time` DATETIME DEFAULT NULL,
	`last_edit_time` DATETIME DEFAULT NULL,
	PRIMARY KEY(`local_auth_id`),
	UNIQUE KEY(`local_auth_id`),
	CONSTRAINT `fk_localauth_profile` FOREIGN KEY(`user_id`) REFERENCES `tb_person_info`(`user_id`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

5、头条类

image.png

package com.imooc.o2o.entity;

import java.util.Date;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 10:10:00
 */
public class HeadLine {
    private Long lineId;
    private String lineName;
    private String lineLink;
    private String lineImg;
    private Integer priority;
    //0.不可用  1.可用
    private Integer enableStatus;
    private Date createTime;
    private Date lastEditTime;

    public Long getLineId() {
        return lineId;
    }

    public void setLineId(Long lineId) {
        this.lineId = lineId;
    }

    public String getLineName() {
        return lineName;
    }

    public void setLineName(String lineName) {
        this.lineName = lineName;
    }

    public String getLineLink() {
        return lineLink;
    }

    public void setLineLink(String lineLink) {
        this.lineLink = lineLink;
    }

    public String getLineImg() {
        return lineImg;
    }

    public void setLineImg(String lineImg) {
        this.lineImg = lineImg;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public Integer getEnableStatus() {
        return enableStatus;
    }

    public void setEnableStatus(Integer enableStatus) {
        this.enableStatus = enableStatus;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getLastEditTime() {
        return lastEditTime;
    }

    public void setLastEditTime(Date lastEditTime) {
        this.lastEditTime = lastEditTime;
    }
}

数据库表:

DROP TABLE IF EXISTS `tb_head_line`;
CREATE TABLE `tb_head_line`(
	`line_id` INT(100) NOT NULL AUTO_INCREMENT,
	`line_name` VARCHAR(1000) DEFAULT NULL,
	`line_link` VARCHAR(2000) NOT NULL,
	`line_img` VARCHAR(2000) NOT NULL,
	`priority` INT(2) DEFAULT NULL,
	`enable_status` INT(2) NOT NULL DEFAULT '0',
	`create_time` DATETIME DEFAULT NULL,
	`last_edit_time` DATETIME DEFAULT NULL,
	PRIMARY KEY(`line_id`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

6、店铺类别

image.png

商铺类别类代码:

package com.imooc.o2o.entity;

import java.util.Date;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 10:21:00
 */
public class ShopCategory {
    private Long shopCategoryId;
    private String shopCategoryName;
    private String shopCategoryDesc;
    private String shopCategoryImg;
    private Integer priority;
    private Date createTime;
    private Date lastEditTime;
    private ShopCategory parent;

    public Long getShopCategoryId() {
        return shopCategoryId;
    }

    public void setShopCategoryId(Long shopCategoryId) {
        this.shopCategoryId = shopCategoryId;
    }

    public String getShopCategoryName() {
        return shopCategoryName;
    }

    public void setShopCategoryName(String shopCategoryName) {
        this.shopCategoryName = shopCategoryName;
    }

    public String getShopCategoryDesc() {
        return shopCategoryDesc;
    }

    public void setShopCategoryDesc(String shopCategoryDesc) {
        this.shopCategoryDesc = shopCategoryDesc;
    }

    public String getShopCategoryImg() {
        return shopCategoryImg;
    }

    public void setShopCategoryImg(String shopCategoryImg) {
        this.shopCategoryImg = shopCategoryImg;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getLastEditTime() {
        return lastEditTime;
    }

    public void setLastEditTime(Date lastEditTime) {
        this.lastEditTime = lastEditTime;
    }

    public ShopCategory getParent() {
        return parent;
    }

    public void setParent(ShopCategory parent) {
        this.parent = parent;
    }
}

sql语句:

DROP TABLE IF EXISTS `tb_shop_category`;
CREATE TABLE `tb_shop_category`(
	`shop_category_id` INT(11) NOT NULL AUTO_INCREMENT,
	`shop_category_name` VARCHAR(100) NOT NULL DEFAULT "",
	`shop_category_desc` VARCHAR(1000) DEFAULT "",
	`shop_category_img` VARCHAR(2000) DEFAULT NULL,
	`priority` INT(2) NOT NULL DEFAULT '0',
	`create_time` DATETIME DEFAULT NULL,
	`last_edit_time` DATETIME DEFAULT NULL,
	`parent_id` INT(11) DEFAULT NULL,
	PRIMARY KEY(`shop_category_id`),
	CONSTRAINT `fk_shop_category_self` FOREIGN KEY(`parent_id`) REFERENCES
	`tb_shop_category`(`shop_category_id`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

7、店铺

image.png

代码:

package com.imooc.o2o.entity;

import java.util.Date;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 10:32:00
 */
public class Shop {
    private Long shopId;
    private String shopName;
    private String shopDesc;
    private String shopAddr;
    private String phone;
    private String shopImg;
    private Integer priority;
    private Date createTime;
    private Date lastEditTime;
    //-1.不可用    0.审核中   1.可用
    private Integer enableStatus;
    //超级管理员给店家的提醒
    private String advice;
    private Area area;
    private PersonInfo owner;
    private ShopCategory shopCategory;

    public Long getShopId() {
        return shopId;
    }

    public void setShopId(Long shopId) {
        this.shopId = shopId;
    }

    public String getShopName() {
        return shopName;
    }

    public void setShopName(String shopName) {
        this.shopName = shopName;
    }

    public String getShopDesc() {
        return shopDesc;
    }

    public void setShopDesc(String shopDesc) {
        this.shopDesc = shopDesc;
    }

    public String getShopAddr() {
        return shopAddr;
    }

    public void setShopAddr(String shopAddr) {
        this.shopAddr = shopAddr;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getShopImg() {
        return shopImg;
    }

    public void setShopImg(String shopImg) {
        this.shopImg = shopImg;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getLastEditTime() {
        return lastEditTime;
    }

    public void setLastEditTime(Date lastEditTime) {
        this.lastEditTime = lastEditTime;
    }

    public Integer getEnableStatus() {
        return enableStatus;
    }

    public void setEnableStatus(Integer enableStatus) {
        this.enableStatus = enableStatus;
    }

    public String getAdvice() {
        return advice;
    }

    public void setAdvice(String advice) {
        this.advice = advice;
    }

    public Area getArea() {
        return area;
    }

    public void setArea(Area area) {
        this.area = area;
    }

    public PersonInfo getOwner() {
        return owner;
    }

    public void setOwner(PersonInfo owner) {
        this.owner = owner;
    }

    public ShopCategory getShopCategory() {
        return shopCategory;
    }

    public void setShopCategory(ShopCategory shopCategory) {
        this.shopCategory = shopCategory;
    }
}

sql语句:

CREATE TABLE `tb_shop`(
	`shop_id` INT(10) NOT NULL AUTO_INCREMENT,
	`owner_id` INT(10) NOT NULL COMMENT '店铺创建人',
	`area_id` INT(5) DEFAULT NULL,
	`shop_category_id` INT(11) DEFAULT NULL,
	`shop_name` VARCHAR(255) NOT NULL,
	`shop_desc` VARCHAR(1024) DEFAULT NULL,
	`shop_addr` VARCHAR(200) DEFAULT NULL,
	`phone` VARCHAR(128) DEFAULT NULL,
	`shop_img` VARCHAR(1024) DEFAULT NULL,
	`priority` INT(3) DEFAULT '0',
	`creat_time` DATETIME DEFAULT NULL,
	`last_edit_time` DATETIME DEFAULT NULL,
	`enable_status` INT(2) NOT NULL DEFAULT '0',
	`advice` VARCHAR(255) DEFAULT NULL,
	PRIMARY KEY(`shop_id`),
	CONSTRAINT `fk_shop_area` FOREIGN KEY(`area_id`) REFERENCES `tb_area`(`area_id`),
	CONSTRAINT `fk_shop_profile` FOREIGN KEY(`owner_id`) REFERENCES `tb_person_info`(`user_id`),
	CONSTRAINT `fk_shop_shopcate` FOREIGN KEY(`shop_category_id`) REFERENCES `tb_shop_category`(`shop_category_id`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

8、商品类别

package com.imooc.o2o.entity;

import java.util.Date;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 10:47:00
 */
public class ProductCategory {
    private Long productCategoryId;
    private Long shopId;
    private String productCategoryName;
    private Integer priority;
    private Date createTime;

    public Long getProductCategoryId() {
        return productCategoryId;
    }

    public void setProductCategoryId(Long productCategoryId) {
        this.productCategoryId = productCategoryId;
    }

    public Long getShopId() {
        return shopId;
    }

    public void setShopId(Long shopId) {
        this.shopId = shopId;
    }

    public String getProductCategoryName() {
        return productCategoryName;
    }

    public void setProductCategoryName(String productCategoryName) {
        this.productCategoryName = productCategoryName;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}

sql语句:

CREATE TABLE `tb_product_category`(
	`product_category_id` INT(11) NOT NULL AUTO_INCREMENT,
	`product_category_name` VARCHAR(200) NOT NULL,
	`priority` INT(2) DEFAULT '0',
	`create_time` DATETIME DEFAULT NULL,
	`shop_id` INT(20) NOT NULL DEFAULT '0',
	PRIMARY KEY(`product_category_id`),
	CONSTRAINT `fk_procate_shop` FOREIGN KEY(`shop_id`) REFERENCES `tb_shop`(`shop_id`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

9、商品类

package com.imooc.o2o.entity;

import java.util.Date;
import java.util.List;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 11:02:00
 */
public class Product {
    private Long productId;
    private String productName;
    private String productDesc;
    private String imgAddr;
    private String normalPrice;
    private String promotionPrice;
    private Integer priority;
    private Date createTime;
    private Date lastEditTime;
    //0.下架  1.在前端展示系统展示
    private Integer enableStatus;
    private List<ProductImg> productImgList;
    private Shop shop;

    public Long getProductId() {
        return productId;
    }

    public void setProductId(Long productId) {
        this.productId = productId;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getProductDesc() {
        return productDesc;
    }

    public void setProductDesc(String productDesc) {
        this.productDesc = productDesc;
    }

    public String getImgAddr() {
        return imgAddr;
    }

    public void setImgAddr(String imgAddr) {
        this.imgAddr = imgAddr;
    }

    public String getNormalPrice() {
        return normalPrice;
    }

    public void setNormalPrice(String normalPrice) {
        this.normalPrice = normalPrice;
    }

    public String getPromotionPrice() {
        return promotionPrice;
    }

    public void setPromotionPrice(String promotionPrice) {
        this.promotionPrice = promotionPrice;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getLastEditTime() {
        return lastEditTime;
    }

    public void setLastEditTime(Date lastEditTime) {
        this.lastEditTime = lastEditTime;
    }

    public Integer getEnableStatus() {
        return enableStatus;
    }

    public void setEnableStatus(Integer enableStatus) {
        this.enableStatus = enableStatus;
    }

    public List<ProductImg> getProductImgList() {
        return productImgList;
    }

    public void setProductImgList(List<ProductImg> productImgList) {
        this.productImgList = productImgList;
    }

    public Shop getShop() {
        return shop;
    }

    public void setShop(Shop shop) {
        this.shop = shop;
    }
}

sql语句:

CREATE TABLE `tb_product`(
	`product_id` INT(100) NOT NULL AUTO_INCREMENT,
	`product_name` VARCHAR(100) NOT NULL,
	`product_desc` VARCHAR(2000) DEFAULT NULL,
	`img_addr` VARCHAR(2000) DEFAULT "",
	`normal_price` VARCHAR(100) DEFAULT NULL,
	`promotion_price` VARCHAR(100) DEFAULT NULL,
	`priority` INT(2) NOT NULL DEFAULT '0',
	`create_time` DATETIME DEFAULT NULL,
	`last_edit_time` DATETIME DEFAULT NULL,
	`enable_status` INT(2) NOT NULL DEFAULT '0',
	`product_category_id` INT(11) DEFAULT NULL,
	`shop_id` INT(20) NOT NULL DEFAULT '0',
	PRIMARY KEY(`product_id`),
	CONSTRAINT `fk_product_procate` FOREIGN KEY(`product_category_id`)
	REFERENCES `tb_product_category`(`product_category_id`),
	CONSTRAINT `fk_product_shop` FOREIGN KEY(`shop_id`) REFERENCES 
	`tb_shop`(`shop_id`)
) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

10、商品图片类

package com.imooc.o2o.entity;

import java.util.Date;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 10:55:00
 */
public class ProductImg {
    private Long productImgId;
    private String imgAddr;
    private String imgDesc;
    private Integer priority;
    private Date createTime;
    private Long productId;
    
    public Long getProductImgId() {
        return productImgId;
    }

    public void setProductImgId(Long productImgId) {
        this.productImgId = productImgId;
    }

    public String getImgAddr() {
        return imgAddr;
    }

    public void setImgAddr(String imgAddr) {
        this.imgAddr = imgAddr;
    }

    public String getImgDesc() {
        return imgDesc;
    }

    public void setImgDesc(String imgDesc) {
        this.imgDesc = imgDesc;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Long getProductId() {
        return productId;
    }

    public void setProductId(Long productId) {
        this.productId = productId;
    }
}

sql语句:

CREATE TABLE `tb_product_img`(
	`product_img_id` INT(11) NOT NULL AUTO_INCREMENT,
	`img_addr` VARCHAR(2000) NOT NULL,
	`img_desc` VARCHAR(2000) DEFAULT NULL,
	`priority` INT(2) DEFAULT '0',
	`create_time` DATETIME DEFAULT NULL,
	`product_id` INT(20) DEFAULT NULL,
	PRIMARY KEY(`product_img_id`),
	CONSTRAINT `fk_proimg_product` FOREIGN KEY(`product_id`) REFERENCES `tb_product`(`product_id`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

3、使用git管理项目

github上创建git仓库:

image.png

创建git项目后,会出现让你执行操作的指令:

git init #让git管理本项目,创建.git文件

git add . #把全部文件都上传到git暂存区

git status #查看是否否加进去了,没加进去可以 使用git add xxx文件全路径去添加

git commit -m "first commit" #提交到本地代码库,commit内容是first commit,也可以换成其他的

git branch -M master	#把当前分支命名为master分支

git remote add origin git@github.com:Jaaava/o2o.git	#本地库和远程库关联,这里使用的是SSH方式具体和含义是不想每次提交都写git@github.com:Jaaava/o2o.git作为项目名,这样把这个大长串起个别名origin,以后都用origin即可

git push -u origin master	#git push -u就是指定一个具体的项目的分支,以后可以使用git push直接推送到这里了,origin我们知道是git@github.com:Jaaava/o2o.git的简写,origin master就是这个项目的master分支,这句话就是说我指定了以后推送的分支是origin master,并且推送过去

4、review之前的web内容

image.png

下面这个index.jsp是可以直接访问的,但是WEB-INF下是不能直接访问的,一些不想让别人访问到的内容可以放在这里,web.xml是配置那些javaweb的信息的,比如servlet的配置、别名、位置等等。

另外要想开发还需要以下包:entity、dao、service、web(controller)、dto、enums、interceptor(拦截器)、util。

5、SSM的配置

resource下创建jdbc.properties文件:

jdbc,driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/o2o?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
jdbc.username=root
jdbc.password=xxxxxx

MyBatis相关配置:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>
        <!--使用jdbc的getGeneratedKeys获取数据库自增主键值-->
        <setting name="useGeneratedKeys" value="true"/>

        <!--使用列标签替换列名-->
        <setting name="useColumnLabel" value="true"/>

        <!--开启驼峰命名转换:Table{create_time} -> Entity{createTime}-->
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>
</configuration>

spring-dao.xml文件的配置:

<?xml version="1.0" encoding="UTF-8" ?>
<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"
       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">



    <!-- 配置整合mybatis过程 -->
    <!-- 1.配置数据库相关参数properties的属性:${url} -->
    <!-- 使用数据库配置文件解耦 -->
    <context:property-placeholder location="classpath:jdbc.properties"/>


    <!-- (2)定义数据源(指定连接到哪个数据库) class:数据库连接池(带数据库的连接)作用:解决数据库多次打开和关闭 destroy-method销毁方法-->
    <bean id="dataSource"  class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" >
        <!--详细配置文档-->
        <!--http://commons.apache.org/proper/commons-dbcp/configuration.html-->
        <property name="driverClass" value="${jdbc.driver}" />
        <property name="jdbcUrl" value="${jdbc.url}" />
        <property name="user" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />

        <!-- c3p0连接池的私有属性 -->
        <property name="maxPoolSize" value="30" />
        <property name="minPoolSize" value="10" />
        <!-- 关闭连接后不自动commit -->
        <property name="autoCommitOnClose" value="false" />
        <!-- 获取连接超时时间 -->
        <property name="checkoutTimeout" value="10000" />
        <!-- 当获取连接失败重试次数 -->
        <property name="acquireRetryAttempts" value="2" />
    </bean>

    <!-- 3.配置SqlSessionFactory对象 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 注入数据库连接池 -->
        <property name="dataSource" ref="dataSource"/>
        <!-- 配置MyBaties全局配置文件:mybatis-config.xml -->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
        <!-- 扫描entity包 使用别名 -->
        <property name="typeAliasesPackage" value="com.imooc.o2o.entity"/>
        <!-- 扫描sql配置文件:[====mapper.xml====]所在位置-->
        <property name="mapperLocations" value="classpath:mapper/*.xml"/>
    </bean>

    <!-- 4.配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 注入sqlSessionFactory -->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
        <!-- 给出需要扫描Dao接口包 -->
        <property name="basePackage" value="com.imooc.o2o.dao" />
    </bean>

</beans>

spring-service.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<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.imooc.o2o.service" />

    <!-- 配置事务管理器 -->
    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!-- 注入数据库连接池 -->
        <property name="dataSource" ref="dataSource" />
    </bean>

    <!-- 配置基于注解的声明式事务 -->
    <tx:annotation-driven transaction-manager="transactionManager" />
</beans>

spring-web.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<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-3.2.xsd">
    <!-- 配置SpringMVC -->
    <!-- 1.开启SpringMVC注解模式 -->
    <mvc:annotation-driven />

    <!-- 2.静态资源默认servlet配置 (1)加入对静态资源的处理:js,gif,png (2)允许使用"/"做整体映射 -->
    <mvc:resources mapping="/resources/**" location="/resources/" />
    <mvc:default-servlet-handler />

    <!-- 3.定义视图解析器 -->
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/html/"></property>
        <property name="suffix" value=".html"></property>
    </bean>
    <!-- 文件上传解析器 -->
    <bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding" value="utf-8"></property>
        <!-- 1024 * 1024 * 20 = 20M -->
        <property name="maxUploadSize" value="20971520"></property>
        <property name="maxInMemorySize" value="20971520"></property>
    </bean>

    <!-- 4.扫描web相关的bean -->
    <context:component-scan base-package="com.imooc.o2o.web" />
    <!-- 5.权限拦截器 -->
<!--    <mvc:interceptors>-->
<!--        &lt;!&ndash; 校验是否已登录了店家管理系统的拦截器 &ndash;&gt;-->
<!--        <mvc:interceptor>-->
<!--            <mvc:mapping path="/shopadmin/**" />-->
<!--            <bean id="ShopInterceptor"-->
<!--                  class="com.imooc.o2o.interceptor.shopadmin.ShopLoginInterceptor" />-->
<!--        </mvc:interceptor>-->
<!--        &lt;!&ndash; 校验是否对该店铺有操作权限的拦截器 &ndash;&gt;-->
<!--        <mvc:interceptor>-->
<!--            <mvc:mapping path="/shopadmin/**" />-->
<!--            &lt;!&ndash; shoplist page &ndash;&gt;-->
<!--            <mvc:exclude-mapping path="/shopadmin/shoplist" />-->
<!--            <mvc:exclude-mapping path="/shopadmin/getshoplist" />-->
<!--            &lt;!&ndash; shopregister page &ndash;&gt;-->
<!--            <mvc:exclude-mapping path="/shopadmin/getshopinitinfo" />-->
<!--            <mvc:exclude-mapping path="/shopadmin/registershop" />-->
<!--            <mvc:exclude-mapping path="/shopadmin/shopoperation" />-->
<!--            &lt;!&ndash; shopmanage page &ndash;&gt;-->
<!--            <mvc:exclude-mapping path="/shopadmin/shopmanagement" />-->
<!--            <mvc:exclude-mapping path="/shopadmin/getshopmanagementinfo" />-->
<!--            <bean id="ShopPermissionInterceptor"-->
<!--                  class="com.imooc.o2o.interceptor.shopadmin.ShopPermissionInterceptor" />-->
<!--        </mvc:interceptor>-->
<!--        &lt;!&ndash; 超级管理员系统拦截部分 &ndash;&gt;-->
<!--        <mvc:interceptor>-->
<!--            <mvc:mapping path="/superadmin/**" />-->
<!--            <mvc:exclude-mapping path="/superadmin/login" />-->
<!--            <mvc:exclude-mapping path="/superadmin/logincheck" />-->
<!--            <mvc:exclude-mapping path="/superadmin/main" />-->
<!--            <mvc:exclude-mapping path="/superadmin/top" />-->
<!--            <mvc:exclude-mapping path="/superadmin/clearcache4area" />-->
<!--            <mvc:exclude-mapping path="/superadmin/clearcache4headline" />-->
<!--            <mvc:exclude-mapping path="/superadmin/clearcache4shopcategory" />-->
<!--            <bean id="SuperAdminLoginInterceptor"-->
<!--                  class="com.imooc.o2o.interceptor.superadmin.SuperAdminLoginInterceptor" />-->
<!--        </mvc:interceptor>-->
<!--    </mvc:interceptors>-->
</beans>

另外需要在web.xml文件中进一步配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

    <servlet>
        <servlet-name>spring-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring/spring-*.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

6、Dao

先操作AreaDao:

package com.imooc.o2o.dao;

import com.imooc.o2o.entity.Area;

import java.util.List;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 15:00:00
 */
public interface AreaDao {
    /**
     * 返回区域列表
     * @return  areaList
     */
    List<Area> queryArea();
}

然后先在Idea上连接数据库,点Idea右边的database,然后选择MySQL:

image.png

大部分情况是需要修改时区的找到serverTimezone=UTC

image.png

这样就可以了。

然后创建AreaDao.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.imooc.o2o.dao.AreaDao">
    <select id="queryArea" resultType="com.imooc.o2o.entity.Area">
        
        select area_id,area_name,priority,create_time,last_edit_time
        from tb_area order by priority desc;
        
    </select>
</mapper>

可以在tb_area中添加一些数据,方便查询。

INSERT INTO tb_area (area_name,priority) VALUES("地球",1),("火星",2)

先创建一个基本的BaseDaoTest类:

package com.imooc.o2o;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 15:23:00
 */
@RunWith(SpringJUnit4ClassRunner.class)
//告诉Junit配置文件位置在哪
@ContextConfiguration({"classpath:spring/spring-dao.xml"})
public class BaseTest {
}

AreaDaoTest类:

package com.imooc.o2o.dao;

import com.imooc.o2o.BaseTest;
import com.imooc.o2o.entity.Area;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import static org.junit.Assert.*;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 15:23:00
 */
public class AreaDaoTest extends BaseTest{
    @Autowired
    private AreaDao areaDao;

    @Test
    public void testQueryArea(){
        List<Area> areaList = areaDao.queryArea();
        ;assertEquals(2,areaList.size());
    }
}

7、Service

Service接口:

package com.imooc.o2o.service;

import com.imooc.o2o.entity.Area;

import java.util.List;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 16:00:00
 */
public interface AreaService {
    List<Area> getAreaList();
}

实现类:

package com.imooc.o2o.service.impl;

import com.imooc.o2o.dao.AreaDao;
import com.imooc.o2o.entity.Area;
import com.imooc.o2o.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 16:04:00
 */
@Service
public class AreaServiceImpl implements AreaService {
    @Autowired
    private AreaDao areaDao;

    @Override
    public List<Area> getAreaList() {
        return areaDao.queryArea();
    }
}

测试类,首先修改BaseTest,让它在测试时也加载spring-service文件:

package com.imooc.o2o;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 15:23:00
 */
@RunWith(SpringJUnit4ClassRunner.class)
//告诉Junit配置文件位置在哪
@ContextConfiguration({"classpath:spring/spring-dao.xml","classpath:spring/spring-service.xml"})
public class BaseTest {
}

测试类:

package com.imooc.o2o.service;

import com.imooc.o2o.BaseTest;
import com.imooc.o2o.entity.Area;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import static org.junit.Assert.assertEquals;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 16:11:00
 */
public class AreaServiceTest extends BaseTest{
    @Autowired
    private AreaService areaService;

    @Test
    public void testGetAreaList(){
        List<Area> areaList = areaService.getAreaList();
        assertEquals(areaList.size(),2);
        assertEquals(areaList.get(0).getAreaName(),"望京");
    }
}

8、Controller

AreaController代码如下:

package com.imooc.o2o.web.superadmin;

import com.imooc.o2o.entity.Area;
import com.imooc.o2o.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author :16140
 * @description :
 * @create :2022-08-21 17:17:00
 */
@Controller
@RequestMapping("/superadmin")
public class AreaController {
    @Autowired
    private AreaService areaService;

    @RequestMapping(value = "/listarea",method = RequestMethod.GET)
    @ResponseBody
    private Map<String,Object> listArea(){
        Map<String,Object> modelMap = new HashMap<>();
        List<Area> areaList = new ArrayList<>();
        try {
            areaList = areaService.getAreaList();
            modelMap.put("rows",areaList);
            modelMap.put("total",areaList.size());
        }catch (Exception e){
            e.printStackTrace();
            modelMap.put("success","false");
            modelMap.put("errMsg",e.toString());
        }
        return modelMap;
    }
}

重启项目测试:http://localhost:8080/o2o/superadmin/listarea