지금은이 문제가 내가 도움을 요청하고 싶은, 내가 테 값을 ACESS 수 없습니다 dto.getIdCliente()
, 그러나 이것은을 위해 JSON처럼 전달됩니다 ServicoPrestadoDTO dto
. 아래 코드 ...
ServicoPrestadoController.java :
@RestController
@RequestMapping("/api/servicos-prestados")
@RequiredArgsConstructor
public class ServicoPrestadoController {
private final ClienteRepository clienteRepository;
private final ServicoPrestadoRepository servicoPrestadoRepository;
private final BigDecimalConverter bigDecimalConverter;
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public ServicoPrestado salvar(@RequestBody ServicoPrestadoDTO dto){
LocalDate data = LocalDate.parse(dto.getData(), DateTimeFormatter.ofPattern("dd/MM/yyyy"));
Integer idCliente = dto.getIdCLiente();
Cliente cliente =
clienteRepository.findById(idCliente)
.orElseThrow(() ->
new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cliente não encontrado!"));
ServicoPrestado servicoPrestado = new ServicoPrestado();
servicoPrestado.setDescricao(dto.getDescricao());
servicoPrestado.setData(data);
servicoPrestado.setCliente(cliente);
servicoPrestado.setValor(bigDecimalConverter.converter(dto.getPreco()));
return servicoPrestado;
}
@GetMapping
public List<ServicoPrestado> pesquisar(
@RequestParam(value = "nome", required = false) String nome,
@RequestParam(value = "mes", required = false) Integer mes
){
return servicoPrestadoRepository.findByNomeClienteAndMes("%" + nome + "%", mes);
}
}
ServicoPrestadoDTO.java :
@Data
@NoArgsConstructor
public class ServicoPrestadoDTO {
private String descricao;
private String preco;
private String data;
private Integer idCLiente;
}
ServicoPrestado.java :
@Entity
@Data
public class ServicoPrestado {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false, length = 150)
private String descricao;
@ManyToOne
@JoinColumn(name = "id_cliente")
private Cliente cliente;
@Column
private BigDecimal valor;
@Column
@JsonFormat(pattern = "dd/MM/yyyy")
private LocalDate data;
}
나는 왜 servico
내 servico-prestado-form.ts
같은 JSON으로 보내지 않는지 이해하지 못합니다 .