我已经修复了您的代码。
控制者
我使用
initValues()方法来填充
model值。
我也
@RequestParam List<String> searchValues向
handleFileUpload()方法添加了参数。
import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.ModelAttribute;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.multipart.MultipartFile;import java.util.Arrays;import java.util.List;@Controllerpublic class CustomerDataController { private static final String SEARCH_TYPES = "searchTypes"; @ModelAttribute public void initValues(Model model) { model.addAttribute(SEARCH_TYPES, Arrays.asList("Search A", "Search B")); } @RequestMapping(value = "/upload", method = RequestMethod.GET) public String displayUpload() { return "upload"; } @RequestMapping(value = "/userFile", method = RequestMethod.POST) public String handleFileUpload(@RequestParam("myFile") MultipartFile file, @RequestParam List<String> searchValues) { // here you can use searchValues and file return "result"; }}
upload.html
我固定
<label th:text="#{${search}}"></label>到
<labelth:text="${search}"></label>。
我也固定
<form>和
<input type="checkbox">标签。
<!DOCTYPE html><html xmlns:th="http://www.thymeleaf.org" lang="en" xmlns="http://www.w3.org/1999/xhtml"><head> <meta charset="UTF-8"/> <title>Upload</title></head><body><form th:action="@{/userFile}" method="post" enctype="multipart/form-data"> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> <ul> <li th:each="search : ${searchTypes}"> <input type="checkbox" name="searchValues" th:value="${search}"/> <label th:text="${search}"></label> </li> </ul> <p><input type="file" name="myFile" id="myFile"/></p> <p><input type="submit" value="Submit Customer Data"/></p> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/></form></body></html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)