registry.addResourceHandler
时间: 2024-05-10 08:14:54 浏览: 18
`registry.addResourceHandler()` is a method used in Spring Boot to configure how static resources (such as HTML, CSS, JavaScript files, images, etc.) are handled by the application.
`addResourceHandler()` method takes a parameter, which is the URL pattern for the static resources that you want to handle. For example, if you want to handle all requests for static resources that start with "/static/", you can use the following code:
```
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/");
```
This code tells Spring Boot to handle all requests for static resources that start with "/static/" by looking for the resources in the "static" folder in the classpath.
You can also configure other properties of the static resources, such as cache control, using additional methods on the `ResourceHandlerRegistration` object returned by `addResourceHandler()`.
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)