Spring HTTP Post方法返回状态代码404
我的maven项目使用hibernate apache cxf spring和backbone.js 我试图用post方法将数据保存到表中,但我总是得到404作为响应代码 我的index.html代码Spring HTTP Post方法返回状态代码404,spring,http-status-code-404,spring-restcontroller,Spring,Http Status Code 404,Spring Restcontroller,我的maven项目使用hibernate apache cxf spring和backbone.js 我试图用post方法将数据保存到表中,但我总是得到404作为响应代码 我的index.html代码 var departmentNameModel=Backbone.Model.extend({ urlRoot:"/rest/departmentName", defaults:{ departmentName:"Boş"
var departmentNameModel=Backbone.Model.extend({
urlRoot:"/rest/departmentName",
defaults:{
departmentName:"Boş"
}
});
var departmentNameView=Backbone.View.extend({
tagName:"tr",
template:"<td><span>{{departmentName}}</span><input type='text' value='{{departmentName}}' style='width:190px; display:none;' /><button class='btn btn-danger btn-mini' style='float:right;'>Sil</button> </td>",
model: {},
events:{
"dblclick span":"duzenlemeModu",
"blur input":"duzenle",
"click button":"sil"
},
duzenlemeModu:function(){
this.$el.find("input").css("display","");
this.$el.find("span").css("display","none");
},
duzenle:function(){
this.model.save("departmentName",this.$el.find("input").val());
this.render();
this.$el.find("input").css("display","none");
this.$el.find("span").css("display","");
},
sil:function(){
this.model.destroy();
this.remove();
},
render: function(){
var html= Mustache.to_html(this.template,this.model.toJSON());
$(this.el).html(html);
return this;
}
});
var AppView=Backbone.View.extend({
el: $("body"),
events:{
"keypress #departmentName":"kaydet"
},
kaydet:function(evt){
if(evt.keyCode!==13) return;
var departmentNameeModel=new departmentNameModel();
departmentNameeModel.set("departmentName",$("#departmentName").val());
departmentNameeModel.save();
var departmentNameeView=new departmentNameView();
departmentNameeView.model=departmentNameeModel;
$("table").append(departmentNameeView.render().el);
$("#departmentName").val("");
}
});
var apppView = new AppView();
</script>
</body>
</html>
我在截图上分享了我的错误。对不起,我的英语不好。我希望我能告诉你这个问题
谢谢你的回答 至少我可以看到您的@Path(“/department”)和urlRoot:“/rest/departmentName”不匹配。这可能就是您收到404(未找到)错误消息的原因。尝试匹配urlRoot和@Path模式,看看这是否有帮助
提示:我建议在尝试调试.html文件中的服务调用404响应问题之前,使用postman chrome插件测试您的服务,以确保Rest服务工作正常。希望这有帮助 您使用的是没有MVC模块的Spring框架吗?是的,我没有使用SpringMVC我使用Backbone.js进行分层架构我尝试了您的建议,但仍然存在以下错误:(.我的apache cxf url模式/rest/*所以我的webapp正在运行/rest/
@Component
@Path("/department")
public class DepartmentResource {
@Autowired
private DepartmentService departmentService;
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public DepartmentDTO save(DepartmentDTO dto) {
//dto.setDepartmentName();
return departmentService.save(dto);
}