Boa noite,
Estou tentando compilar um código para rodar um simples rest no spring mvc, porém encontrei com o erro "The request sent by the client was syntactically incorrect."
Class Controller
package br.com.aprendendorest.controllers;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import br.com.aprendendorest.models.cliente;
import br.com.aprendendorest.repository.clienteRepository;
@RestController
public class clienteController {
@Autowired
clienteRepository clienteService;
@GetMapping("/cliente")
public ResponseEntity<List<cliente>> listCliente() {
System.out.println("Entro Get");
List<cliente> clientes = clienteService.listAll();
return new ResponseEntity<List<cliente>>(clientes, HttpStatus.OK);
}
@PostMapping("/cliente")
public ResponseEntity<cliente> creatCliente(@RequestBody cliente cli) {
System.out.println("Entro no POST");
System.out.println("ID: " + cli.getId() + ", NOME: " + cli.getNome() + ", EMAIL: " + cli.getEmail());
clienteService.addCliente(cli);
return new ResponseEntity<cliente>(cli, HttpStatus.CREATED);
}
}
Classe Model
package br.com.aprendendorest.models;
public class cliente {
private Integer id;
private String nome;
private String email;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public cliente(int id, String nome, String email) {
this.id = id;
this.nome = nome;
this.email = email;
}
}
POST JSON
{
"id": 5,
"nome": "Marcos",
"email": "teste"
}