![](/img/trans.png)
[英]Errai JAX-RS - No resource method found for POST, return 405 with Allow header
[英]JAX-RS 405 Method not allowed
我的JAX-RS GET函数运行良好。 我现在正在使用我的POST方法,但这一直给我405错误。 我的资源指向我的DAO。
我的代码有问题吗?
资源
@POST
@Path("/insert")
public void insertIngredient(@QueryParam("Q1") int hoeveelheid, @QueryParam("Q2") String datum,@QueryParam("Q3") String ingredientnaam , @QueryParam("Q4") String gebruikersnaam) {
IngredientService service = ServiceProvider.getIngredientService();
service.insertIngredient(hoeveelheid, datum, ingredientnaam, gebruikersnaam);
}
DAO
public void insertIngredient(int hoeveelheid, String datum, String ingredientnaam, String gebruikersnaam) {
try (Connection con = super.getConnection()) {
Statement stmt = con.createStatement();
ResultSet nextId = stmt.executeQuery("SELECT MAX(dagboek_id) FROM dagboek");
int maxId = nextId.getInt("dagboek_id") + 1;
stmt.executeQuery("insert into dagboek(dagboek_id, hoeveelheid, datum, fk_ingredientnaam, fk_gebruikersnaam) values('"+maxId+"','" + hoeveelheid + "','" + datum + "','" + ingredientnaam + "','" + gebruikersnaam + "')");
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
不允许使用HTTP 405方法意味着您获得了正确的终结点,但是没有获得正确的http方法。 它与端点的实现无关。 要检查的常见潜在问题是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.