springboot整合iview发布及部署

配置iview中的setting.env.js

这里应当注意publicPath的设置,如果你的项目有项目名称(例如 当所有页面的访问路径为http://localhost:8080/xxx/index.html时 应将publicPath配置为
publicPath: env === ‘development’ ? ‘/xxx’ : ‘/xxx’)(如果访问路径仅为http://localhost:8080/index.html 则应设置为’development’ ? ‘/’ : ‘/’)

const Setting = {
    // 是否使用 Mock 的数据,默认 开发环境为 true,生产环境为 false
    isMock: false,
    // 部署应用包时的基本 URL
    publicPath: env === 'development' ? '/xxx' : '/xxx',
    // 生产环境构建文件的目录名
    outputDir: 'dist',
    // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。
    assetsDir: '',
    // 开发环境每次保存时 lint 代码,会将 lint 错误输出为编译警告
    // true || false || error
    lintOnSave: true,
    // iView Loader 的选项
    // 详见 https://www.iviewui.com/docs/guide/iview-loader
    iviewLoaderOptions: {
        prefix: false
    }
};

配置iview中的setting.env.js

将iview的配置设置好后进行打包,运行npm run build的命令,会生成一系列文件,如下图
在这里插入图片描述
将其分别放到springboot中resource下的static和templates下
在这里插入图片描述

springboot配置Thymeleaf视图解析

SpringBoot提供了Thymeleaf的默认配置,并且为Thymeleaf设置了视图解析器,在pom.xml的配置文件中配置thymeleaf视图

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

配置application.yml

  spring:
	  thymeleaf:
		prefix=classpath:/templates/:
      resources:
    	static-locations: classpath:static/
	  

配置静态资源访问路径

创建类WebConfig 实现接口 WebMvcConfigurer并重写方法 addResourceHandlers

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@EnableWebMvc
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/")
                .addResourceLocations("classpath:/templates/");
    }
}

将上述配置完成后便可进行项目发布了,如有问题随时交流

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值