一、数据源
1)可以使用自己的MySQL数据库;
2)使用我提供的数据。(免费下载)
gmall_report用于可视化的SQL文件-MySQL文档类资源-CSDN下载
二、所需工具
MySQL
IDEA
jdk1.8
Maven
三、项目框架搭建
3.1新建springboot项目
创建springboot项目有二种方式:
1)在IDEA中创建
2)在官网上创建
我喜欢在官网创建
3.1.1进入官网
官网地址(记得收藏):
https://start.spring.io/
3.1.2创建项目
注:
1)注意红色框框的地方,选择你想要的版本和与你的计算机相应的配置;
2)在1.处点击添加相关依赖;
3)在2.处点击生成初始代码并下载。
下面给出我的配置信息:
项目下载后解压,然后用IDEA打开解压后的项目。
我的pom.xml:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.18.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
1)
</project>
4.2配置数据源
1)重命名或者复制,把application.properties变为application.yml
2) 在application.yml中添加内容:
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.17.XXX:3306/gmall_report?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=CONVERT_TO_NULL
username: root
password: 123456
注:要按照实际情况修改内容。
(1)192.168.17.XXX是我的MySQL所在计算机的IP地址,要修改成你的;
(2)3306:是端口号;
(3)gmall_report是用到的数据库名;
(4)root是MySQL的用户名,123456是用户相应的密码;
4.3创建目录结构
按照下图创建你的包,使其目录和下图一样。
4.4后端编写代码
想要从MySQL中提取数据,要编写entity,dao,servier,controller类或者接口,强烈建议一张一张表的编写,方便梳理。
本文用到的表有:goods,ads_area_topic,ads_order_day_count,ads_product_sale_topN,ads_user_action_count
4.4.1entity类
在entity包下面创建java类,如下图;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
@Data
@TableName("ads_area_topic")
public class AreaTopicEntity implements Serializable {
private static final long serialVersionUID = 2L;
@TableId
private String dt;
private String id;
private String provinceName;
private String regionName;
private String orderDayAmount;
private String paymentDayAmount;
private String areaCode;
}
注:
1)ads_area_topic是用到的mysql表名;
2)dt , id, provinceName, regionDayAmouth, orderDayAmount, paymentDayAmount, areaCode;是ads_area_topic表的列名;
(2)GoodEntity
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
@Data
@TableName("goods")
public class GoodEntity implements Serializable {
private static final long serialVersionUID = 1L;
@TableId
private Long id;
private String name;
private Integer num;
}
(3)OrderDayCountEntity
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
@Data
@TableName("ads_order_daycount")
public class OrderDayCountEntity implements Serializable {
private static final Long serialVersionUID = 1L;
@TableId
private String dt;
private String orderCount;
private String orderAmount;
private String orderUsers;
}
(4)ProductSaleTopNEntity
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
@Data
@TableName("ads_product_sale_topN")
public class ProductSaleTopNEntity implements Serializable {
private static final Long serialVersionUID = 1L;
@TableId
private String dt;
private String skuId;
private String paymentAmount;
}
(5)UserActionCountEntity
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import javax.print.DocFlavor;
import java.io.Serializable;
@Data
@TableName("ads_user_action_convert_day")
public class UserActionCountEntity implements Serializable {
private static final Long serialVersionUID = 1L;
@TableField
private String dt;
private String homeCount;
private String goodDetailCount;
private String home2goodDetailConvertRatio;
private String cartCount;
private String goodDetail2cartConvertRatio;
private String orderCount;
private String cart2orderConvertRatio;
private String paymentAmount;
private String order2paymentConvertRatio;
}
4.4.2dao
按照下图在dao包下面创建java接口文件;
(1)AreaTopicDao
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.AreaTopicEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface AreaTopicDao extends BaseMapper<AreaTopicEntity> {
}
(2)GoodDao
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.GoodEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface GoodDao extends BaseMapper<GoodEntity> {
}
(3)OrderDayCountDao
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.OrderDayCountEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface OrderDayCountDao extends BaseMapper<OrderDayCountEntity> {
}
(4)ProductSaleTopNDao
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.ProductSaleTopNEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ProductSaleTopNDao extends BaseMapper<ProductSaleTopNEntity> {
}
(5)UserActionCountDao
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.UserActionCountEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface UserActionCountDao extends BaseMapper<UserActionCountEntity> {
}
文章
10.51W+人气
19粉丝
1关注
©Copyrights 2016-2022 杭州易知微科技有限公司 浙ICP备2021017017号-3 浙公网安备33011002011932号
互联网信息服务业务 合字B2-20220090