0
我有一个表单,用户可以在其中为图形程序输入自己的参数。提交函数肯定会保存模型,但是当我转到输出页面时,出现一个错误,提示“出现意外错误(type = Unsupported Media Type,status = 415)。 不支持内容类型'null' ”。
我使用的是骨干模型来保存这些参数,所以这里是我的模型:将属性从Backbone模型传递给Spring Controller作为参数
var GraphModel = Backbone.Model.extend({
defaults: {
"graphTitle": "",
"prefix": "",
"inputFile": "",
"grType": ""
}
});
的视图存储在这些属性提交事件的用户价值。然后它进入一个新的页面,“/输出”。在我看来,提交功能看起来像这样...
submit: function(event){
var model = new GraphModel();
model.set({graphTitle: $("#graphTitle").val(), prefix: $("#prefix").val(),
inputFile: $("#inputFile").val(), grType: $("#grType").val()});
var graphTitle = model.get("graphTitle");
var prefix = model.get("prefix");
var inputFile = model.get("inputFile");
var grType = model.get("grType");
model.save();
console.log(graphTitle + " " + prefix + " " + inputFile + " " + grType);
window.location = "http://localhost:8181/output"
}
我试着输入图形参数作为模型的属性,其形式传入
public OntologyGraph(String graphTitle, String prefix, String grType,
String inputFile) throws Exception {
然后,我有我的控制器代码,我只是试图用来返回一个JSON格式来测试它。
@RestController
public class GraphController {
@RequestMapping(value = "/output", consumes = "application/json",
produces = "application/json")
public @ResponseBody OntologyGraph graph(@RequestBody OntologyGraph model)
throws Exception {
return model;
}
}