【发布时间】:2017-07-29 11:16:27
【问题描述】:
我的maven项目使用hibernate apache cxf spring和backbone.js 我正在尝试使用 post 方法将数据保存到表中。但我总是得到 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);
}
我在屏幕截图上分享了我的错误。对不起,我的英语不好。我希望我能告诉你这个问题。
感谢您的回答!
【问题讨论】:
-
您使用的是没有 MVC 模块的 Spring Framework?
-
是的,我没有使用 SpringMVC 我使用 Backbone.js 进行分层架构
标签: spring http-status-code-404 spring-restcontroller