接口@RequestBody加與不加的區(qū)別
加@RequestBody表是以body[form-data]方式傳遞,一般是傳入?yún)?shù)是類(json方式)需要加,""需要加\"轉(zhuǎn)義,接口接收后會(huì)自動(dòng)反轉(zhuǎn)義,不需要處理。
不加表示默認(rèn)以@Requestparms的方式傳遞,在地址后面會(huì)加?參數(shù)組合方式傳遞,如果參數(shù)中存在""等會(huì)自動(dòng)進(jìn)行編碼轉(zhuǎn)換,接口接收后需要StringEscapeUtils.unescapeHtml()解碼才行。
public ResponseResult queryDetails(@RequestParam("id") Integer id,@RequestParam(value = "inCode",required = false, defaultValue = "") String inCode)
傳入變量前加@RequestParam和傳入變量不加@RequestParam和函數(shù)上方加如下方式是一樣的:
@ApiImplicitParams({@ApiImplicitParam(name = "provinceCode", value = "省級(jí)編碼", dataType = "String", paramType = "query")})
動(dòng)態(tài)路徑參數(shù)傳遞:
@RequestMapping(value = "/infoall/{insId}", method = RequestMethod.GET)
@ApiImplicitParams({@ApiImplicitParam(name = "insId", value = "實(shí)例id", required = true, dataType = "String", paramType = "path"),
@ApiImplicitParam(name = "Status", value = "默認(rèn)傳-1",dataType = "Integer", paramType = "query")})
@ApiOperation(value = "獲得詳情信息", notes = "")
public ResponseResult<Object> getInfoAll(@PathVariable(name = "insId") String insId,@RequestParam(value = "Status", required = false, defaultValue = "0") Integer Status) {
Map map = this.projectInfoService.getInfoAll(insId,Status);
return new ResponseResult<Object>(map);
}
@IgnoreAuth
@GetMapping("/{date}/{fileName:.+}")
@ResponseBody
public ResponseEntity<Resource> show(@PathVariable String fileName, @PathVariable String date) {
try {
return ResponseEntity.ok(new FileSystemResource(uploadPath + "/" + date + "/" + fileName));
} catch (Exception e) {
logger.error("get fileName error:{}", e);
return ResponseEntity.notFound().build();
}
}
還可以看看
其他文章,謝謝您的閱讀。
網(wǎng)站申明:系本文編輯轉(zhuǎn)載,來源于網(wǎng)絡(luò),目的在于傳遞更多信息,并不代表本網(wǎng)贊同其觀點(diǎn)和對其真實(shí)性負(fù)責(zé),所有權(quán)歸屬原作者。如內(nèi)容、圖片有任何版權(quán)問題,請
聯(lián)系我們刪除。