SpringCloud中微服务之间的调用,传递参数时需要加相应的注解。主要用到的就是这三个注解@RequestBody,@RequestParam,@PathVariable
上一篇已经展示了怎么使用@RequestParam该注解,这一篇我们使用一下剩下的两种注解:
@PathVariable使用如下:
只需要在eureka-fegin-service和eureka-fegin-service-tmp的Controller中修改如下:
package com.cn.controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class EurekaFeginTmpController {
@RequestMapping("/getName")
public String getName(@RequestParam String name){
return "hello2 : " + name;
}
@RequestMapping("/getName/{id}")
public String getNameById(@PathVariable Long id){
return "hello2 :