• 第六节--消费者订单Module模块


    测试添加修改时不要忘记在提供端使用@ReqestBody注解,否则插入的值都是空
    1 .新建工程cloud-consumer-order80 ,
     
    2 .pom.xml依赖
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <!-- actuator监控信息完善 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
        <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>
        </dependency>
    
    
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <!--热部署  -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
    
    
    </dependencies>

    2 .yml文件

    server:
      port: 80

    3 .controller类

    @RestController
    @Slf4j
    public class OrderController {
    
    
    
    
        public  static final String PAYMENT_URL="http://localhost:8001";
    
    
        @Resource private RestTemplate restTemplate;
        @PostMapping("/consumer/addPayment")
        public CommonResult addPayment(Payment payment){
           return  restTemplate.postForObject(PAYMENT_URL+"/admin/addPayment",payment,CommonResult.class);
         }
    
    
         @GetMapping("/consumer/findPaymentById")
         public CommonResult  findPaymentById(@PathVariable("id")Long id){
            log.info("消费端查找数据");
            return restTemplate.getForObject(PAYMENT_URL+"/admin/findPaymentById"+id,CommonResult.class);
         }
    }

    4 RestTemplate配置类

    @Configuration
    public class ApplicationConfig {
    
    
        @Bean
        public RestTemplate getTemplate(){
            return new RestTemplate();
        }
    }

    5 .主启动类

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

    6 .使用Postman测试

  • 相关阅读:
    kNN算法python实现和简单数字识别的方法
    python3.4学习笔记(二十) python strip()函数 去空格 函数的用法
    SolrCloud分布式集群部署步骤
    hbases索引技术:Lily HBase Indexer介绍
    HBase1.0以上版本的API改变
    Hbase1.0 客户端api
    java.io.IOException: Could not locate executable nullinwinutils.exe in the Hadoop binaries
    Resharp最新破解方法
    Cloudera Manager 5和CDH5离线安装
    Apache Thrift
  • 原文地址:https://www.cnblogs.com/hexublog/p/13681755.html
Copyright © 2020-2023  润新知