第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

HttpServletRequest 到 MultipartHttpServletRequest:

HttpServletRequest 到 MultipartHttpServletRequest:

手掌心 2021-06-08 13:27:48
我正在嘗試為包含以下方法的 Controller 類編寫 Junit 測試。 @RequestMapping(value = "/mappingUrl", method = RequestMethod.POST)public String uploadFileMethod(HttpServletResponse httpResponse, HttpServletRequest httpRequest, ModelMap model) throws Exception {  try {    MultipartFile multipartFile = ((MultipartHttpServletRequest) httpRequest).getFile("fileName");   }  catch(Exception e){}}在測試類中,我有以下方法 @Testpublic void testUploadFileMethod() throws Exception {mockMVC.perform(post("/mappingUrl")).andExpect(status().isOk());}執(zhí)行測試時出現(xiàn)以下異常:java.lang.ClassCastException: org.springframework.mock.web.MockHttpServletRequest cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest有沒有一種方法可以在不更改現(xiàn)有代碼的情況下測試該方法?該類在整個應(yīng)用程序中使用,我擔(dān)心我可能會破壞其他東西。
查看完整描述

1 回答

?
拉風(fēng)的咖菲貓

TA貢獻(xiàn)1995條經(jīng)驗 獲得超2個贊

你試一試


MockMultipartFile myFile = new MockMultipartFile("data", "myFile.txt", "text/plain", "myFileContent".getBytes());

mockMVC.perform(MockMvcRequestBuilders.multipart("/mappingUrl")

                    .file(myFile)).andExpect(status().isOk());

正如這里所解釋的


查看完整回答
反對 回復(fù) 2021-06-10
  • 1 回答
  • 0 關(guān)注
  • 604 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號