1、前端代码放置位置
2、配置输入端口后直接跳转到文件访问
@Controller
public class ViewController {
@RequestMapping(value = {"/"})
public String redir(){
return "redirect:/index.html";
}
}
3、配置访问
@Configuration
public class ResourceConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String dirPath = AppProperties.getProperty("server.resource");
String cachePath = AppProperties.getProperty("server.resource") + AppConstant.FileCacheDirName;
checkDir(dirPath);
checkDir(cachePath);
checkDir(dirPath + "paper");
checkDir(dirPath + "pics");
checkDir(dirPath + "otherFile");
registry.addResourceHandler(AppConstant.ResourceDir + "/**")
.addResourceLocations("file:" + dirPath);
registry.addResourceHandler(cachePath + "/**")
.addResourceLocations("file:" + cachePath);
registry.addResourceHandler("/**")
.addResourceLocations("file:" + dirPath)
.addResourceLocations("classpath:/static/");
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
}
private void checkDir(String dirFile) {
File htmlFile = new File(dirFile);
if (!htmlFile.exists()) {
htmlFile.mkdirs();
}
}
}