接口@RequestBody加与不加的区别
加@RequestBody表是以body[form-data]方式传递,一般是传入参数是类(json方式)需要加,""需要加\"转义,接口接收后会自动反转义,不需要处理。
不加表示默认以@Requestparms的方式传递,在地址后面会加?参数组合方式传递,如果参数中存在""等会自动进行编码转换,接口接收后需要StringEscapeUtils.unescapeHtml()解码才行。
public ResponseResult queryDetails(@RequestParam("id") Integer id,@RequestParam(value = "inCode",required = false, defaultValue = "") String inCode)
传入变量前加@RequestParam和传入变量不加@RequestParam和函数上方加如下方式是一样的:
@ApiImplicitParams({@ApiImplicitParam(name = "provinceCode", value = "省级编码", dataType = "String", paramType = "query")})
动态路径参数传递:
@RequestMapping(value = "/infoall/{insId}", method = RequestMethod.GET)
@ApiImplicitParams({@ApiImplicitParam(name = "insId", value = "实例id", required = true, dataType = "String", paramType = "path"),
@ApiImplicitParam(name = "Status", value = "默认传-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();
}
}