欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Springcloud 之feign调用踩坑

程序员文章站 2022-04-26 10:31:42
...
@RestController
@RequestMapping("/ykt")
public class YktController {
@PostMapping("/queryPermissionByCardNumber/{cardNumber}")
	public String queryPermissionByCardNumber(@PathVariable(value = "cardNumber") String cardNumber) {
		return yktService.queryPermissionByCardNumber(cardNumber);
	}

@PostMapping("/openDoor/{channelList}")
	public String openDoor(@PathVariable(value = "channelList") List<String> channelList) {
		closeDoor(channelList);
		List<String> newList = new ArrayList<>();
		for (String str : channelList) {
			newList.add(str.replace("-", "$"));
		}
		return yktService.openDoor(newList);
	}
}

服务提供者

@SuppressWarnings("ALL")
@FeignClient(value = "device", fallback = ScheduleDeviceServiceHys.class)
public interface ScheduleDeviceService {
@PostMapping("/ykt/queryPermissionByCardNumber/{cardNumber}")
	public String queryPermissionByCardNumber(@PathVariable(value = "cardNumber") String cardNumber);


@PostMapping("/ykt/openDoor/{channelList}")
	public String openDoor(@PathVariable(value = "channelList") List<String> channelList);
}

服务消费者

服务消费者接口必须和提供者接口完全相同(其中注解最好不用@RequestMapping)最好明确用@PostMapping或者@GetMapping
另外携带参数时接口中@PathVariable后面须指定value的值,不然会报错

相关标签: springcloud