java - 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;
}
}
解决方案
推荐阅读
- angular - node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts 中的错误
- php - 在 PHP 中向 Datetime 对象添加一微秒
- python - 维护 log.django 文件
- wordpress - 从 Woocommerce 存档页面中删除“类别:”字样
- python - 如何详尽地查看 Django 正在运行的查询?
- sql-server - SQL Server - Management Studio 和自定义应用程序之间的不同功能结果
- sorting - 排序目录文件
- ms-access - MS Access VBA .recordcount 在记录存在时返回 0,并且 debug.print 返回值
- powershell - 如何使用powershell设置密码框的PasswordRevealMode属性[WPF]
- visual-studio - 数据连接器电源查询视觉工作室