registry.addResourceHandler
时间: 2024-05-10 16:14:54 浏览: 97
`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()`.
阅读全文