Это мой код: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
;
}
Если предупреждение истинно, как мне получить null от Postman?
edit:
@Repository
публичный интерфейс PlayerRepository расширяет JpaRepository
Long> {
pom.xml
Код: Выделить всё
org.springframework.boot
spring-boot-starter-parent
3.2.5
Подробнее здесь: https://stackoverflow.com/questions/788 ... null-value