废话不多说,直接上代码
1、controller类
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
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.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
/**
* <pre>
* 上传文件
* </pre>
*
* @author naveu
* @date 2018年7月9日 上午10:38:51
*/
@Slf4j
@RestController
public class UpFileController {
@Autowired
private UpFileService upFileService;
@RequestMapping(value = "/upFile", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }, method = RequestMethod.POST)
public String upFile(@RequestParam("file") MultipartFile file) {
return upFileService.upFile(file);
}
}