0
我正在研究一个项目,该项目需要一些用户输入并从该输入返回一个图形文件。我使用的是Spring Boot框架,所以我有一个带有主类的Application.java,以及一个带有@RequestParam的GraphController用于用户输入。
创建图表,OntologyGraph类,有这个在它:
类中的构造函数不能应用于使用Spring引导控制器的给定类型
public class OntologyGraph {
// Set argument variables
private String graphTitle;
private String prefix;
private String graphType;
private String inputFile;
public String graphmlString;
// create graphml
public OntologyGraph(String graphTitle, String prefix, String type,
String inputFile) throws Exception {
// Set content to given content
this.graphTitle = graphTitle;
this.prefix = prefix;
this.type = type;
this.inputFile = inputFile;
// code to process input is here
return graphmlString;
}
然后,我有GraphController.java获取和输入ARGS:
@RestController
public class GraphController {
@RequestMapping("/graph")
public OntologyGraph graph(@RequestParam(value="graphTitle", defaultValue="Title") String graphTitle,
@RequestParam(value="prefix", defaultValue="Prefix") String prefix,
@RequestParam(value="type", defaultValue="class") String type,
@RequestParam(value="inputFile", defaultValue="/Users/Tauber/Documents/onto-graph/src/test/Core.ttl") String inputFile) {
return new OntologyGraph(graphTitle, prefix, type, inputFile);
}
}
所以它接受这四个参数。但是,当我尝试运行它(这是一个gradle这个身材,所以我用gradle这个bootRun),它返回这个错误...
error: constructor OntologyGraph in class OntologyGraph cannot be applied to given types;
return new OntologyGraph(graphTitle, prefix, type, inputFile);
^
required: String
found: String,String,String,String
reason: actual and formal argument lists differ in length
所以这似乎是出于某种原因,这只是接受一个参数?
你会推荐什么来返回GraphController的graphmltring?我已经尝试在构造函数中设置graphmlString,并使用public String getString(){return graphmlString; },但我不知道如何将它作为本地主机的GraphController输出。 –
我只会覆盖toString方法或添加一个getter来访问构建字符串。 – berlinguyinca