springboot整合web

一、整合Filter 

1,通过注解扫描完成Filter 组件的注册

注意:springboot的启动类要增加注解@ServletComponentScan,否则filter不生效

springboot整合web_第1张图片

2,通过方法完成Filter 组件的注册

编写filter类,不要加注解,在启动类中注册filter

springboot整合web_第2张图片
springboot整合web_第3张图片


二、整合 Listener

    与整合filter类似,过程不写

三、访问静态资源

1.在resources/static存放静态资源

springboot整合web_第4张图片

2.在src/main/webapp下存放静态资源

springboot整合web_第5张图片

如果2个地方都有同名文件,则访问resources/static下的资源

四、文件上传

1. 编写html上传页面

form表单中,action为请求的url,method必须是post,enctype="multipart/form-data"

springboot整合web_第6张图片

2.编写controller

方法的形参类型必须是MultipartFile,并且形参名要和html表单中input标签的name一致

springboot整合web_第7张图片

3.设置上传文件的大小限制(不同版本的springboot不同)


你可能感兴趣的:(springboot整合web)