+ファイルアップロードフォームの呼び出しのために装います

Feiginのデフォルトはファイルのアップロードをサポートしてフォームを送信していない、あなたがサポートするいくつかの設定を行う必要があります。

1、依存性を装います

 

 赤は、JARしなければならない支持体の形態です。

 

2、装うインタフェース・クラス:

輸入org.springframework.http.MediaType。
輸入org.springframework.web.bind.annotation.RequestMapping。
輸入org.springframework.web.bind.annotation.RequestMethod;
輸入org.springframework.web.bind.annotation.RequestParam。
輸入org.springframework.web.multipart.MultipartFile。

輸入com.longge.common.GlobalResponse。
輸入com.longge.dto.EmailDto; 

/ ** 
 * @author :yangzhilong 
 * @description:
 * MULTIPART_FORM_DATA_VALUEとポスト
 *あなたのクライアント装う設定: 
 * --------------------------- ----------------------------------------
 *インポートorg.springframework.cloud.openfeign.FeignClient。
    輸入org.springframework.context.annotation.Bean。
    
    輸入feign.codec.Encoder。
    輸入feign.form.spring.SpringFormEncoder。
    
    @FeignClient(値= "通知サービス"構成= NotificationServiceFeign.FeignSimpleEncoderConfig.class)
    NotificationMultipartService {延びNotificationServiceFeignパブリックインターフェイス
        クラスFeignSimpleEncoderConfig { 
            
            @Bean 
            公共エンコーダエンコーダは、(){ 
                )(新しいSpringFormEncoderを返します。
            } 
        } 
    } 
 * ---------------------------------------------- ----------------------- 
 * * / 
@RequestMapping(値 = "/ V1 / API"パブリック インターフェースNotificationMultipartService { 

    / ** 
     *一般的な電子メール・チャネルは、一般的な電子メールを送信するために使用します
     * 
     * <P>コンテンツのサポート:TXT、HTML、attachmentfile; </ P> 
     * <P> attachfileない必要</ P> 
     * 
     * @ PARAM attachfileファイル添付
     * @param emailDtoの電子メールの送信者のparam 
     * @return GlobalResponse <ロング>電子メールID
      * / 
    @RequestMapping(値 = "/メールを送信する"、方法= RequestMethod.POST、=、= {MediaType.APPLICATION_JSON_UTF8_VALUE}生産消費MediaType.MULTIPART_FORM_DATA_VALUE)
    GlobalResponseの<string>のsendmail(@RequestParam(値= "attachfile"、必須= )MultipartFileのattachfile、EmailDto emailDto)。
}

前記フォームをサポートするための要求、この個別の設定装うの必要性:

輸入org.springframework.cloud.openfeign.FeignClient。
輸入org.springframework.context.annotation.Bean。

輸入feign.codec.Encoder。
輸入feign.form.spring.SpringFormEncoder。

@FeignClient(値 = "通知サービス"構成= NotificationServiceFeign.FeignSimpleEncoderConfig。クラスパブリック インターフェース NotificationServiceFeign 延びNotificationMultipartService {
     クラスFeignSimpleEncoderConfig { 
        
        @Bean 
        公共エンコーダエンコーダは、(){
             戻り 新しい)(SpringFormEncoderします。
        }
    } 
}

 

3.サービスの実装クラス

@RequestMapping(値= "/ V1 / API / send_mail" METHOD = RequestMethod.POST、= MediaType.MULTIPART_FORM_DATA_VALUEを消費=生産{MediaType.APPLICATION_JSON_VALUE})
 パブリック GlobalResponse <ストリング>のsendmail(@RequestParam(値= "attachfile"は、必要= )MultipartFile [] attachfile、emailDto emailDto){
     // TODO 
}

 

おすすめ

転載: www.cnblogs.com/yangzhilong/p/11714620.html
おすすめ