2017-03-08 79 views
0

使用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

回答

0

至少,我可以看到你的@Path( 「/部門」)和urlRoot: 「/ REST/DEPARTMENTNAME」 不匹配。這可能是您獲取404(未找到)錯誤消息的原因。嘗試匹配urlRoot和@Path模式,看看是否有幫助。

溫馨提示:我會建議使用郵遞員鉻插件,以確保如果REST服務效果很好試圖嘗試從.html文件調試服務電話404響應發行前測試您的服務。希望這可以幫助。

+0

我想你的意見,但用SpringMVC這個錯誤仍然在這裏:(。我的Apache CXF URL模式/ REST/*所以我的web應用程序的運行/ REST / – thearrow