Skip to content

📚 Spring Boot 2 Essentials 07 - Método GET #58

Description

@JayCesar

Assim mostra o status da requisição, bom para testes.

  @GetMapping
    public ResponseEntity<List<Anime>> list() {;
        return new ResponseEntity<>(animeService.listAll(), HttpStatus.OK);
        // return ResponseEntity.ok(animeService.listAll()); // outro jeito de fazer
    }

By adding / changing the application to yml extension, I can avoid a stack of errors shows up to the frontend:

On application.yml file:

server:
  error:
    include-stacktrace: never

There are others optiosn to add to include-stacktrace!

AnimeService file:

@Service
public class AnimeService {
    private List<Anime> animes = List.of(new Anime(1L, "Dragon Ball (Test - Build - Hot Swap)"), new Anime(2L, "Bersek"));
    public List<Anime> listAll() {
        return animes;
    }
    public Anime findById(long id) {
        return animes.stream()
                .filter(anime -> anime.getId().equals(id))
                .findFirst()
                .orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "Anime not found"));
    }
}

image

image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions