• 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();
    	}
    }
    

      

  • 相关阅读:
    USACO 2008 Mar Silver 3.River Crossing 动态规划水题
    常见经验总结
    Ikki's Story IV
    洛谷P1993 小K的农场_差分约束_dfs跑SPFA
    洛谷P3275 [SCOI2011]糖果_差分约束_判负环
    Integer Intervals POJ
    洛谷 P2365 任务安排_代价提前计算 + 好题
    [NOI2005]瑰丽华尔兹 动态规划 + 单调队列
    Shoot the Bullet ZOJ
    background-clip 和 background-origin
  • 原文地址:https://www.cnblogs.com/zfzf1/p/8543266.html
Copyright © 2020-2023  润新知