2
I’m running some tests on Spring to return error 404 in case he doesn’t find one id
when searching in Repository, but is giving 200 OK.
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<?> buscar(@PathVariable("id") Long id) {
Optional<Livro> livro = livrosRepository.findById(id);
if(livro == null) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.status(HttpStatus.OK).body(livro);
}`
Does anyone know what might be going on?
How about changing if para if(!livro.isPresent())? Your book attribute is an Optional, and most likely it is not null.
– Tom Melo