我目前正在使用spring创建一个网站,我偶然发现了这个基本场景,我对如何解决这个特定代码一无所知:Entity = Optional;
RoomEntity roomEntity = roomRepository.findById(roomId);
Run Code Online (Sandbox Code Playgroud)
ReservationResource(API请求类):
public class ReservationResource {
@Autowired
RoomRepository roomRepository;
@RequestMapping(path = "/{roomId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RoomEntity> getRoomById(
@PathVariable
Long roomId){
RoomEntity roomEntity = roomRepository.findById(roomId);
return new ResponseEntity<>(roomEntity, HttpStatus.OK);}
}}
Run Code Online (Sandbox Code Playgroud)
RoomRepository类:
public interface RoomRepository extends CrudRepository<RoomEntity, Long> {
List<RoomEntity> findAllById(Long id);
}
Run Code Online (Sandbox Code Playgroud)
RoomEntity
@Entity
@Table(name = "Room")
public class RoomEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotNull
private Integer roomNumber;
@NotNull
private String price;
public RoomEntity() {
super();
} …Run Code Online (Sandbox Code Playgroud) 当我执行 tns run ios 时,一切都很好,但是 tns run android 只是给了我这样的错误。我尝试了设备和模拟器,但结果相同。
我已经做好了:
错误代码:
Installing on device 2744b499...
Successfully installed on device with identifier '2744b499'.
Application org.nativescript.fagck_app is not running on device 2744b499.
This issue may be caused by:
* crash at startup (try `tns debug android --debug-brk` to check why it crashes)
* different application …Run Code Online (Sandbox Code Playgroud)