|
①. 创建Maven工程 ②. 导入spring-boot-stater-web起步依赖 ③. 编写Controller ④. 提供启动类 <!--boot工程的父工程,用于管理起步依赖的版本-->
- <?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/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <!--boot工程的父工程,用于管理起步依赖的版本-->
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>3.5.11</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <groupId>com.jinhei</groupId>
- <artifactId>demo01</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <name>demo01</name>
- <description>demo01</description>
- <url/>
- <licenses>
- <license/>
- </licenses>
- <developers>
- <developer/>
- </developers>
- <scm>
- <connection/>
- <developerConnection/>
- <tag/>
- <url/>
- </scm>
- <properties>
- <java.version>21</java.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
- </project>
复制代码
C层: - package com.jinhei.demo01.controller;
-
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
-
- @RestController
- public class HelloController {
- @RequestMapping("/hello")
- public String hello(){
- return "hello world";
- }
- }
复制代码
启动类: - package com.jinhei.demo01;
-
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- // 启动类
- @SpringBootApplication
- public class Demo01Application {
-
- public static void main(String[] args) {
- SpringApplication.run(Demo01Application.class, args);
- System.out.println("【金数据,黑科技】恭喜您!项目启动成功");
- }
-
- }
复制代码
|