以下是一个简化的代码示例,展示了如何创建一个Spring Boot 3和Vue 3前后端分离项目的基座:
Spring Boot 3:
pom.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/pom.xml">
 
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>com.example</groupId>
    <artifactId>demo-backend</artifactId>
    <version>1.0.0-SNAPSHOT</version>
 
    <properties>
        <java.version>17</java.version>
        <spring-boot.version>3.0.0</spring-boot.version>
    </properties>
 
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
 
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
 
</project>
DemoBackendApplication.java 文件:
package com.example.demobackend;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
@SpringBootApplication
public class DemoBackendApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoBackendApplication.class, args);
    }
}
Vue 3:
package.json 文件:
{
  "name": "demo-frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build"
  },
  "dependencies": {
    "core-js": "^3.20.3",
    "vue": "^3.0.0"
  },
  "devDependencies": {
    "@vue/cli-service": "~5.0.0",
    "@vue/compiler-sfc": "^3.0.0",
    "vue-template-compiler": "^2.6.12"
  }
}
src/App.vue 文件:
<template>
  <div>
    <h1>Vue 3 + Spring Boot 3 项目基座</h1>
  </div>
</template>
 
<script>
export default {
  name: 'App'
}
</script>
public/index.html 文件:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Demo Frontend</title>
</head>
<body>
  <div id="app"></div>
</body>
</html>
这个示例展示了如何创建一个简单的Spring Boot 3和Vue