欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Spring boot @RequestBody數(shù)據(jù)傳遞過(guò)程詳解

 更新時(shí)間:2019年12月03日 09:51:10   作者:慕塵  
這篇文章主要介紹了Spring boot @RequestBody數(shù)據(jù)傳遞過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

這篇文章主要介紹了Spring boot @RequestBody數(shù)據(jù)傳遞過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

@RequestBody需要接的參數(shù)是一個(gè)string化的json

@RequestBody,要讀取的數(shù)據(jù)在請(qǐng)求體里,所以要發(fā)post請(qǐng)求,還要將Content-Type設(shè)置為application/json

java的api

參數(shù)為JSONObject,獲取到的參數(shù)處理

@PostMapping("/combine")
  public Result combine(@RequestBody JSONObject jsonParam) {
    System.out.println(jsonParam.toJSONString());
    System.out.println(jsonParam.get("fileName"));
    ArrayList ll= (ArrayList)jsonParam.get("ops");
    for(int i = 0;i < ll.size(); i ++){
      ArrayList mm = (ArrayList)ll.get(i);
      for(int j = 0;j < mm.size(); j ++){
        System.out.println(mm.get(j));
      }
    }
    return ResultGenerator.genSuccessResult();
  }

(1)js調(diào)用

var dispatchesDTO = {"fileName":"E:/java/project/ppt/data/tmpTest.pptx","ops":[["E:/java/project/ppt/data/test1.pptx","1,2,9"],["E:/java/project/ppt/data/Threejs動(dòng)畫(huà).pptx","1"],["E:/java/project/ppt/data/系統(tǒng)時(shí)間和實(shí)時(shí)天氣.pptx","1"]]};
$.ajax({
    type: "post", 
    contentType:"application/json", 
  url: "http://localhost:8080/api/ppt/combine", 
  data: JSON.stringify(dispatchesDTO), 
  success: function(data){ 
    console.log(data); 
  }
});

(2)php的curl調(diào)用

<?php
//初始化
$curl = curl_init();
//設(shè)置抓取的url
curl_setopt($curl, CURLOPT_URL, 'http://localhost:8080/api/ppt/combine');
$aa = [
  "fileName" => "E:/java/project/ppt/data/tmp.pptx",
  "ops"   => [['E:/java/project/ppt/data/test1.pptx', '1,2,9'],
    ['E:/java/project/ppt/data/test1.pptx', '2'],
  ],
];
$data_string = json_encode($aa);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
  'Content-Type: application/json',
  'Content-Length: ' . strlen($data_string),
));
//執(zhí)行命令
$data = curl_exec($curl);
//關(guān)閉URL請(qǐng)求
curl_close($curl);
//顯示獲得的數(shù)據(jù)
print_r($data);

(3)postman調(diào)用

參數(shù)

{"fileName":"E:/java/project/ppt/data/tmpTest.pptx","ops":[["E:/java/project/ppt/data/test1.pptx","1,2,9"],["E:/java/project/ppt/data/Threejs動(dòng)畫(huà).pptx","1"]]}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論