2016-02-27 64 views
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 


所以這似乎是出於某種原因,這只是接受一個參數?

回答

2

它看起來像有在你的構造錯誤

公共OntologyGraph(字符串graphTitle,字符串前綴字符串類型, 字符串INPUTFILE)拋出異常{

return graphmlString; 

}

你試圖在構造函數中返回一個字符串,這在Java中是不可能的。這會導致編譯錯誤,我猜想

+0

你會推薦什麼來返回GraphController的graphmltring?我已經嘗試在構造函數中設置graphmlString,並使用public String getString(){return graphmlString; },但我不知道如何將它作爲本地主機的GraphController輸出。 –

+0

我只會覆蓋toString方法或添加一個getter來訪問構建字符串。 – berlinguyinca

相關問題