SpringCloud微服务(2022)

微服务/分布式(轻量级/模块)

    • 一、SpringCloud:服务全家桶/一站式
      • (一) 组件
        • 1、服务发现框架(注册中心):~~Eureka~~ 、Zookeeper、Consul、nacos
        • 2、负载均衡: Ribbon、Nignx、loadBalancer
        • 3、服务调用映射:~~feign~~ 、Open Feign
        • 4、熔断器(断路器):Alibaba sentienl、Hystrix、resilience4j
        • 5、网关路由:gateway、Zuul
        • 6、统一配置中心:nacos、Config
        • 7、消息总线:nacos、Bus
      • (二)工程搭建
        • 1、总父工程项目(Maven)
          • 1. 创建:直接创建普通maven项目即可
          • 2. 问题:
          • 3.编码设置(idea):
          • 4.注解处理器激活(idea):
          • 5.JDK编译器版本(idea):
          • 6.过滤文件类型(idea):
          • 7.mvn命令:右边窗口Maven里面的命令
          • 8.打包类型(idea):
          • 9.Maven总包依赖管理(idea):
          • 10.生命周期:闪电图标:禁止test:跳过单元测试
        • 2、Maven子工程项目(Module):模块
          • 1.支付模块
            • 1 POM.xml: cloud-provider-payment8001
            • 2 application.yml:spring配置文件——properties可替代
            • 5 主启动类:@SpringBootApplication
            • 3 数据库SQL:建库、建表
            • 4 实体类::Lombok(简化代码)
            • 5 服务业务
            • 6 控制调度
            • 7 数据映射
            • 8 测试
          • 2.消费者
            • 1 POM.xml: cloud-provider-payment8001
            • 2 application.yml:spring配置文件——properties可替代
            • 5 主启动类:@SpringBootApplication
            • 3 数据库SQL:建库、建表
            • 4 实体类::Lombok(简化代码)
            • 5 服务业务
            • 6 控制调度
            • 7 数据映射
            • 8 测试
    • 二、软件使用
      • (一)postma软件测试http协议
        • 1、GET方法:浏览器支持良好
        • 2、POST方法:浏览器支持不好
      • (二)RUN运行方式:IDEA Run Dashboard面板
        • 1、传统运行方式:Run
        • 2、新方式:Run Dashboard
      • (三)热部署:自动部署、生产环境关闭
    • 三、SpringCloud Alibaba

  1. 技术:Java、maven、Git、github、Nginx、RabbitMQ、springboot
  2. 根据:约定>约束>配置
  3. 架构:前端——后台(C-S-D)——数据库
  4. 问题:文件名、路径、配置重复、版本号、依赖、地址、连接路径
  5. https://start.spring.io → 换地址 → https://start.aliyun.com
    解决SocketTimeoutException: connect timed out问题

一、SpringCloud:服务全家桶/一站式

(一) 组件

1、服务发现框架(注册中心):Eureka 、Zookeeper、Consul、nacos

2、负载均衡: Ribbon、Nignx、loadBalancer

负载均衡算法
进程内负载均衡器

3、服务调用映射:feign 、Open Feign

4、熔断器(断路器):Alibaba sentienl、Hystrix、resilience4j

服务降级熔断器

5、网关路由:gateway、Zuul

6、统一配置中心:nacos、Config

7、消息总线:nacos、Bus

(二)工程搭建

1、总父工程项目(Maven)

1. 创建:直接创建普通maven项目即可
2. 问题:
  1. 标红:
    maven-project-info-reports-plugin
  2. 解决:
<dependency>
      <groupId>org.apache.maven.pluginsgroupId>
      <artifactId>maven-project-info-reports-pluginartifactId>
      <version>3.0.0version>
      <type>maven-plugintype>
    dependency>
3.编码设置(idea):
File | Settings | Editor | File Encodings | 全局编码(UTF-8)
File | Settings | Editor | File Encodings | 项目编码(UTF-8)
File | Settings | Editor | File Encodings | 项目文件路径项目(UTF-8)
File | Settings | Editor | File Encodings | 默认编码属性配置文件/打钩翻译本地编码转换(√)(UTF-8)
4.注解处理器激活(idea):
File | Settings | Build, Execution, Deployment | Compiler | Annotation Processors | Enable annotation processing打钩√
5.JDK编译器版本(idea):
  1. 项目构建:
    Project Settings | Project
    Project Settings | Modules(注意!!)
  2. 设置:File | Settings | Build, Execution, Deployment | Compiler | Java Compiler
6.过滤文件类型(idea):
File | Settings | Editor | File Types | Recognized File | AS ActionScript | Ignored Files and Folders
7.mvn命令:右边窗口Maven里面的命令
8.打包类型(idea):
  1. pom
9.Maven总包依赖管理(idea):
  
  
  <properties>
    
    <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    
    <maven.compiler.source>1.8maven.compiler.source>
    <maven.compiler.target>1.8maven.compiler.target>
    
    <junit.version>4.12junit.version>
    
    <log4j.version>1.2.17log4j.version>
    
    <lombok.version>1.18.0lombok.version>
    
    <mysql.version>8.0.19mysql.version>
    
    <druid.version>1.1.16druid.version>
    
    <mybatis.spring.boot.version>1.3.2mybatis.spring.boot.version>
  properties>



  
  
  
  
  
  
  
  <dependencyManagement>

    <dependencies>
      
      <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-dependenciesartifactId>
        <version>2.2.2.RELEASEversion>
        <type>pomtype>
        <scope>importscope>
      dependency>
      
      <dependency>
        <groupId>org.springframework.cloudgroupId>
        <artifactId>spring-cloud-dependenciesartifactId>
        <version>Hoxton.SR1version>
        <type>pomtype>
        <scope>importscope>
      dependency>
      
      <dependency>
        <groupId>com.alibaba.cloudgroupId>
        <artifactId>spring-cloud-alibaba-dependenciesartifactId>
        <version>2.1.0.RELEASEversion>
        <type>pomtype>
        <scope>importscope>
      dependency>
      <dependency>
        <groupId>mysqlgroupId>
        <artifactId>mysql-connector-javaartifactId>
        <version>${mysql.version}version>
      dependency>
      <dependency>
        <groupId>com.alibabagroupId>
        <artifactId>druidartifactId>
        <version>${druid.version}version>
      dependency>
      <dependency>
        <groupId>org.mybatis.spring.bootgroupId>
        <artifactId>mybatis-spring-boot-starterartifactId>
        <version>${mybatis.spring.boot.version}version>
      dependency>
      <dependency>
        <groupId>junitgroupId>
        <artifactId>junitartifactId>
        <version>${junit.version}version>
      dependency>
      <dependency>
        <groupId>log4jgroupId>
        <artifactId>log4jartifactId>
        <version>${log4j.version}version>
      dependency>
      <dependency>
        <groupId>org.projectlombokgroupId>
        <artifactId>lombokartifactId>
        <version>${lombok.version}version>
        <optional>trueoptional>
      dependency>
    dependencies>
  dependencyManagement>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-maven-pluginartifactId>
        <version>2.2.6.RELEASEversion>
        <configuration>
          <fork>truefork>
          <addResources>trueaddResources>
        configuration>
      plugin>
    plugins>
  build>
10.生命周期:闪电图标:禁止test:跳过单元测试

在这里插入图片描述

2、Maven子工程项目(Module):模块

  1. 方式:鼠标右击项目
  2. 路径:New | Module | Maven
  3. 模块套路:
    建Module
    改POM
    写YML
    主启动
    业务类
1.支付模块
1 POM.xml: cloud-provider-payment8001
    
    <parent>
        <artifactId>CloudartifactId>
        <groupId>com.remligroupId>
        <version>1.0-SNAPSHOTversion>
    parent>

    <modelVersion>4.0.0modelVersion>
    <artifactId>cloud-provider-payment8001artifactId>

    <properties>
        <maven.compiler.source>8maven.compiler.source>
        <maven.compiler.target>8maven.compiler.target>
    properties>

    
    <dependencies>
        
        <dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-starter-zipkinartifactId>
        dependency>
        
        <dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-starter-netflix-eureka-clientartifactId>
        dependency>
        
        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-actuatorartifactId>
        dependency>
        <dependency>
            <groupId>org.mybatis.spring.bootgroupId>
            <artifactId>mybatis-spring-boot-starterartifactId>
        dependency>
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>druid-spring-boot-starterartifactId>
            <version>1.1.10version>
        dependency>
        
        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
        dependency>
        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-jdbcartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-devtoolsartifactId>
            <scope>runtimescope>
            <optional>trueoptional>
        dependency>
        <dependency>
            <groupId>org.projectlombokgroupId>
            <artifactId>lombokartifactId>
            <optional>trueoptional>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>
    dependencies>

project>
2 application.yml:spring配置文件——properties可替代
server:
  port: 8001

spring:
  application:
    name: cloud-payment-service
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource          # 当前数据源操作类型
    driver-class-name: com.mysql.cj.jdbc.Driver            # mysql驱动包
    url: jdbc:mysql://localhost:3306/db2022?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: root
    password: 12345678
  zipkin:
    base-url: http://localhost:9411
  sleuth:
    sampler:
      #采样率值介于0到1之间,1则表示全部采集
      probability: 1

mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.atguigu.springcloud.entities

eureka:
  client:
    service-url:
      defaultZone: http://www.eureka7001.com:7001/eureka/,http://www.eureka7002.com:7002/eureka/
#      defaultZone: http://eureka7001.com:7001/eureka/
  instance:
    ip-address: 127.0.0.1
    instance-id: payment8001
    prefer-ip-address: true
    lease-renewal-interval-in-seconds: 1
    lease-expiration-duration-in-seconds: 2
5 主启动类:@SpringBootApplication
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class PaymentMain001 {
    public static void main(String[] args) {
        SpringApplication.run(PaymentMain001.class, args);
    }
}
3 数据库SQL:建库、建表
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
CREATE database db2019;
USE db2022;
DROP TABLE IF EXISTS `payment`;
CREATE TABLE `payment`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `serial` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '支付流水号',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '支付表' ROW_FORMAT = Dynamic;
4 实体类::Lombok(简化代码)
  1. Payment.java:
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Payment implements Serializable {
    private Long id;
    private String serial;
}
  1. CommonResult.java:JSON封装体
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T>{
    private Integer code;
    private String message;
    private T data;

    public CommonResult(Integer code, String message){
        this(code, message, null);
    }
}
5 服务业务
  1. PaymentService.java:服务接口
import com.lun.springcloud.entities.Payment;
import org.apache.ibatis.annotations.Param;

public interface PaymentService
{
    public int create(Payment payment);
    public Payment getPaymentById(@Param("id") Long id);
}
  1. PaymentServiceImpl.java:服务实现
import com.lun.springcloud.dao.PaymentDao;
import com.lun.springcloud.entities.Payment;
import com.lun.springcloud.service.PaymentService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

@Service
public class PaymentServiceImpl implements PaymentService
{
    @Resource
    private PaymentDao paymentDao;

    public int create(Payment payment)
    {
        return paymentDao.create(payment);
    }

    public Payment getPaymentById(Long id)
    {
        return paymentDao.getPaymentById(id);
    }
}
6 控制调度
import com.lun.springcloud.entities.CommonResult;
import com.lun.springcloud.entities.Payment;
import com.lun.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.web.bind.annotation.*;
import org.springframework.cloud.client.discovery.DiscoveryClient;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 */
@RestController
@Slf4j
public class PaymentController{
    @Resource
    private PaymentService paymentService;

    @PostMapping(value = "/payment/create")
    public CommonResult create(Payment payment)
    {
        int result = paymentService.create(payment);
        log.info("*****插入结果:"+result);

        if(result > 0)
        {
            return new CommonResult(200,"插入数据库成功,serverPort: "+serverPort,result);
        }else{
            return new CommonResult(444,"插入数据库失败",null);
        }
    }

    @GetMapping(value = "/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id)
    {
        Payment payment = paymentService.getPaymentById(id);

        if(payment != null)
        {
            return new CommonResult(200,"查询成功,serverPort:  "+serverPort,payment);
        }else{
            return new CommonResult(444,"没有对应记录,查询ID: "+id,null);
        }
    }
}

7 数据映射
  1. PaymentDao.java:接口
import com.atguigu.springcloud.entities.Payment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

@Mapper
//@Repository不用Spring的
public interface PaymentDao
{
    public int create(Payment payment);

    public Payment getPaymentById(@Param("id") Long id);
}
  1. PaymentMapper.xml:MyBatis映射文件

DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

<mapper namespace="com.lun.springcloud.dao.PaymentDao">

