springboot配置集成vue前端並打包發佈

springboot配置集成vue前端並打包發佈

操作步驟

  1. 新建一個springboot工程orchid

  2. 新建一個vue項目併成功打包,可以參考https://www.cnblogs.com/ants_double/p/13391211.html

  3. 添加必要的依賴

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
            </dependency>
    
  4. 添加controller入口

    @Controller()
    @RequestMapping("/")
    public class IndexController {
        @GetMapping("home")
        public ModelAndView index(){
            ModelAndView mv =  new ModelAndView("index");
            return mv;
        }
    }
    
  5. 配置資源文件

    spring:
      thymeleaf:
        prefix: classpath:/templates/
        suffix: .html
        servlet:
          content-type: text/html
        mode: HTML
        cache: false
        encoding: utf-8
    
    
  6. 放入vue生成的包文件(使用默認路徑)

    • static 文件夾放入 resources/static文件夾下
    • index.html放入resources/templates文件夾下
  7. 打包發佈

    mvn package
    nohup java -jar ****.jar
    

源碼

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章