Feign使用案例

1、maven
sb版本要比sc版本一样,或者比sc高

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-data-redis</artifactId>
		<version>2.1.2.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-openfeign</artifactId>
		<version>2.1.1.RELEASE</version>
	</dependency>

2、启动类

	@EnableFeignClients(basePackages={"com.*"})
	public class WmsApplication {
		public static void main(String[] args) {
			SpringApplication.run(WmsApplication.class, args);
		} 
	}

3、使用案例

	import org.springframework.cloud.openfeign.FeignClient;
	import org.springframework.web.bind.annotation.RequestBody;
	import org.springframework.web.bind.annotation.RequestMapping;
	import org.springframework.web.bind.annotation.RequestMethod;
	import org.springframework.web.bind.annotation.RequestParam;
	
	import com.alibaba.fastjson.JSONObject;
	
	@FeignClient(url= "${test_url}",name="client")
	public interface TestClient {
	
	  @RequestMapping(value="${test_token}",method= RequestMethod.GET)
	  JSONObject getAccessToken(@RequestParam("grant_type") String grant_type,@RequestParam("appid") String appid,@RequestParam("secret") String secret);
	  
	  @RequestMapping(value="${test_getticket}",method= RequestMethod.GET)
	  JSONObject getTicket(@RequestParam("access_token") String access_token,@RequestParam("type") String type);
	
	  @RequestMapping(value="${test_oauth2_access_token}",method= RequestMethod.GET)
	  String getOpenId(@RequestParam("appid") String appid,@RequestParam("secret") String secret,@RequestParam("code") String code,@RequestParam("grant_type") String grant_type);
	
	  @RequestMapping(value="${test_menu_create}",method= RequestMethod.POST)
	  JSONObject menuCreate(@RequestParam("access_token") String accessToken,@RequestBody(required=false)String jsonResult);
	}

你可能感兴趣的:(feign,后端)