私はファイル入力とテキスト入力のコレクションを持っています。各ファイル入力には、対応するタイプ・フィールドがあります。両方の値をリストとして取得する必要があります。春にファイルとテキスト入力フィールドを同時に扱うMVC
コントローラーコード:
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public OutletIndex updateOutlet(@PathVariable String id,
@ModelAttribute @Valid OutletIndex outlet,
@RequestParam(value = "file", required = false) List<MultipartFile> file,
@RequestParam(value = "types", required = false) List<MultipartFile> types,
HttpServletRequest request
) {
//......
}
HTMLコード:現在、私は次のよう試みたのだ
<input type="text" name="types"/>
<input type="text" name="types"/>
<input type="text" name="types"/>
<input type="text" name="types"/>
<input type="file" name="file"/>
<input type="file" name="file"/>
<input type="file" name="file"/>
<input type="file" name="file"/>
ファイルの入力は任意のファイルを選択した場合、それはうまく働いています。ファイルを選択しないと、リストには表示されませんが、空の場合でもテキスト入力が表示されます。どうすれば解決できますか?
私はまた、request.getParameterMap()
を使用して値を取得しようとしましたが、両方の結果が同じです。
2つのファイルを選択すると、出力は同じようになります。
types
リストのサイズが4
とfile
リストのサイズが2
です。
ファイルが選択されていない場合、null
をリストに追加できますか?
おかげでたくさんの男...最後に 'FileWrapper'のリストを保持する追加POJOクラスを作成した後、私は問題を解決しました:) –
ようこそPranav。 –