欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

如何解決SpringMVC同時接收J(rèn)son和Restful時Request里有Map的問題

這篇文章給大家分享的是有關(guān)如何解決SpringMVC同時接收J(rèn)son和Restful時Request里有Map的問題的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

創(chuàng)新互聯(lián)是一家專注于網(wǎng)站設(shè)計、成都網(wǎng)站設(shè)計與策劃設(shè)計,泉州網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)十年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:泉州等地區(qū)。泉州做網(wǎng)站價格咨詢:028-86922220

代碼

Json 數(shù)據(jù)

{
 "fieldMap": 
 {
  "middleName": "1",
  "mailingAddress": "2",
  "mobilenumber": "3" 
 }
}

Restful URL

//注意要讓 @ModelAttribute RequestDTO 自動封裝成 Map 的話要像下面的format。
http://localhost:8080/hello?fieldMap[middleName]=1&fieldMap[mailingAddress]=2&fieldMap[mobilenumber]=3

Request DTO

public class RequestDTO {

 private HashMap<String, String> fieldMap;

 public HashMap<String, String> getFieldMap() {
  return fieldMap;
 }
 public void setFieldMap(HashMap<String, String> fieldMap) {
  this.fieldMap = fieldMap;
 }
}

Spring Mvc 代碼

//接收 Json 數(shù)據(jù), consumes = "application/json" 來區(qū)分同一個請求是用json還是其他
@RequestMapping(method = { RequestMethod.POST },
   value = { "/hello" }, 
   consumes = "application/json")
public final void requestByJson(
  final HttpServletRequest httpRequest,
  final HttpServletResponse httpResponse,
  @RequestBody final RequestDTO requestDTO) {

 ...
}

//接收 Restful 數(shù)據(jù), @ModelAttribute 將param配對成 RequestDTO
@RequestMapping(method = { RequestMethod.POST },
   value = { "/hello" })
public final void restfulRequest(
  final HttpServletRequest httpRequest, 
  final HttpServletResponse httpResponse,
  @ModelAttribute final RequestDTO requestDTO ){

 ...

 }

感謝各位的閱讀!關(guān)于“如何解決SpringMVC同時接收J(rèn)son和Restful時Request里有Map的問題”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

網(wǎng)站欄目:如何解決SpringMVC同時接收J(rèn)son和Restful時Request里有Map的問題
分享鏈接:http://chinadenli.net/article48/jecsep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、自適應(yīng)網(wǎng)站、建站公司、商城網(wǎng)站、定制網(wǎng)站、網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)