我有这个资源处理程序,我可以调用位于不同位置的静态网页,但我试图从控制器类调用,我无法获得页面
@Configuration
public class Static_ResourceHandler implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/system/files/**").addResourceLocations("file:/home/niteshb/Documents/data");
}
}
这就是我所说的
http://localhost:8080/system/files/test.html
但是如何从控制器调用它,我试过这样的方法,但它不起作用这是我的控制器类调用。。
@GetMapping("/")
public String getfile() {
return "test.html";
}
为/system/files/
创建Get映射,您已经为其创建了资源处理程序,并以新创建的方法返回该文件。
@GetMapping("/system/files/")
public String getStaticfile() {
return "/system/files/test.html";
}
希望这能奏效。