Это мой код:PlayerController.java
Код: Выделить всё
@GetMapping("/{id}")
public Optional
getPlayer(@PathVariable Long id) {
return playerService.getPlayerById(id);
}
Код: Выделить всё
public interface PlayerService {
List
getAllPlayers();
Optional getPlayerById(Long id);
}
Код: Выделить всё
@Override
public Optional
getPlayerById(Long id) {
return playerRepository.findById(id);
}

Я затем попробовал проверить, имеет ли объект игрока значение null, чтобы вернуть какое-то сообщение, например:
Код: Выделить всё
@Override
public Optional
getPlayerById(Long id) {
Optional player = playerRepository.findById(id);
if (player == null) { // warning
//some message
;
}
Если предупреждение истинно, как мне получить ноль от Почтальона?
Подробнее здесь: https://stackoverflow.com/questions/788 ... null-value
Мобильная версия