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);

      }

    }

      

  • 相关阅读:
    ADB 多设备中指定设备的启动
    vuex 绑定表单,多个输入框的解决办法
    vue 自动触发点击事件
    js 打印dom的所有属性
    邮件分享
    table表格 td设置固定宽度
    Echarts--Y坐标标题显示不全
    ExtJS5.0 菜鸟的第一天
    字体设置
    短信验证码+倒计时
  • 原文地址:https://www.cnblogs.com/jiehanshi/p/11634051.html
Copyright © 2011-2022 走看看