通常解決方案參考
https://blog.csdn.net/qq_42651201/article/details/120710224
我的報(bào)錯(cuò)?
org.springframework.http.converter.HttpMessageNotWritableException:
?No converter for [class com.xxx.dto.Result] with preset Content-Type 'application/vnd.ms-excel;charset=utf-8'
我的問(wèn)題根因
controller處理邏輯有問(wèn)題,導(dǎo)致報(bào)錯(cuò),然后被全局異常捕捉,再然后返回了錯(cuò)誤信息
也就是說(shuō)本來(lái)沒(méi)有返回值的方法,最終有返回值class com.xxx.dto.Result ,就會(huì)拋出以上錯(cuò)誤。
我的解決方案
把controller里面的報(bào)錯(cuò)解決,讓邏輯正常執(zhí)行,不報(bào)錯(cuò),不被全局異常捕捉即可
以上為我遇到的問(wèn)題根因和解決方案
另外還有種情況 也可能會(huì)報(bào)以上錯(cuò)誤,就是表格列的? index的值重復(fù)
@ExcelProperty(value = "字段", index = 0)
以下是具體的分析步驟,可看,可略過(guò)。
我的代碼情況:
1. controller內(nèi)無(wú)返回值,因此不適用通常解決方案
public void downloadExt(HttpServletResponse response, DataQuery qry) throws IOException {
?? ?try {
?? ??? ?// 查詢(xún)數(shù)據(jù) 導(dǎo)出數(shù)據(jù)邏輯
?? ?} catch (Exception e) {
? ? ? ? ? ? throw new BsException("文件下載失敗");
? ? }
}
2. 再細(xì)看日志,報(bào)錯(cuò)內(nèi)其他信息
org.springframework.http.converter.HttpMessageNotWritableException:
?No converter for [class com.xxx.dto.Result] with preset Content-Type 'application/vnd.ms-excel;charset=utf-8'
發(fā)現(xiàn)雖然接口代碼沒(méi)有返回值,但是 前端請(qǐng)求接口的時(shí)候 的確返回了 com.xxx.dto.Result 對(duì)象
3. 查看代碼是否有全局異常處理
public class ExceptionHandler ?implements GlobalExceptionHandler {
?? ?@ExceptionHandler(Exception.class)
? ? @ResponseBody
? ? public Result errorException(Exception e) {
? ? ? ? log.error(e.getMessage(), e);
? ? ? ? return Result.fail(xxxx);
? ? }
?}
經(jīng)查看,是全局異常處理捕捉了第1步的controller拋出的異常,然后返回了Result對(duì)象,導(dǎo)致下載報(bào)錯(cuò)。
但是 根因不在這里,而是在導(dǎo)出的controller代碼里面報(bào)錯(cuò)了
public void downloadExt(HttpServletResponse response, DataQuery qry) throws IOException {
?? ?try {
?? ??? ?**// 查詢(xún)數(shù)據(jù) 導(dǎo)出數(shù)據(jù)邏輯**
?? ?} catch (Exception e) {
?? ??? ??? ?log.info(null, e);
? ? ? ? ? ? throw new BsException("文件下載失敗");
? ? }
}
打出日志,查看日志,即可解決問(wèn)題文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-407845.html
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-407845.html
到了這里,關(guān)于No converter for [class java.util.LinkedHashMap] with preset Content-Type ‘a(chǎn)pplication/vnd.ms-excel;的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!