1
我遵循this tutorial來構建Spring Boot的REST API。我已經運行並響應了我的呼叫,但是它顯示的信息存在問題。當我問一個條目,我希望沿着Spring Boot REST API - 顯示信息的問題
{
"id": 1,
"name": "petName",
"photo": "meh",
"status": "Meh"
},
線的東西而是我得到
{
"id": 1,
"photo": "meh",
"status": "Meh"
},
,我一點兒也不知道爲什麼。
RestController
@RestController
@RequestMapping("/pet")
class PetRestController {
private final PetRepo petRepo;
@RequestMapping(value="/{petId}", method = RequestMethod.GET)
Pet getPet(@PathVariable Long petId) {
return this.petRepo.findOne(petId);
}
@RequestMapping(value="/all", method = RequestMethod.GET)
List<Pet> getPets() {
return this.petRepo.findAll();
}
@RequestMapping(value="/delete/{petId}", method = RequestMethod.DELETE)
void deletePet(@PathVariable Long petId) {
this.petRepo.delete(petId);
}
@RequestMapping(value="/add", method = RequestMethod.POST)
void addPet(@RequestParam String name, @RequestParam String photo, @RequestParam String status) {
Pet pet = new Pet(name, photo, status);
this.petRepo.save(pet);
}
@Autowired
PetRestController(PetRepo petRepo){
this.petRepo = petRepo;
}
}
Pet.java
@Entity
public class Pet {
@Id
@GeneratedValue
private Long id;
public Long getId() {
return id;
}
public String getName() {
return name;
}
public String getPhoto() {
return photo;
}
public String getStatus() {
return status;
}
@JsonIgnore
public String name;
public String photo;
public String status;
public Pet(String name, String photo, String status) {
this.name = name;
this.photo = photo;
this.status = status;
}
Pet() {
}
}
人有什麼想法?
哎呀,錯過了那一個。謝謝。現在工作 –