Springboot2.1.4+redis+mysql

时间:2022-05-06 10:06:10
【文件属性】:
文件名称:Springboot2.1.4+redis+mysql
文件大小:140KB
文件格式:ZIP
更新时间:2022-05-06 10:06:10
spring @RequestMapping("/testjson") @ResponseBody public Map testjson(String data) throws JSONException { Map map = new HashMap<>(); // String objectStr="{\\\\"username\":\"老李\",\"nickname\":\"李刚\",\"remark\":\"肚痛\"}"; // String basestr = Base64.getBase64(objectStr); String javabean = Base64.getFromBase64(data);//解密 // System.out.println(javabean+"解密后"); JSONObject JSON = JSONObject.parseObject(javabean);//转json String j = JSON.get("data").toString();//根据key获取value // System.out.println(j+"解密后"); JSONObject JSONs = JSONObject.parseObject(j);//value转json SysUser sysUser = JSONs.toJavaObject(SysUser.class);//json转实体类 System.out.println(sysUser.getUsername()+"名字"); return map; } 测试类 package com.example.hello; import com.alibaba.fastjson.JSONObject; import com.example.hello.util.Base64; import com.example.hello.util.HttpClientUtil; import org.junit.Test; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; public class HelloApplicationTests { public static final String baseUrl = "http://localhost:8080/"; @Test public void contextLoads() throws UnsupportedEncodingException { String requestUrl = baseUrl + "testjson"; Map argsMap = new HashMap(); argsMap.put("data", "{'username':'老李','nickname':'李刚','remark':'肚痛'}"); String argsStr = JSONObject.toJSONString(argsMap); System.out.println("加密前"+argsStr); String base = Base64.getBase64(argsStr); argsStr = URLEncoder.encode(base,"utf8"); HttpClientUtil.httpRequest(requestUrl + "?data=" + argsStr, ""); System.out.println("10000000000"); } }

网友评论