У меня есть бэкэнд из приложения весенней загрузки с REST, с отображением один ко многим. Я хочу назначить Пациенту попечителя, для этого мне нужно отправить оба идентификатора, чтобы я мог найти элементы. Фронтенд является реагирующим js и axios
страница реакции
import React, { Component } from 'react'
import CaregiverApiService from "../../service/CaregiverApiService";
class AddRelationCaregiverPatient extends Component{
constructor(props){
super(props);
this.state ={
idPac:'',
idCare:'',
message: null
}
this.getOne = this.getOne.bind(this);
}
getOne = (e) => {
e.preventDefault();
let rel = {idPac: this.state.idPac, idCare: this.state.idCare};
console.log(rel);
const { idPac, idCare } = this.state;
CaregiverApiService.getOne(idPac,idCare)
.then(res => {
this.setState({message : 'Caregiver added successfully.'});
this.props.history.push('/patients');
});
}
onChange = (e) =>
this.setState({ [e.target.name]: e.target.value });
render() {
return(
<div>
<h2 className="text-center">Add Caregiver</h2>
<form>
<div className="form-group">
<label>Caregiver Name:</label>
<input type= "number" placeholder="idPac" name="idPac" className="form-control" value={this.state.idPac} onChange={this.onChange}/>
</div>
<div className="form-group">
<label>Surname:</label>
<input type="number" placeholder="idCare" name="idCare" className="form-control" value={this.state.idCare} onChange={this.onChange}/>
</div>
<button className="btn btn-success" onClick={this.getOne}>Save</button>
</form>
</div>
);
}
}
export default AddRelationCaregiverPatient;
Запрос API, который я пытался сделать
getOne(idPac,idCare)
{
return axios.put(CAREGIVER_PACIENT_API_BASE_URL+'/'+idCare+ '/'+idPac);
}
Бэкэнд
@RestController
@CrossOrigin
@RequestMapping(value = "/caregiver_patient")
public class caregiver_patientController {
@Autowired
private CaregiverService careService;
@Autowired
private PatientService patService;
@PutMapping("/{id}/{id}")
public ApiResponse<Patient> getOne(@PathVariable int idCare,@PathVariable int idPat){
PatientViewDTO pp= patService.findPatientByIdPatient(idPat);
CaregiverViewDTO cc=careService.findCaregiverByIdCaregiver(idCare);
pp.setCaregiver_idCaregiver(CaregiverViewBuilder.generateEntityFromDTO(cc));
Patient pat=PatientViewBuilder.generateEntityFromDTO(pp);
PatientDTO ppat= PatientBuilder.generateDTOFromEntity(pat);
patService.update(ppat);
return new ApiResponse<>(HttpStatus.OK.value(), "Patient fetched successfully.",ppat);
}
//
}
Я получаю сообщение об ошибке и не могу найти решение этой проблемы "HTTP400: ПЛОХОЙ ЗАПРОС - запрос не может быть обработан сервером из-за неверного синтаксиса. (XHR) ОПЦИИ - http://localhost:8080/caregiver-patient/[object Объект] /[объект Объект] "Спасибо!