controller 接收json

@ResponseBody
@RequestMapping(value = “/request/data”, method = RequestMethod.POST, produces = “application/json;charset=UTF-8”)
public String getByRequest(HttpServletRequest request) {

    //獲取到JSONObject
    JSONObject jsonParam = this.getJSONParam(request);

    // 將獲取的json數據封裝一層,然後在給返回
    JSONObject result = new JSONObject();

    result.put("msg", "ok");
    result.put("method", "request");
    result.put("data", jsonParam);
    System.out.print(result);
    return result.toJSONString();
}

public JSONObject getJSONParam(HttpServletRequest request){
JSONObject jsonParam = null;
try {
// 獲取輸入流
BufferedReader streamReader = new BufferedReader(new InputStreamReader(request.getInputStream(), “UTF-8”));

        // 寫入數據到Stringbuilder
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = streamReader.readLine()) != null) {
            sb.append(line);
        }
        jsonParam = JSONObject.parseObject(sb.toString());
        // 直接將json信息打印出來
        System.out.println(jsonParam.toJSONString());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return jsonParam;
}

測試地址:http://qq1012822599.cn:8888/findAllLog
QQ:1012822599 跳過安全效驗(java,python)
自動登錄,無需掃碼和輸入用戶名、密碼
1、全天候 7*24 自動監控收款,自動將即時到帳的交易反饋到網站接口或者數據庫
2、輕鬆實現支付寶即時到賬接口的功能,省去了人工一一對賬再加款操作的麻煩
3、成功地解決了中、小企業及非企業支付,手續費昂貴等問題
在這裏插入圖片描述
在這裏插入圖片描述在這裏插入圖片描述在這裏插入圖片描述
測試地址:http://qq1012822599.cn:8888/findAllLog
QQ:1012822599

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章