第七章 layui + spring boot 搭建后台管理模板
页面效果:
1. 项目中新建static文件夹
引入layui开发相关代码 源码下载路径 https://www.layui.com/doc/
2.配置webConfig 添加静态文件路径
package com.example.demo.config;
import com.example.demo.interceptor.mHandlerInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Resource
private mHandlerInterceptor interceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 自定义拦截器,添加拦截路径和排除拦截路径
registry.addInterceptor(interceptor)
.addPathPatterns("/**")
.excludePathPatterns("/login/**",
"/swagger-resources/**",
"/swagger-ui.html/**",
"/webjars/**",
"/static/**",
"/examples/**");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/");
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
启动项目即可