springboot整合vue的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/");
}
}
将上述配置完成后便可进行项目发布了,如有问题随时交流