springboot整合vue项目(小试牛刀)
序
本文主要研究一下如何在springboot工程整合vue
maven
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
新建springboot的web工程,默认会在resources目录下生成static以及templates文件夹
templates文件用于存放后端渲染的模板,这里我们采用前后端分离的方式,因而该文件夹就没有用了
static文件夹就是存放静态文件的地方
plugin
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- mvn process-resources -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy Vue.js frontend content</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>src/main/resources/static</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${basedir}/vue-demo/dist</directory>
<includes>
<include>static/</include>
<include>index.html</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
这里我们使用了maven-resources-plugin插件,将vue工程npm run build之后的dist文件夹下的文件拷贝到static目录下
这里我们假设vue工程名为vue-demo,在这个springboot工程的根目录下
对于vue工程,首先执行npm run build生成静态文件,之后对maven工程执行mvn process-resources,就可以一键拷贝
小结
在springboot工程整合vue的话,将静态文件拷贝到src/main/resources/static目录下即可,这样就可以在springboot工程打开静态文件了,对api的请求也无需再转发,也没有跨域问题,比较适合管理后台前端资源的整合。
doc
上一篇:详解WebSocket+spring示例demo(已使用sockJs库)
栏 目:JAVA代码
下一篇:springboot项目获取resources相对路径的方法
本文地址:http://www.codeinn.net/misctech/99172.html


阅读排行
- 1Java Swing组件BoxLayout布局用法示例
- 2java中-jar 与nohup的对比
- 3Java邮件发送程序(可以同时发给多个地址、可以带附件)
- 4Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type异常
- 5Java中自定义异常详解及实例代码
- 6深入理解Java中的克隆
- 7java读取excel文件的两种方法
- 8解析SpringSecurity+JWT认证流程实现
- 9spring boot里增加表单验证hibernate-validator并在freemarker模板里显示错误信息(推荐)
- 10深入解析java虚拟机




