首页 > 解决方案 > Java POST - 客户端发送的请求在语法上不正确

问题描述

这是我第一次在 java 中编写 rest 服务并且我有一个 400 问题,它说

客户端发送的请求在语法上不正确

我在邮递员中发送了正确的格式,但我不确定我的错误是在我的代码级别还是在邮递员中

这是我的模型

public class Model {

private int id;
private String descripcion;
private double precio;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getDescripcion() {
    return descripcion;
}

public void setDescripcion(String descripcion) {
    this.descripcion = descripcion;
}

public double getPrecio() {
    return precio;
}

public void setPrecio(double precio) {
    this.precio = precio;
}
}

这是我的通用响应

@Path("generic")
public class GenericResource {

@Context
private UriInfo context;

public GenericResource() {
}

static final List<Model> lista = new ArrayList<>();

@GET
@Path("listar")
@Produces("application/json")
public List<Model> listarProductos(){
    return lista;
}

@POST
@Path("guardar")
@Produces("application/json")
@Consumes(MediaType.APPLICATION_JSON)
public List<Model> guardar(Model m){
    lista.add(m);
    return lista;
}
}

这就是邮递员和响应中的内容 在此处输入图像描述

标签: javarestpostjava-8

解决方案


推荐阅读