• 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));
        }
    
    }
  • 相关阅读:
    MySQL之数据库优化
    cookie和session
    php自动加载
    php函数之strtr和str_replace的区别
    php函数之substr()
    阶段总结(一)
    json和xml
    sqlserver交换数据行中的指定列
    3 宏、条件编译
    5 常量与变量
  • 原文地址:https://www.cnblogs.com/wblade/p/10632002.html
Copyright © 2020-2023  润新知