艾编程架构课程第二十七、八节笔记未完待续
分布式系统架构搭建
业务架构: 电商系统
- 用户访问量大
- 过程数据大
- 并发高,极端场景丰富
- 涉及网络安全内容比较多
应用架构
- 用户系统
- 产品系统
- ERP系统
- 订单系统
- 报表系统
技术架构
- vue+分布式
- springCloud
- mybatis-plus
- maven
- git
- MySQL
- redis
- ElasticSearch
- FastDFs
- MQ
- nginx
- SSO
- Dubbo
- zookeeper
- Docker
数据架构
1、系统技术栈及工程规划
将整个系统基于模块化开发,拆分成为各个业务模块,为后续的分布式微服务调用做基础
代码托管至
GitHub:
1.1. 基础模块
1.1.1. im-parent
依赖包管理模块
该模块主要对系统中所有使用到的依赖包进行管理,作为系统所有工程的父级依赖及依赖包版本管理工具
创建:以Module形式的maven工程
创建的Module不是Maven项目可以在项目的POM文件上鼠标右键将其设置为maven项目
im-parent模块需要做的事情
- 将springboot的父依赖放入
- 将packaging设置为pom形式
- 加入整个项目现在及将来要使用的依赖包版本和依赖管理
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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!--dubbo-->
<dubbo-starter.version>2.7.3</dubbo-starter.version>
<kryo.version>4.0.2</kryo.version>
<kryo-serializers.version>0.45</kryo-serializers.version>
<!--zookeeper-->
<zkclient.version>0.11</zkclient.version>
<curator-framework.version>2.12.0</curator-framework.version>
<curator-recipes.version>2.12.0</curator-recipes.version>
<zookeeper.version>3.4.14</zookeeper.version>
<!--MyBatis Mapper-->
<mybatis.version>2.1.1</mybatis.version>
<mapper.version>4.1.5</mapper.version>
<mybatis-generator.version>1.3.2</mybatis-generator.version>
<pagehelper-starter.version>1.2.13</pagehelper-starter.version>
<!--log-->
<xml-apis.version>1.4.01</xml-apis.version>
<commons-lang3.version>3.9</commons-lang3.version>
<log4j-starter.version>1.3.8.RELEASE</log4j-starter.version>
<!--local file fastDFS-->
<fileupload.version>1.4</fileupload.version>
<io.version>2.6</io.version>
<fastdfs.version>1.26.7</fastdfs.version>
<!--hystrix-->
<hystrix.version>2.2.1.RELEASE</hystrix.version>
<hystrix-dashboard.version>2.2.1.RELEASE</hystrix-dashboard.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>${zkclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo-starter.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator-framework.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${curator-recipes.version}</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>${xml-apis.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>${log4j-starter.version}</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper-starter.version}</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>${mapper.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>${mybatis-generator.version}</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${fileupload.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${io.version}</version>
</dependency>
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>${fastdfs.version}</version>
</dependency>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>${kryo.version}</version>
</dependency>
<dependency>
<groupId>de.javakaffee</groupId>
<artifactId>kryo-serializers</artifactId>
<version>${kryo-serializers.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>${hystrix.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
<version>${hystrix-dashboard.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
1.1.2. im-api
存放所有的bean和接口
im-api模块也是创建一个maven的module,主要用来存放bean数据和后续所有业务模块的接口
将bean和接口抽离是为了使各个业务模块更面向业务,将公共使用的实体类、pojo、接口集中管理,便于进行服务注册的发现的调用
由于要存放bean,因此需要导入的Lombok依赖和后面tk-mybatis生成pojo的依赖
<?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>
<parent>
<artifactId>im-parent</artifactId>
<groupId>com.icodingedu.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-api</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
</dependency>
</dependencies>
</project>
1.1.3. im-common-util
存放所有业务模块公共的依赖(springboot启动依赖)以及工具类,统一API返回工具类,统一异常输出
<?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>
<parent>
<artifactId>im-parent</artifactId>
<groupId>com.icodingedu.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-common-util</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
1、加入统一API返回
-
创建Package:com.icodingedu.mall.common
-
打开项目的类序列化id设置自动生成序列化id
package com.icodingedu.mall.common;
import java.io.Serializable;
public class R implements Serializable {
private static final long serialVersionUID = 7874608936453437793L;
private static final int SUCCESS_CODE = 200;
private static final String SUCCESS_MSG = "SUCCESS";
private int code = SUCCESS_CODE;
private String msg = SUCCESS_MSG;
private Object data = null;
public R() {
}
public static R returnOK(){
return new R();
}
public static R returnOK(int code, String msg){
R response = new R();
response.setCode(code);
response.setMsg(msg);
return response;
}
public static R returnOK(int code, String msg, Object data){
R response = new R();
response.setCode(code);
response.setMsg(msg);
response.setData(data);
return response;
}
public static R returnFAIL(int code, String msg){
R response = new R();
response.setCode(code);
response.setMsg(msg);
return response;
}
public static R returnFAIL(int code, String msg, Object data){
R response = new R();
response.setCode(code);
response.setMsg(msg);
response.setData(data);
return response;
}
public int getCode() {
return this.code;
}
public String getMsg() {
return this.msg;
}
public Object getData() {
return this.data;
}
public void setCode(int code) {
this.code = code;
}
public void setMsg(String msg) {
this.msg = msg;
}
public void setData(Object data) {
this.data = data;
}
}
2、加入统一的异常信息返回处理
package com.icodingedu.mall.common;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@ControllerAdvice
public class MyExceptionHandler {
//Exception异常处理,也可以细化到具体的异常
@ResponseBody
@ExceptionHandler(Exception.class)
//这里将统一返回结合在一起用
public R handleException(Exception e){
//这里的code可以根据业务需要自行编写
return R.returnFAIL(500,e.getMessage());
}
}
1.1.4. im-web-util
存放对接静态前端页面的controller相关依赖,例如我们的后台管理系统界面使用thymeleaf进行开发,这里就需要引入thymeleaf的依赖
<?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>
<parent>
<artifactId>im-parent</artifactId>
<groupId>com.icodingedu.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-web-util</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
</project>
1.1.5. im-service-util
存放后端业务服务模块相关依赖包,比如数据库依赖,MyBatis,PageHelper
<?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>
<parent>
<artifactId>im-parent</artifactId>
<groupId>com.icodingedu.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-service-util</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
以上的基础模块框架已经搭建完毕,后续需要新增其他内容再根据场景进行分类加入即可
1.2. 业务模块
按照上面的业务流程图,先完成后台业务管理功能模块,后台业务功能模块先以产品为主线
1.2.1. im-admin-web
后台管理系统业务模块,使用thymeleaf集成功能页面,主要包含:鉴权,权限管理,员工管理,thymeleaf页面
因此基础模块都需要导入,对于业务系统均需要创建为springboot项目
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>im-parent</artifactId>
<groupId>com.icodingedu.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-admin-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>im-admin-web</name>
<description>im-admin-web</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-common-util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-web-util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-service-util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
1.2.2. im-product-manage
产品信息管理模块,对外提供产品相关信息的查询上传等功能,输入后端服务
因此只需要引用:im-parent, im-api, im-common-util, im-service-util,依然是springboot工程
<?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>
<artifactId>im-parent</artifactId>
<groupId>com.icodingedu.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-product-manage</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>im-product-manage</name>
<description>im-product-manage</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-common-util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-service-util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
至此系统框架已经搭建完成,只待业务填充了
2、系统数据库结构分析及工具使用
数据脚本在代码库的sql-file文件夹下,使用PDMan建模工具可以管理数据库版本
3、统一接口及及异常数据返回
公共代码已经提取到im-common-util中,只需要在接口返回时调用即可,异常信息返回会自动加载
4、数据库逆向工程应用
4.1. 逆向工程使用
单独创建一个逆向工程用来生成pojo,mapper,mapper.xml
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>
<parent>
<artifactId>im-parent</artifactId>
<groupId>com.icodingedu.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.icodingedu.com</groupId>
<artifactId>im-dbreverse</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-common-util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.icodingedu.mall</groupId>
<artifactId>im-service-util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
</dependency>
</dependencies>
</project>
逆向工程配置文件generatorConfig.xml,放在resource下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<context id="MysqlContext" targetRuntime="MyBatis3Simple" defaultModelType="flat">
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<!-- 通用mapper所在目录 -->
<plugin type="tk.mybatis.mapper.generator.MapperPlugin">
<property name="mappers" value="com.icodingedu.mall.reverse.tools.MyMapper"/>
</plugin>
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/icoding-mall"
userId="root"
password="gavin">
</jdbcConnection>
<!-- 对应生成的pojo所在包 -->
<javaModelGenerator targetPackage="com.icodingedu.mall.reverse.pojo" targetProject="/Users/gavin/Documents/ideaworkspace/icodingedu-mall-study/im-dbreverse/src/main/java"/>
<!-- 对应生成的mapper.xml所在目录 -->
<sqlMapGenerator targetPackage="mybatis/mapper" targetProject="/Users/gavin/Documents/ideaworkspace/icodingedu-mall-study/im-dbreverse/src/main/resources"/>
<!-- 配置mapper对应的java映射 -->
<javaClientGenerator targetPackage="com.icodingedu.mall.reverse.mapper" targetProject="/Users/gavin/Documents/ideaworkspace/icodingedu-mall-study/im-dbreverse/src/main/java" type="XMLMAPPER"/>
<!-- 数据库表 -->
<table tableName="im_product"></table>
<table tableName="im_product_images"></table>
<table tableName="im_product_inventory"></table>
</context>
</generatorConfiguration>
逆向生成类
package com.icodingedu.mall.reverse.tools;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import org.springframework.util.ResourceUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class GeneratorDisplay {
public void generator() throws Exception {
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
//指定 逆向工程配置文件
File configFile = ResourceUtils.getFile("classpath:generatorConfig.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
callback, warnings);
myBatisGenerator.generate(null);
}
public static void main(String[] args) throws Exception {
try {
GeneratorDisplay generatorSqlmap = new GeneratorDisplay();
generatorSqlmap.generator();
} catch (Exception e) {
e.printStackTrace();
}
}
}
以上逆向工程生成pojo、mapper、mapper.xml完毕后
-
pojo类和MyMapper接口复制到im-api模块中
-
mapper和mapper.xml复制到需要使用的模块
这里只逆向了产品信息,直接复制到im-product-manage里即可,复制后的代码参考GitHub
4.2. 逆向工程应用
4.2.1. 使用tk-mapper实现CRUD
将mapper和mapper.xml导入后im-product-manage注意bean和mapper的资源路径要重新引用
im-product-manage的yaml文件
server:
port: 8091
tomcat:
uri-encoding: UTF-8
spring:
datasource:
username: root
password: gavin
url: jdbc:mysql://localhost:3306/icoding-mall?useUnicode=true&characterEncoding=UTF-8
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.zaxxer.hikari.HikariDataSource
hikari:
connection-timeout: 30000 #等待分配连接最大时长,毫秒,默认30秒
minimum-idle: 5 #最小连接数
maximum-pool-size: 20 #最大连接数,推荐的公式:((core_count * 2) + effective_spindle_count)
auto-commit: true #自动提交
idle-timeout: 600000 #连接闲置的最大时长,毫秒,默认10分钟
pool-name: DataSourceHikariCP #自定义名字
max-lifetime: 1800000 #一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟
connection-test-query: select 1 #测试活跃sql
#使用tk-mybatis缺省可以不加
mapper:
mappers: com.icodingedu.mall.api.service.MyMapper
not-empty: false
identity: MYSQL
#使用pagehelper缺省可以不加
pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-arguments: false
使用tk-mybatis需要在启动类上加入注解扫包
@MapperScan("com.icodingedu.mall.product.mapper")
接口实现
package com.icodingedu.mall.api.service;
import com.icodingedu.mall.api.bean.ImProduct;
import java.util.List;
public interface ProductService {
List<ImProduct> queryProductList(int pageNum,int pageSize);
}
实现类
package com.icodingedu.mall.product.service.impl;
import com.github.pagehelper.PageHelper;
import com.icodingedu.mall.api.bean.ImProduct;
import com.icodingedu.mall.api.service.ProductService;
import com.icodingedu.mall.product.mapper.ImProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ProductServiceImpl implements ProductService {
@Autowired
ImProductMapper imProductMapper;
@Override
public List<ImProduct> queryProductList(int pageNum,int pageSize) {
PageHelper.startPage(pageNum,pageSize);
List<ImProduct> imProductList = imProductMapper.selectAll();
return imProductList;
}
}
controller
package com.icodingedu.mall.product.controller;
import com.github.pagehelper.PageInfo;
import com.icodingedu.mall.api.bean.ImProduct;
import com.icodingedu.mall.api.service.ProductService;
import com.icodingedu.mall.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
public class ProductController {
@Autowired
ProductService productService;
@GetMapping("/productlist")
@ResponseBody
public R queryAllProduct(){
List<ImProduct> imProductList = productService.queryProductList(1,3);
PageInfo<ImProduct> productPageInfo = new PageInfo<ImProduct>(imProductList);
return R.returnOK(200,"成功",productPageInfo);
}
}
至此一个完整的调用已完成,调用关系也已验证完成
5、系统分布式架构设计
系统在分布式前是以单体垂直集群模式运行,一个系统内业务功能互相影响
这个时候就需要将业务按照功能模块进行拆分