Получите идентификатор в URL-адресе PostMapping с помощью PathVariable.
@PostMapping(value = "/{id}")
public PagamentoGuia create(@RequestBody PagamentoGuia pagamentoGuia, @PathVariable(value = "id") Long id) {
GuiaRecolhimento g = repositoryGuia.getOne(id);
pagamentoGuia.setGuia(g);
return repository.save(pagamentoGuia);
}
Редактировать: я согласен с Matheus Cirillo
За вами следуют правильные semanti c согласно шаблонам REST вы можете использовать объект DTO.
public class PagamentoGuiaDto {
private Long guiaRecolhimentoId;
// all attributes of PagamentoGuiaDto
// all getters and setters
}
@PostMapping
public PagamentoGuia create(@RequestBody PagamentoGuiaDto dto) {
GuiaRecolhimento g = repositoryGuia.getOne(dto.getPagamentoGuiaId());
PagamentoGuia pagamentoGuia = new PagamentoGuia();
pagamentoGuia.setGuia(g);
// set the values of dto to pagamentoGuia
return repository.save(pagamentoGuia);
}