当前位置:网站首页>4. Web Development
4. Web Development
2022-07-30 04:37:00 【time postman】
文章目录
1、简单功能分析
1)静态资源
静态资源目录:/static 或 /resources 或 /META-INF/resources 或 /public
访问:当前项目根目录/ + 静态资源名
原理: 静态映射/**
请求进来,先去找Controller看能不能处理,Requests that cannot be processed are handed over to the static resource handler,静态资源也找不到则响应404页面
#Modify the path for web pages to access static resource files
spring:
mvc:
static-path-pattern: /res/** #Change the default static assets folder location web: resources: static-locations: [classpath:/haha/]
2)欢迎页支持
静态资源路径下 index.html–可以配置静态资源路径,但是不可以配置静态资源的访问前缀,否则导致 index.html不能被默认访问
controller能处理/index
3)自定义 Favicon(图标)
静态资源路径下放置favicon.ico图标、重启项目
4)静态资源配置原理
SpringBoot启动默认加载 xxxAutoConfiguration 类(自动配置类)
SpringMVC功能的自动配置类 WebMvcAutoConfiguration生效
@Configuration(
proxyBeanMethods = false
)
@ConditionalOnWebApplication(
type = Type.SERVLET
)
@ConditionalOnClass({
Servlet.class, DispatcherServlet.class, WebMvcConfigurer.class})
@ConditionalOnMissingBean({
WebMvcConfigurationSupport.class})
@AutoConfigureOrder(-2147483638)
@AutoConfigureAfter({
DispatcherServletAutoConfiguration.class, TaskExecutionAutoConfiguration.class, ValidationAutoConfiguration.class})
public class WebMvcAutoConfiguration {
}
2、请求参数处理
@xxxMapping
Rest风格支持(使用HTTP请求方式动词来表示对资源的操作)
以前:/getUser 获取用户 /deleteUser 删除用户 /editUser 修改用户 /saveUser 保存用户
现在: /user GET-获取用户 DELETE-删除用户 PUT-修改用户 POST-保存用户
核心Filter;HiddenHttpMethodFilter
用法: 表单method=post,隐藏域 _method=put
SpringBoot中手动开启
@RequestMapping(value = "/user",method = RequestMethod.GET)
public String getUser(){
return "GET-叶子航";
}
@RequestMapping(value = "/user",method = RequestMethod.POST)
public String saveUser(){
return "POST-叶子航";
}
@RequestMapping(value = "/user",method = RequestMethod.PUT)
public String putUser(){
return "PUT-叶子航";
}
@RequestMapping(value = "/user",method = RequestMethod.DELETE)
public String deleteUser(){
return "DELETE-叶子航";
}
rest默认设置为flase
@Bean
@ConditionalOnMissingBean(HiddenHttpMethodFilter.class)
@ConditionalOnProperty(prefix = "spring.mvc.hiddenmethod.filter", name = "enabled", matchIfMissing = false)
public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new OrderedHiddenHttpMethodFilter();
}
spring:
mvc:
hiddenmethod:
filter:
enabled: true #开启页面表单的Rest功能
Rest原理(表单提交要使用REST的时候)
a>表单提交会带上_method=PUT
b>请求过来被HiddenHttpMethodFilter拦截
c>请求是否正常,并且是POST
d>获取到_method的值.
e>兼容以下请求;PUT.DELETE.PATCH
f>原生request(post),包装模式requesWrapper重写了getMethod方法,返回的是传入的值.
过滤器链放行的时候用wrapper.以后的方法调用getMethod是调用requesWrapper的.
自定义MethodParam(_method)
//自定义filter
@Bean
public HiddenHttpMethodFilter hiddenHttpMethodFilter(){
HiddenHttpMethodFilter methodFilter = new HiddenHttpMethodFilter();
methodFilter.setMethodParam("_m");
return methodFilter;
}
3、分析源码
咕咕咕~WebThere is too much source code to develop this part,I'll start,Wait for me to come back and fill in the source code
边栏推荐
- The 2nd Shanxi Province Network Security Skills Competition (Enterprise Group) Part of the WP (9)
- GCC Rust is approved to be included in the mainline code base, or will meet you in GCC 13
- labelme的使用技巧
- Get the local IP and Request's IP
- QT(39)-vs development qt program prompts that the source file cannot be opened
- 小程序 wx.miniProgram.navigateTo 跳转地址不能是tabbar地址
- Chapter8 支持向量机
- KubeMeet Registration | The complete agenda of the "Edge Native" Online Technology Salon has been announced!
- My first experience of Go+ language——Blessing message system, so that she can also feel your blessings
- 机器学习:知道通过低方差过滤实现降维过程
猜你喜欢
Introduction to database - MySQL simple introduction
Simple experiment with BGP
【 notes 】 the beauty of the software engineering - column 31 | software testing are responsible for the quality of products?
DAY17:弱口令的探测与测试
Perspective transformation matrix of image perspective correction should be matrix (single)/findHomography with getPerspectiveTransformd difference
Database Design of Commodity Management System--SQL Server
复现XXL-JOB 任务调度中心后台任意命令执行漏洞
The Azure developer news 丨 memorabilia in July
Machine Learning: Knowing the Dimensionality Reduction Process Through Low Variance Filtering
labelme的使用技巧
随机推荐
【 notes 】 the beauty of the software engineering - column 31 | software testing are responsible for the quality of products?
Thinkphp 5.0.24变量覆盖漏洞导致RCE分析
Learning of redis_Basic part
Mini Program wx.miniProgram.navigateTo jump address cannot be tabbar address
Simple experiment with BGP
Xiamen SenseCore Technology MC3172(1): Introduction and Environment Construction
精品MySQL面试题,备战八月99%必问!过不了面试算我的
Golang eight-legged text finishing (continuous handling)
代码开源设计实现思路
handler+message【消息机制】
基于OpenCV实现的图像拼接(配准)案例
商品管理系统数据库设计--SQL Server
Android Studio 实现登录注册-源代码 (连接MySql数据库)
2.6 Radix sort (bucket sort)
六、读取应用配置+日志配置
Shanxi group (enterprises) in the second network security skills competition part problem WP (8)
【线性表】- LeetCode力扣三道练习题详解
文件系统二
DAY17: weak password detection and test
四、Web开发