[英]Java EE - Return 415 status
I'm creating an WEB Api with Java and Jersey and now i get 415 status code on a POST request to my API. 我正在使用Java和Jersey创建一个WEB Api,现在在对我的API的POST请求中得到415状态代码。
The request made by Postman with the Header Content-type application/json Postman使用标头内容类型application / json发出的请求
These images show my request 这些图像显示了我的要求
And that is my code. 那就是我的代码。
package api;
import java.sql.SQLException;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import DAO.TransactionDAO;
import DAO.UsersDAO;
import Entity.Transaction;
import Entity.Users;
@Path("/users")
public class UsersController {
private UsersDAO dao;
private static final String CHARSET = ";charset=UTF-8";
@PostConstruct
private void init(){
this.dao = new UsersDAO();
}
@POST
@Path("/add")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public int insert(Users user){
try{
return this.dao.add(user);
}
catch(Exception e){
e.toString();
return 0;
}
}
}
I found the error. 我发现了错误。 My model didn't have an empty constructor.
我的模型没有空的构造函数。 I just create it and work.
我只是创建它并工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.