当前位置:网站首页>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
边栏推荐
- 数据库概论 - MySQL的简单介绍
- 【C语言】程序环境和预处理
- Usage of EFR32 as sniffer for Zigbee/Thread
- 【周周有奖】云原生编程挑战赛“边缘容器”赛道邀你来战!
- MySql 怎么查出符合条件的最新的数据行?
- 软件测试员必看!数据库知识mysql查询语句大全
- - B + tree index and MySQL series 】 【 what is the difference between a HASH index
- C. Travelling Salesman and Special Numbers (binary + combination number)
- 双指针问题(下)
- [Redis Master Cultivation Road] Jedis - the basic use of Jedis
猜你喜欢

PyG builds R-GCN to realize node classification

MYSQL 唯一约束

golang八股文整理(持续搬运)

Learning of redis_Basic part

【线性表】- LeetCode力扣三道练习题详解

How does MySql find out the latest data row that meets the conditions?

Shanxi group (enterprises) in the second network security skills competition part problem WP (7)

【Redis高手修炼之路】Jedis——Jedis的基本使用

See you in shenzhen!Cloud native to accelerate the application building special: see cloud native FinOps, SRE, high-performance computing scenario best practices
![[SQL] at a certain correlation with a table of data update another table](/img/66/4dff4383509e5d25890d8a24720de6.png)
[SQL] at a certain correlation with a table of data update another table
随机推荐
cnpm installation steps
基于OpenCV实现的图像拼接(配准)案例
The 2nd Shanxi Province Network Security Skills Competition (Enterprise Group) Part of the WP (9)
Get the local IP and Request's IP
golang八股文整理(持续搬运)
Go 学习笔记(84)— Go 项目目录结构
js 操作在当前日期加减(天、周、月、年数)
DAY17, CSRF vulnerability
Shanxi group (enterprises) in the second network security skills competition part problem WP (7)
C. Qualification Rounds
2.6 Merge Sort
js operation to add or subtract from the current date (day, week, month, year)
《构建之法》笔记---第十章 典型用户和场景
商品管理系统数据库设计--SQL Server
Introduction to Thymeleaf
(题目练习)条件概率+权值线段树+FWT+后缀数组
模拟问题(中)
Chapter8 Support Vector Machines
数据目录是什么?为何需要它?
Machine Learning: Knowing the Dimensionality Reduction Process Through Low Variance Filtering