    <insert id="create" parameterType="Payment" useGeneratedKeys="true" keyProperty="id">
        insert into payment(serial)  values(#{serial});
    insert>
    
    <resultMap id="BaseResultMap" type="com.lun.springcloud.entities.Payment">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <id column="serial" property="serial" jdbcType="VARCHAR"/>
    resultMap>

    <select id="getPaymentById" parameterType="Long" resultMap="BaseResultMap">
        select * from payment where id=#{id};
    select>

mapper>

8 测试
  1. GET查询:http://localhost:8001/payment/get/1
    格式:http://localhost:端口号/payment/get/表id
    端口号=server-port
    数据库id=表中id号
    直接查询
  2. 提交Postman:http://localhost:8001/payment/create?serial=lun2
2.消费者
1 POM.xml: cloud-provider-payment8001


<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.0modelVersion>

  <groupId>com.remligroupId>
  <artifactId>cloud-consumer-order80artifactId>
  <version>1.0-SNAPSHOTversion>



  
  <dependencies>
    <dependency>
      <groupId>org.apache.httpcomponentsgroupId>
      <artifactId>httpclientartifactId>
      <scope>testscope>
    dependency>

    
    <dependency>
      <groupId>org.springframework.cloudgroupId>
      <artifactId>spring-cloud-starter-netflix-eureka-clientartifactId>
    dependency>

    <dependency>
      <groupId>org.springframework.bootgroupId>
      <artifactId>spring-boot-starter-webartifactId>
    dependency>
    <dependency>
      <groupId>org.springframework.bootgroupId>
      <artifactId>spring-boot-starter-actuatorartifactId>
    dependency>
    <dependency>
      <groupId>org.mybatis.spring.bootgroupId>
      <artifactId>mybatis-spring-boot-starterartifactId>
    dependency>
    <dependency>
      <groupId>com.alibabagroupId>
      <artifactId>druid-spring-boot-starterartifactId>
    dependency>
    
    <dependency>
      <groupId>mysqlgroupId>
      <artifactId>mysql-connector-javaartifactId>
    dependency>
    
    <dependency>
      <groupId>org.springframework.bootgroupId>
      <artifactId>spring-boot-starter-jdbcartifactId>
    dependency>
    <dependency>
      <groupId>org.projectlombokgroupId>
      <artifactId>lombokartifactId>
      <optional>trueoptional>
    dependency>
    <dependency>
      <groupId>org.springframework.bootgroupId>
      <artifactId>spring-boot-starter-testartifactId>
      <scope>testscope>
    dependency>
    <dependency>
      <groupId>org.springframework.bootgroupId>
      <artifactId>spring-boot-devtoolsartifactId>
      <scope>runtimescope>
      <optional>trueoptional>
    dependency>
  dependencies>

project>

2 application.yml:spring配置文件——properties可替代
server:
  port: 8001

spring:
  application:
    name: cloud-payment-service
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource          # 当前数据源操作类型
    driver-class-name: com.mysql.cj.jdbc.Driver            # mysql驱动包
    url: jdbc:mysql://localhost:3306/db2022?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: root
    password: 12345678
  zipkin:
    base-url: http://localhost:9411
  sleuth:
    sampler:
      #采样率值介于0到1之间,1则表示全部采集
      probability: 1

mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.atguigu.springcloud.entities

eureka:
  client:
    service-url:
      defaultZone: http://www.eureka7001.com:7001/eureka/,http://www.eureka7002.com:7002/eureka/
#      defaultZone: http://eureka7001.com:7001/eureka/
  instance:
    ip-address: 127.0.0.1
    instance-id: payment8001
    prefer-ip-address: true
    lease-renewal-interval-in-seconds: 1
    lease-expiration-duration-in-seconds: 2
5 主启动类:@SpringBootApplication
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class PaymentMain001 {
    public static void main(String[] args) {
        SpringApplication.run(PaymentMain001.class, args);
    }
}
3 数据库SQL:建库、建表
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
CREATE database db2019;
USE db2022;
DROP TABLE IF EXISTS `payment`;
CREATE TABLE `payment`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `serial` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '支付流水号',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '支付表' ROW_FORMAT = Dynamic;
4 实体类::Lombok(简化代码)
  1. Payment.java:
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Payment implements Serializable {
    private Long id;
    private String serial;
}
  1. CommonResult.java:JSON封装体
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T>{
    private Integer code;
    private String message;
    private T data;

    public CommonResult(Integer code, String message){
        this(code, message, null);
    }
}
5 服务业务
  1. PaymentService.java:服务接口
import com.lun.springcloud.entities.Payment;
import org.apache.ibatis.annotations.Param;

public interface PaymentService
{
    public int create(Payment payment);
    public Payment getPaymentById(@Param("id") Long id);
}
  1. PaymentServiceImpl.java:服务实现
import com.lun.springcloud.dao.PaymentDao;
import com.lun.springcloud.entities.Payment;
import com.lun.springcloud.service.PaymentService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

@Service
public class PaymentServiceImpl implements PaymentService
{
    @Resource
    private PaymentDao paymentDao;

    public int create(Payment payment)
    {
        return paymentDao.create(payment);
    }

    public Payment getPaymentById(Long id)
    {
        return paymentDao.getPaymentById(id);
    }
}
6 控制调度
import com.lun.springcloud.entities.CommonResult;
import com.lun.springcloud.entities.Payment;
import com.lun.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.web.bind.annotation.*;
import org.springframework.cloud.client.discovery.DiscoveryClient;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 */
@RestController
@Slf4j
public class PaymentController{
    @Resource
    private PaymentService paymentService;

    @PostMapping(value = "/payment/create")
    public CommonResult create(Payment payment)
    {
        int result = paymentService.create(payment);
        log.info("*****插入结果:"+result);

        if(result > 0)
        {
            return new CommonResult(200,"插入数据库成功,serverPort: "+serverPort,result);
        }else{
            return new CommonResult(444,"插入数据库失败",null);
        }
    }

    @GetMapping(value = "/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id)
    {
        Payment payment = paymentService.getPaymentById(id);

        if(payment != null)
        {
            return new CommonResult(200,"查询成功,serverPort:  "+serverPort,payment);
        }else{
            return new CommonResult(444,"没有对应记录,查询ID: "+id,null);
        }
    }
}

7 数据映射
  1. PaymentDao.java:接口
import com.atguigu.springcloud.entities.Payment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

@Mapper
//@Repository不用Spring的
public interface PaymentDao
{
    public int create(Payment payment);

    public Payment getPaymentById(@Param("id") Long id);
}
  1. PaymentMapper.xml:MyBatis映射文件

DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

<mapper namespace="com.lun.springcloud.dao.PaymentDao">

    <insert id="create" parameterType="Payment" useGeneratedKeys="true" keyProperty="id">
        insert into payment(serial)  values(#{serial});
    insert>
    
    <resultMap id="BaseResultMap" type="com.lun.springcloud.entities.Payment">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <id column="serial" property="serial" jdbcType="VARCHAR"/>
    resultMap>

    <select id="getPaymentById" parameterType="Long" resultMap="BaseResultMap">
        select * from payment where id=#{id};
    select>

mapper>

8 测试
  1. GET查询:http://localhost:8001/payment/get/1
    格式:http://localhost:端口号/payment/get/表id
    端口号=server-port
    数据库id=表中id号
    直接查询
  2. 提交Postman:http://localhost:8001/payment/create?serial=lun2

二、软件使用

(一)postma软件测试http协议

1、GET方法:浏览器支持良好

2、POST方法:浏览器支持不好

(二)RUN运行方式:IDEA Run Dashboard面板

1、传统运行方式:Run

2、新方式:Run Dashboard

  1. IDEA设置:
    View →Tool Windows → Services
  2. 文件配置:.idea / workspace.xml
  <component name="RunDashboard">
    <option name="configurationTypes">
      <set>
        <option value="SpringBootApplicationConfigurationType" />
      set>
    option>
  component>

3.作用:
看到启动项目、显示相应端口、启动多模块、微服务启动

(三)热部署:自动部署、生产环境关闭

开发时使用、生产环境关闭
  1. 支付子模块pom.xml:Adding devtools to your project
<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-devtoolsartifactId>
    <scope>runtimescope>
    <optional>trueoptional>
dependency>
  1. 聚合父类总工程pom.xml:Adding plugin to your pom.xml
  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-maven-pluginartifactId>
        <version>2.2.6.RELEASEversion>
        <configuration>
          <fork>truefork>
          <addResources>trueaddResources>
        configuration>
      plugin>
    plugins>
  build>
  1. IDEA设置:Enabling automatic build
    路径:File → Settings → Build/Execution/Deployment → Complier
    打钩:√
    √ Automatically show first error in editor
    √ Display notification on build completion
    √ Build project automatically
    √ Compile independent modules in parallel

  2. 2021版本IDEA:Update the value of
    老版本:键入Ctrl + Shift + Alt + / ,打开Registry,
    勾选:compiler.automake.allow.when.app.running
    勾选:actionSystem.assertFocusAccessFromEdt

    2021版本路径:File → Settings → Advanced Settings
    √ Allow auto-make to start even if developed application is currently running

    快捷键:键入Ctrl + Shift + Alt + / ,打开Registry
    √ actionSystem.assertFocusAccessFromEdt

  3. 重启IDEA

三、SpringCloud Alibaba

你可能感兴趣的:(Spring,分布式,java,spring,cloud,微服务)