Kein Konverter für [Klasse xxx] mit voreingestelltem Inhaltstyp „multipart/form-data“

Melden Sie einen Fehler

org.springframework.http.converter.HttpMessageNotWritableException: Kein Konverter für [Klasse cn.guet.utils.Result] mit voreingestelltem Inhaltstyp „multipart/form-data“

Wenn ich die Logik zur Bestimmung, ob die Datei vorhanden ist, in writeBytes einfüge, wenn festgestellt wird, dass die Datei nicht vorhanden ist und BusinessExceptioneine Ausnahme ausgelöst wird, wird im Hintergrund ein Fehler gemeldet.
Da ich zu diesem Zeitpunkt nicht damit umgehen konnte response.setContentType("multipart/form-data"), HttpMessageConverterbrachte ich die Beurteilungslogik in den Vordergrund und das Problem wurde gelöst.

// 检验文件是否存在
        File file = new File(storagePath);
        log.info("storagePath: {}",storagePath);
        if(!file.exists()){
    
    
            log.info("wfenwogergh======================");
            throw new BusinessException(400,"文件不存在");
        }

        response.setContentType("multipart/form-data");
        response.setHeader("Content-Disposition",
                "attachment;fileName=" + downloadName);
        // 现阶段, 没区别
//                "attachment;fileName=" + URLEncoder.encode(downloadName, "utf-8"));

        writeBytes(storagePath,response.getOutputStream());

Supongo que te gusta

Origin blog.csdn.net/qq_53318060/article/details/127116665
Recomendado
Clasificación