<dependencies>
<dependency>?
<groupId>org.springframework.boot</groupId>???
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>?
<groupId>org.springframework.boot</groupId>???
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>???
<groupId>org.springframework.boot</groupId>???
<artifactId>spring-boot-devtools</artifactId>???
<scope>runtime</scope>???
<optional>true</optional>
</dependency>
<dependency>???
<groupId>org.projectlombok</groupId>???
<artifactId>lombok</artifactId>??
<optional>true</optional>
</dependency>
<dependency>???
<groupId>org.springframework.boot</groupId>???
<artifactId>spring-boot-starter-test</artifactId>???
<scope>test</scope>
</dependency>
</denpendencies>
server:
port: 80
@SpringBootApplication
public class OrderMain80 {
public static void main(String[] args) {
SpringApplication.run(OrderMain80.class, args);
}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Payment implements Serializable {
private Long id;
private String serial;
}
@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);
}
}
@Configuration
public class ApplicationContextConfig {
@Bean
public RestTemplate getRestTemplate() {
return new RestTemplate();
}
}
@RestController
@Slf4j
public class OrderController {
// 这里的 url 根据自己的来写
public static final String PAYMENT_URL = "http://localhost:8001";
@Resource
private RestTemplate restTemplate;
@GetMapping("/consumer/payment/create")
public CommonResult<Payment> create(Payment payment) {
return restTemplate.postForObject(PAYMENT_URL + "/payment/create", CommonResult.class);
}
@GetMapping("/consumer/payment/get/{id}")
public CommonResult<Payment> getPayment(@PathVariable("id") Long id) {
return restTemplate.getForObject(PAYMENT_URL + "/payment/get" + id, CommonResult.class);
}
}
04_4-cloud-consumer-order80 微服务消费者订单Module模块
原文:https://www.cnblogs.com/zwxo1/p/13466784.html