簡體   English   中英

java.lang.IllegalStateException:找不到類 com.domain.Profile 所需的標識符屬性! - 蒙戈,SpringBoot

[英]java.lang.IllegalStateException: Required identifier property not found for class com.domain.Profile! - Mongo, SpringBoot

我在我的項目中使用 SpringBoot 和 Mongo。

我有一個看起來像這樣的Profile模型。

@Data
@Document
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Profile {
    private String birthDate;
    private Stirng city;
    private String country;  
}

我可以通過郵遞員將它添加到 Mongo,但是當我嘗試通過Id從 Mongo 中delete它時,出現以下錯誤。

java.lang.IllegalStateException: Required identifier property not found for class com.domain.Profile!

這是 deleteById 方法。

 @DeleteMapping(value = "/{profileId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> deleteById(@PathVariable String profileId) {
        if (profileRepository.existsById(profileId)) {
            profileRepository.deleteById(profileId);
            return new ResponseEntity<>("Profile properly deleted.",HttpStatus.OK);
        } else {
            return new ResponseEntity<>("Profile not found.", HttpStatus.NOT_FOUND);
        }
    }

我像這樣使用Postman

在此處輸入圖片說明

我在這里缺少什么?

嘗試這個,

在此處輸入圖片說明

其中 23 是 profileId

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM