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