当前位置: 首页 > news >正文

vue-element-admin 打包部署到SpringBoot

更改vue里面vue.config.js

运行build命令 npm run build:prod

生成dist文件夹

打开你的springboot项目

复制static文件夹到 src/main/resources/ 并将index.html移动到templates(使用template)

更改index.html文件中导入地址 

在colltroller层写一个控制器返回index.html

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class SpaController {
    @RequestMapping("/index")
    public ModelAndView forward() {
        ModelAndView model = new ModelAndView();
        model.setViewName("index");
        return model;
    }
}

配置WebMvcConfig

@Configuration
@ComponentScan({"com.Manage.config", "com.Manage.controller", "com.Manage.filter"})
@EnableWebMvc
public class WebMvcConfig implements WebMvcConfigurer {

  @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截器,并指定需要拦截的路径
        registry.addInterceptor(jwtInterceptor)//jwtInterceptor为自定义token拦截器
                .addPathPatterns("/**") // 拦截所有路径,可以根据需要修改这个配置
                .excludePathPatterns("/index","/static/**"); // 排除不需要拦截的路径

    }
   @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // 将根路径 "/" 的请求重定向到 "/index.html"
        registry.addViewController("/login").setViewName("forward:/index.html");
        WebMvcConfigurer.super.addViewControllers(registry);
    }
@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
                  
    registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
     

    }

}

访问浏览器"http://localhost:你的端口号/index"即可

相关文章:

  • Linux Python 调试/堵塞/性能分析与定位工具
  • 【Cesium学习(十三)】Cesium学习主要优秀资源资料总结
  • python用 PythonNet 从 Python 调用 WPF 类库 UI 用XAML
  • 支持向量机 (Support Vector Machine, SVM)
  • ProfiNet转EtherNet/IP罗克韦尔PLC与监控系统通讯案例
  • hydra docker版本
  • 云原生监控体系建设:Kubernetes架构下的全面监控策略
  • DeepSeek R1本地Linux服务器Docker部署<实现网页访问/本地终端访问>完整教程
  • vxe-grid 通过配置式给单元格字段格式化树结构数据,转换树结构节点
  • CentOS7设置静态IP
  • 细分数字货币钱包的不同种类
  • CSS文本属性
  • 网工项目实践2.4 北京公司安全加固、服务需求分析及方案制定
  • CSS基础(浮动、相对定位、绝对定位、固定定位、粘性定位、版心、重置默认样式)
  • 22爬虫:使用Drission Page的两个案例
  • 网络安全高级软件编程技术
  • Java八股文(下)
  • Mac安装配置Tomcat 8
  • C++栈与队列:数据结构的“单行道”与“流水线
  • QML Component 与 Loader 结合动态加载组件
  • 集齐中国泳坛“老中青”!200自潘展乐力压汪顺、孙杨夺冠
  • 8000余万元黄金投入研发后“不知去向”,咋回事?
  • 苏丹港持续遭无人机袭击,外交部:呼吁各方保护民用设施和平民安全
  • 国家主席习近平任免驻外大使
  • “大国重器”、新型反隐身雷达……世界雷达展全面展示尖端装备
  • LPR名副其实吗?如果有所偏离又该如何调整?