У меня появляется это сообщение об ошибке, когда я пытаюсь опубликовать и применить метод к пациентам, но метод работает для меня.
"error": "Unsupported Media Type", "message": "Content type 'application / json; charset = UTF-8 'not supported ",
Думаю, проблема с @JsonBackReference. когда я удаляю @JsonBackReference, у меня появляется это сообщение об ошибке, когда я пытаюсь получить метод: Произошла ошибка синтаксического анализа JSON данные
Неожиданный конец JSON ввод
код здесь
класс пациенты
@Entity
public class Patient {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id_pat;
private Integer cin_pat;
private String fname_pat;
private String lname_pat;
private String sexe_pat;
@Temporal(javax.persistence.TemporalType.DATE)
private Date date_naissance_pat;
private String ville_pat;
private String poid_pat;
private String mail_pat;
private Integer num_tel_pat;
private String adress_pat;
private String remarque_pat;
private String malade_pat;
private String medicament_pat;
@Temporal(javax.persistence.TemporalType.DATE)
private Date der_soin_pat;
private String mot_de_passe_pat;
@OneToMany(cascade = CascadeType.ALL, mappedBy="patient", orphanRemoval = true)
private List<Rdv> Rdvs;
public Patient(){
}
public Patient(Integer id_pat, Integer cin_pat, String fname_pat, String lname_pat, String sexe_pat, Date date_naissance_pat, String ville_pat, String poid_pat, String mail_pat, Integer num_tel_pat, String adress_pat, String remarque_pat, String malade_pat, String medicament_pat, Date der_soin_pat, String mot_de_passe_pat) {
this.id_pat = id_pat;
this.cin_pat = cin_pat;
this.fname_pat = fname_pat;
this.lname_pat = lname_pat;
this.sexe_pat = sexe_pat;
this.date_naissance_pat = date_naissance_pat;
this.ville_pat = ville_pat;
this.poid_pat = poid_pat;
this.mail_pat = mail_pat;
this.num_tel_pat = num_tel_pat;
this.adress_pat = adress_pat;
this.remarque_pat = remarque_pat;
this.malade_pat = malade_pat;
this.medicament_pat = medicament_pat;
this.der_soin_pat = der_soin_pat;
this.mot_de_passe_pat = mot_de_passe_pat;
}
// Getters & Setters
}
контроллер пациента
@RestController
public class PatientController {
@Autowired
PatientService patientService;
@GetMapping("/patients")
private List<Patient> getAllPatients() {
return patientService.getAllPatients();
}
@GetMapping("/patients/{id_pat}")
private Patient getPatient(@PathVariable("id_pat") Integer id_pat){
return patientService.getPatientById(id_pat) ;
}
@PostMapping("/patients")
public void addPatient(@RequestBody Patient patient){
patientService.addPatient(patient);
}
@PutMapping("/patients/{id_pat}")
public void upatePatient (@RequestBody Patient patient, @PathVariable String id_pat){
patientService.updatePatient(id_pat, patient);
}
@DeleteMapping("/patients/{id_pat}")
private void deletePatient(@PathVariable("id_pat") Integer id_pat){
patientService.delete(id_pat);
}
}
служба пациента
@Service
public class PatientService {
@Autowired
private PatientRepository patientRepository;
public List<Patient> getAllPatients() {
List<Patient> patients = new ArrayList<Patient>();
patientRepository.findAll().forEach(patient-> patients.add(patient));
return patients;
}
public Patient getPatientById(Integer id_pat){
return patientRepository.findById(id_pat).get();
}
public void addPatient(Patient patient) {
patientRepository.save(patient);
}
public void updatePatient(String id_pat, Patient patient){
patientRepository.save(patient);
}
public void delete(Integer id_pat){
patientRepository.deleteById(id_pat);
}
}
объект rdv
@Entity
public class Rdv {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id_rdv;
@Temporal(javax.persistence.TemporalType.DATE)
private Date date_rdv;
private Time time_rdv;
@JsonBackReference
@ManyToOne( fetch = FetchType.LAZY)
@JoinColumn(name = "id")
private Medecin medecin;
@JsonBackReference
@ManyToOne( fetch = FetchType.LAZY)
@JoinColumn(name = "id_pat")
private Patient patient;
public Rdv() {}
public Rdv(Integer id_rdv, Date date_rdv, Time time_rdv, Integer id, Integer id_pat) {
this.id_rdv = id_rdv;
this.date_rdv = date_rdv;
this.time_rdv = time_rdv;
this.medecin = new Medecin(id, "", "", "", null, "", "", "");
this.patient = new Patient(id_pat, null, "", "", "", null, "", null, "", null, "", "", "", "", null, "");
}
// Getters & Setters
}
хранилище пациентов
public interface PatientRepository extends JpaRepository<Patient, Integer> {
}
репозиторий rdv
public interface SecretaireRepository extends JpaRepository<Secretaire, Integer>{
public List<Secretaire> findByMedecinId(Integer id);
}