2017-09-26 64 views
0

這是我的腳本如何從春天控制器列表中的JavaScript

$.ajax({ 
    url: 'request/batch/details', 
    contentType: 'application/json', 
    dataType: 'json', 
    type: 'GET', 
    success: function (data) { 

     alert("ok"); 
    }, 
    error: function (jqXHR, textStatus, errorThrown) { 
     alert("error" + errorThrown); 
    } 
}); 

,這是我的控制器

@RequestMapping(value = {"/request/batch/details"}, method = RequestMethod.GET, produces = "application/json") 
public List<Batch> SentAllBatchs() { 

    List<Batch> allBatches = service.getAllBatches(); 

    for (Batch allBatche : allBatches) { 
     System.out.println(allBatche.getBatchName()); 
    } 
    return allBatches; 
} 

當我運行這個它拋出一個錯誤

405方法不允許..

我做錯了什麼? 幫我解決這個問題。

回答

0

請如果缺少的pom.xml

<dependency> 
    <groupId>com.fasterxml.jackson.core</groupId> 
    <artifactId>jackson-core</artifactId> 
    <version>2.4.1</version> 
</dependency> 
<dependency> 
    <groupId>com.fasterxml.jackson.core</groupId> 
    <artifactId>jackson-databind</artifactId> 
    <version>2.4.1.1</version> 
</dependency> 

添加以下MVN文物,並檢查,如果你有

<dependency> 
    <groupId>org.codehaus.jackson</groupId> 
    <artifactId>jackson-core-asl</artifactId> 
    <version>1.9.13</version> 
</dependency> 

<dependency> 
    <groupId>org.codehaus.jackson</groupId> 
    <artifactId>jackson-mapper-asl</artifactId> 
    <version>1.9.13</version> 
</dependency> 
+0

此前的問題將錯誤代碼稱爲406,因此,答案是指406錯誤代碼 –

0
  1. 檢查您的安全/日誌
  2. 添加或@ResponseBody ResponseEntry作爲您的控制器的呼叫

Andtry在您的請求中添加主要斜槓;)

+0

您的意思是這樣的? public @ResponseBody列表 SentAllBatchs(){ –

+0

這樣的事情,是的。如果它是RestController,它不是nesesary,但它不存在於你的問題中。 – AlexGera