zoukankan      html  css  js  c++  java
  • RestTemplate invoke JSON and convert to Object

    @Test
        public void webTest() throws JsonProcessingException {
    
            Map<String, String> a = new HashMap<>();
    
            a.put("userName", "ff");
            a.put("password", "fff");
    
            ObjectMapper b = new ObjectMapper();
    
            String as = b.writeValueAsString(a);
    
            HttpHeaders headers2 = new HttpHeaders();
            MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
            headers2.setContentType(type);
            headers2.add("Accept", MediaType.APPLICATION_JSON.toString());
    
            HttpEntity<String> entity = new HttpEntity<String>(as, headers2);
    
            Object ss = restTemplate.postForObject("http://localhost:" + port + "/api/admin/login2", entity, Object.class);
            System.out.println("port is: " + port);
        }
  • 相关阅读:
    html常用标签_new
    Nginx缓存
    购物车
    css的属性选择
    前端基础之css
    htm基础知识
    TypeScript(1)为什么需要TypeScript
    Electron
    Ant Design
    Umi
  • 原文地址:https://www.cnblogs.com/wblade/p/10625191.html
Copyright © 2011-2022 走看看