• spring cloud feign


    <dependencies>
            <dependency>
                <groupId>io.github.openfeign</groupId>
                <artifactId>feign-core</artifactId>
                <version>9.5.0</version>
            </dependency>
            <dependency>
                <groupId>io.github.openfeign</groupId>
                <artifactId>feign-gson</artifactId>
                <version>9.5.0</version>
            </dependency>        
        </dependencies>
    @RestController
    public class MyRestController {
    
    	@RequestMapping(value = "/person/{id}", method = RequestMethod.GET, 
    			produces = MediaType.APPLICATION_JSON_VALUE)
    	public Person getPerson(@PathVariable Integer id) {
    		Person p = new Person();
    		p.setId(id);
    		p.setName("angus");
    		p.setAge(30);
    		return p;
    	}
    }
    
    
    

      

    
    
    public interface HelloClient {
    
        @RequestLine("GET /hello")
        public String hello();
        
        @RequestLine("GET /person/{id}")
        public Person getPerson(@Param("id") Integer id);
    }
    public static void main(String[] args) {
    		HelloClient client = Feign.builder().target(HelloClient.class,
    				"http://localhost:8080");
    		String result = client.hello();
    		System.out.println(result);
    	}
    

      

    public static void main(String[] args) {
            HelloClient client = Feign.builder()
                    .decoder(new GsonDecoder())
                    .target(HelloClient.class,
                    "http://localhost:8080");
            Person p = client.getPerson(1);
            System.out.println(p.getId());
            System.out.println(p.getName());
            System.out.println(p.getAge());
        }
  • 相关阅读:
    Python:解析PDF文本及表格——pdfminer、tabula、pdfplumber 的用法及对比
    2018数学建模国赛B题
    目标检测综述整理
    numpy实现两层layer
    应用安全
    应用安全
    应用安全
    应用安全
    应用安全
    应用安全
  • 原文地址:https://www.cnblogs.com/zfzf1/p/8540291.html
Copyright © 2020-2023  润新知