我找不到原因为什么......但我随机获得了Http 400,param not present:
Required String parameter 'id' is not present.
我在Postman和不同的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
答案 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);
}
因为我有一些downvotes我无法评论,人们不理解我所说的...所以换句话说它就像这样.. EDITED