zoukankan      html  css  js  c++  java
  • spring cloud spirng整合feign

    restserver

    @RestController
    public class PoliceController {
    
    	@RequestMapping(value = "/call/{id}", method = RequestMethod.GET, 
    			produces = MediaType.APPLICATION_JSON_VALUE)
    	public Police call(@PathVariable Integer id, HttpServletRequest request) {
    		Police p = new Police();
    		p.setId(id);
    		p.setName("angus");
    		p.setMessage(request.getRequestURL().toString());
    		return p;
    	}
    	
    	@RequestMapping(value = "/hello/{name}", method = RequestMethod.GET)
    	public String hello(@PathVariable String name) {
    		return "Hello, " + name;
    	}
    	
    	@RequestMapping(value = "/hellowd", method = RequestMethod.GET)
    	public String helloWithOutArg() {
    		return "Hello World";
    	}
    }
    

      feign client interface

    @FeignClient("spring-feign-provider")
    public interface HelloClient {
    
    	@RequestMapping(method = RequestMethod.GET, value="/hello/{name}")
    	String hello(@PathVariable("name") String name);
    	
    	
    	@RequestMapping(method = RequestMethod.GET, value="/call/{id}")
    	Police getPolice(@PathVariable("id") Integer id);
    	
    	@MyUrl(url = "/hellowd", method = "GET")
    	String myHello();
    }
    

      feign client

    @RestController
    public class TestController {
    	
    	@Autowired
    	private HelloClient helloClient;
    
    	@RequestMapping(method = RequestMethod.GET, value="/router")
    	public String router() {
    		String result = helloClient.hello("angus");
    		return result;
    	}
    
    	@RequestMapping(method = RequestMethod.GET, value="/police", 
    			produces = MediaType.APPLICATION_JSON_VALUE)
    	public Police getPolice() {
    		Police p = helloClient.getPolice(1);
    		return p;
    	}
    	
    	@RequestMapping(method = RequestMethod.GET, value="/myhello")
    	public String myHello() {
    		return helloClient.myHello();
    	}
    }
    

      

  • 相关阅读:
    Java 的 多态和构造方法
    java 的 抽象类、接口
    java 的 封装 、继承
    eclipse的安装和基本使用、面向对象、类和对象
    方法的重载、引用数据类型、 ArrayList集合
    SQL单行函数
    JAVA
    mysql约束
    MYSQL的常用属性
    mysql的索引
  • 原文地址:https://www.cnblogs.com/zfzf1/p/8543266.html
Copyright © 2011-2022 走看看