最近在做一个生成前后端代码的功能,vue+java,开发的时候分开开发,最终将vue项目打包进java,具体如下
前端注意事项:
vue在打包前需要修改
改完保存,打包npm run build,将dist文件夹下的内容全部复制到/resources/static 下
后端注意事项:
需要引用的pom
<!--Spring boot Web容器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
项目配置
spring:
resources:
static-locations: classpath:/
定义一个SpringMvcConfig,省得写一堆空的controller
package org.csits.generator.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @author zk
* @date 2021/6/8 14:52
*/
@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/generator").setViewName("index");
}
}
启动项目,访问路径 http://localhost:8080/generator