Handling empty results on findAll(): Is there a orElseThrow() for lists?
问题 I am creating a little Spring REST service. I have a findById() call: @GetMapping("/items/{id}") MyItem one(@PathVariable String id) { return repository.findById(id).orElseThrow(() -> new MyItemNotFoundException(id)); } If there is no MyItem object with the given id , I am throwing an exception using the Optional<T>.orElseThrow() method. This is very useful and quite simple. Now I added a findAll() call from the PagingAndSorting<T, ID> repository: @GetMapping("/items") List<MyItem> all() {