簡體   English   中英

class org.springframework.http.converter.HttpMessageNotWritableException 沒有轉換器 [class java.lang.Boolean] 與預設 Content-Type 'null'

[英]class org.springframework.http.converter.HttpMessageNotWritableException No converter for [class java.lang.Boolean] with preset Content-Type 'null'

class org.springframework.http.converter.HttpMessageNotWritableException 沒有轉換器 [class java.lang.Boolean] 與預設 Content-Type 'null'

我的 Controller 有一個返回 Boolean 類型的方法。 因為有一些客戶端服務要求它以“文本/純文本”的形式返回響應。

@RequestMapping(value="/test",method=RequestMethod.POST,produces= "text/plain")
public Boolean test() {
 return <boolean value>
}

當我使用它時,它會拋出以下錯誤 class org.springframework.http.converter.HttpMessageNotWritableException No converter for [class Z93F725A07423FE1C889F448B33D21F46.

在點擊請求時嘗試在curlPostman中添加Accept header !

(由於您要返回 Boolean,因此在返回響應之前使用toString()將 boolean 轉換為字符串)

Accept: text/plain

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM