springboot调用http方式


1.httpclient

2.okhttp

3.feign

安装Gradle包

compile 'org.springframework.cloud:spring-cloud-starter-openfeign:2.0.2.RELEASE'

代码示例

@SpringBootApplication
@EnableFeignClients
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

 

@Service
@FeignClient(name = "httpService", url = "${url}")
public interface IHttpService {

    @RequestMapping(value = "test/register", method = RequestMethod.POST, headers = "Accept=application/json", produces = "application/json;charset=UTF-8")
    String add(@RequestBody RequestTestBody body);

    @RequestMapping(value = "register/{name}", method = RequestMethod.PUT)
    String update(@PathVariable("name") String name, @RequestBody RegisterDto body);

    @RequestMapping(value = "test123/{name}", method = RequestMethod.DELETE)
    String delete(@PathVariable("name") String name);
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM