zoukankan      html  css  js  c++  java
  • RestTemplate调用

    一、get请求
    public class TestController{
        @Autowired
        RestTemplate restTemplate;
    
        public void getlist(String a,String b) {
           ResponseEntity<ResultVO<List<TClNew>>> result = restTemplate.exchange("http://192.168.1.1/server/getlist/{a}/{b}", HttpMethod.GET, null,
                    new ParameterizedTypeReference<ResultVO<List<test>>>() {
                    }, a, b);
         }
    }  

    二、get请求

    public class TestController{
        @Autowired
        RestTemplate restTemplate;
    
           public ResultVO<String> getlist(String a,String b) {
               return restTemplate.getForObject("http://192.168.1.1/server/getlist/{a}/{b}", ResultVO.class, a,  b);
        }
    }  
    

      

    三、post请求

    public class TestController{
        @Autowired
        RestTemplate restTemplate;
    
      public void post(){
       HttpHeaders headers = new HttpHeaders();
       Map<String, Object> map = new HashMap<>();
        map.put("aaa", "qqqq");
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(map, headers);
        ResponseEntity<ResultVO<String>> response = restTemplate.exchange(url, HttpMethod.POST, httpEntity,
        new ParameterizedTypeReference<ResultVO<String>>() {
        });
    
      }
    
    } 
    

     四、post请求

    public class TestController{
        @Autowired
        RestTemplate restTemplate;
    
        public ResultVO<String> getlist(String a,String b) {
          List<TestEntity> aaa = new ArrayList<>();
          return restTemplate.postForObject("http://192.168.1.1/server/post", aaa, ResultVO.class);

      }

    }

      

  • 相关阅读:
    30 Day Challenge Day 20 | Leetcode 938. Range Sum of BST
    30 Day Challenge Day 20 | Leetcode 124. Binary Tree Maximum Path Sum
    30 Day Challenge Day 20 | Leetcode 94. Binary Tree Inorder Traversal
    idea2019版本破解
    xml文件时第一行无缘无故报错
    activeMQ的基本使用
    activeMQ的安装(Linux下)
    redis的基本用法
    redis安装(Linux下)
    redis安装(window下)
  • 原文地址:https://www.cnblogs.com/jiehanshi/p/11634051.html
Copyright © 2011-2022 走看看