• Restclient


    package com.xjj;
    
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import org.junit.Test;
    
    import com.fasterxml.jackson.core.JsonProcessingException;
    import com.xjj.web.controller.LoginObj;
    
    import net.minidev.json.JSONObject;
    
    public class RestClient extends CMERestClient {
    
        String url = "http://localhost:8082/api/admin/login2";
    
        @Test
        public void object() {
    
            Map<String, String> a = new HashMap<>();
    
            a.put("userName", "ff");
            a.put("password", "fff");
    
            String jsr = JSONObject.toJSONString(a);
    
            LoginObj ss = processRestJson(url, jsr, LoginObj.class);
    
            System.out.println("jsonReturn is: " + objToJSONString(ss));
        }
        
        @Test
        public void object2() {
    
            Map<String, String> a = new HashMap<>();
    
            a.put("userName", "ff");
            a.put("password", "fff");
    
            String jsr = JSONObject.toJSONString(a);
    
            Object ss = processRestJsonObj(url, a, Map.class);
            Object mapList = restTemplate.postForObject(url, a, Map.class);
    
            System.out.println("jsonReturn is: " + objToJSONString(ss));
        }
        @Test
        public void jsonObject() throws JsonProcessingException {
    
            String jsonStr2 = "{"userName": "fff", "password": "oooo"}";
    
            JSONObject ss2 = processRestJson2(url, jsonStr2);
            
            Map<String, String> a = new HashMap<>();
    
            a.put("userName", "ff");
            a.put("password", "fff");
    
            String jsr = JSONObject.toJSONString(a);
    
            Object ss = restTemplate.postForObject(url, ss2, Map.class);
            System.out.println("jsonReturn is: " + objToJSONString(ss2));
        }
    
        // @Test
        public void list() throws Exception {
    
            String url = "http://localhost:8082/api/admin/login3";
    
            String jsonStr2 = "{"userName": "fff", "password": "oooo"}";
    
            List<LoginObj> r = processRestJsonList(url, jsonStr2, LoginObj.class);
    
            System.out.println("jsonReturn is: " + objToJSONString(r));
        }
    
        @Test
        public void listMap() throws Exception {
    
            String url = "http://localhost:8082/api/admin/login3";
    
            String jsonStr2 = "{"userName": "fff", "password": "oooo"}";
    
            List<HashMap> r = processRestJsonList(url, jsonStr2, HashMap.class);
    
            System.out.println("jsonReturn is: " + objToJSONString(r));
        }
    
        @Test
        public void listJSON() throws Exception {
    
            String url = "http://localhost:8082/api/admin/login3";
    
            JSONObject result = new JSONObject();
            result.put("userName", "HT");
            result.put("password", "30");
    
            List<JSONObject> r = processRestJsonList(url, result.toJSONString(), JSONObject.class);
    
            System.out.println("jsonReturn is: " + objToJSONString(r));
        }
    
    }
  • 相关阅读:
    HTTP 501 错误 – 未实现 (Not implemented) 或者是 Failure: Address already in use
    HTTP 400 Bad request 原因
    树莓派 NAS aria2 下载磁力链接无速度
    踩坑备忘之“yarn : 无法加载文件 C:\Users\siazon\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行脚本。"
    架构小试之IDL
    服务端基本概念和指标
    git常用命令
    mysql20211116
    blog JavaJinguo
    android 分享功能
  • 原文地址:https://www.cnblogs.com/wblade/p/10632002.html
Copyright © 2020-2023  润新知