Springboot+bootstarp+fileinput文件上传

Springboot+bootstarp+fileinput文件上传

1:导入依赖

		1> bootstrap-fileinput-master/css/fileinput.min.css
		2> bootstrap-fileinput-master/js/fileinput.min.js
		3> bootstrap-fileinput-master/js/locales/zh.js

设置上传大小 (application.yml)

springboot 2.0[application.yml]
spring:
    servlet:
      multipart:
        enabled: true
        max-file-size: 50MB
        max-request-size: 50MB

 2:前端代码

	
	

效果

Springboot+bootstarp+fileinput文件上传_第1张图片

Springboot+bootstarp+fileinput文件上传_第2张图片 

3.后台代码

@PostMapping("fileUpload")
	@ResponseBody
	public void fileUpload(@RequestParam("file")MultipartFile file){		
		if (file.isEmpty()) {			
            return;
        }else{
        	String fileName = file.getOriginalFilename();
        	String filepath = "D:/file/";
        	 File localFile = new File(filepath);
             if(!localFile .exists()) {
                 localFile.mkdirs();
            }
            String path = filepath+fileName;
            try {
            	File server_file = new File(path);
				file.transferTo(server_file);
				
			} catch (Exception e) {
				logger.info("文件上传异常");
			}
        }
		return;
	}

注意

name一定要和Controller对应上


public void fileUpload(@RequestParam("file")MultipartFile file){	

 

你可能感兴趣的:(JavaEE,(后端框架+基础知识))