HTTP POST方法returnin响应代码状态码404

问题描述:

使用Hibernate的Apache CXF春天和Backbone.js的 我想保存的数据与交method.But表我的Maven项目我总是得到404。HTTP POST方法returnin响应代码状态码404

我的index.html代码

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> 

和我cxfservlet的url-pattern是/ 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); 
     } 

我分享我的错误上抓住我的英语不好。我希望我能告诉你这个问题。

谢谢解答!

+0

您正在使用未经MVC模块Spring框架? –

+0

是的,我没有使用我使用Backbone.js的分层架构 – thearrow

至少,我可以看到你的@Path( “/部门”)和urlRoot: “/ REST/DEPARTMENTNAME” 不匹配。这可能是您获取404(未找到)错误消息的原因。尝试匹配urlRoot和@Path模式,看看是否有帮助。

温馨提示:我会建议使用邮递员铬插件,以确保如果REST服务效果很好试图尝试从.html文件调试服务电话404响应发行前测试您的服务。希望这可以帮助。

+0

我想你的意见,但用SpringMVC这个错误仍然在这里:(。我的Apache CXF URL模式/ REST/*所以我的web应用程序的运行/ REST / – thearrow