Spring Boot. how to Pass Optional<> to an Entity Class

前端 未结 7 1644
予麋鹿
予麋鹿 2021-02-13 16:06

i am currently making a website using spring and i stumble upon this basic scenario that i don\'t have any idea on how to solve this specific code: Entity = Optional;

         


        
7条回答
  •  无人及你
    2021-02-13 17:03

    According to your error you are getting Optional from repository's findAll method and you are casting it to RoomEntity.

    Instead of RoomEntity roomEntity = roomRepository.findById(roomId); do this

    Optional optinalEntity = roomRepository.findById(roomId); RoomEntity roomEntity = optionalEntity.get();

提交回复
热议问题