[英]Spring boot - Rest Service - Getting random HTTP status 400
我找不到原因。。。但是我隨機得到Http 400,參數不存在:
Required String parameter 'id' is not present.
我在郵遞員和其他Rest Client中得到這個,
這是我的代碼:
@RequestMapping(path = "/borrower", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@CrossOrigin(origins = "*")
public ResponseEntity<?> borrower(@RequestParam(value = "id") String cuit, @RequestHeader("Authorization") String token) throws Exception {
// some business code
return ResponseEntity.ok().build();
}
我正在使用Spring Boot 2.0.1
如果您這樣嘗試怎么辦?
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<?> getStuff(@PathVariable("id") long id) {
//the long id defined is the variable passed when making the petition through postman
Entity entity = entityService.getById(id);
//for the entity it is supposed to be your model, and service
if (entity == null) {
return new ResponseEntity<ErrorDTO>(new ErrorDTO(
// the ErrorDTO is a file where you get all the descriptions
"did not find any id " + id), HttpStatus.NOT_FOUND);
}
return new ResponseEntity<Entity>(entity, HttpStatus.OK);
}
因為我有一些反對意見,所以我無法發表評論,人們也聽不懂我說的話。換句話說,它像這樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.