找回密码
 立即注册
查看: 4|回复: 0

2,SpringBoot3入门

[复制链接]

197

主题

6

精华

201

金币

技术维护QQ:515138

积分
432
发表于 昨天 21:35 | 显示全部楼层 |阅读模式
①. 创建Maven工程
②. 导入spring-boot-stater-web起步依赖
③. 编写Controller
④. 提供启动类
<!--boot工程的父工程,用于管理起步依赖的版本-->
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4.     <modelVersion>4.0.0</modelVersion>
  5.     <!--boot工程的父工程,用于管理起步依赖的版本-->
  6.     <parent>
  7.         <groupId>org.springframework.boot</groupId>
  8.         <artifactId>spring-boot-starter-parent</artifactId>
  9.         <version>3.5.11</version>
  10.         <relativePath/> <!-- lookup parent from repository -->
  11.     </parent>
  12.     <groupId>com.jinhei</groupId>
  13.     <artifactId>demo01</artifactId>
  14.     <version>0.0.1-SNAPSHOT</version>
  15.     <name>demo01</name>
  16.     <description>demo01</description>
  17.     <url/>
  18.     <licenses>
  19.         <license/>
  20.     </licenses>
  21.     <developers>
  22.         <developer/>
  23.     </developers>
  24.     <scm>
  25.         <connection/>
  26.         <developerConnection/>
  27.         <tag/>
  28.         <url/>
  29.     </scm>
  30.     <properties>
  31.         <java.version>21</java.version>
  32.     </properties>
  33.     <dependencies>
  34.         <dependency>
  35.             <groupId>org.springframework.boot</groupId>
  36.             <artifactId>spring-boot-starter-web</artifactId>
  37.         </dependency>
  38.         <dependency>
  39.             <groupId>org.springframework.boot</groupId>
  40.             <artifactId>spring-boot-starter-test</artifactId>
  41.             <scope>test</scope>
  42.         </dependency>
  43.     </dependencies>
  44.     <build>
  45.         <plugins>
  46.             <plugin>
  47.                 <groupId>org.springframework.boot</groupId>
  48.                 <artifactId>spring-boot-maven-plugin</artifactId>
  49.             </plugin>
  50.         </plugins>
  51.     </build>
  52. </project>
复制代码
C层:
  1. package com.jinhei.demo01.controller;
  2. import org.springframework.web.bind.annotation.RequestMapping;
  3. import org.springframework.web.bind.annotation.RestController;
  4. @RestController
  5. public class HelloController {
  6.     @RequestMapping("/hello")
  7.     public String hello(){
  8.         return "hello world";
  9.     }
  10. }
复制代码
启动类:
  1. package com.jinhei.demo01;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. // 启动类
  5. @SpringBootApplication
  6. public class Demo01Application {
  7.     public static void main(String[] args) {
  8.         SpringApplication.run(Demo01Application.class, args);
  9.         System.out.println("【金数据,黑科技】恭喜您!项目启动成功");
  10.     }
  11. }
复制代码
demo01.zip (22.74 KB, 下载次数: 0, 售价: 5 金币)



上一篇:1,SpringBoot3特征
网站建设,公众号小程序开发,系统定制,软件App开发,技术维护【联系我们】手机/微信:17817817816 QQ:515138

QQ|Archiver|自丢网 ( 粤ICP备2024252464号-1 )

GMT+8, 2026-2-24 06:18

专注于网站建设,公众号小程序制作,商城小程序,系统定制,软件App开发

【联系我们】手机/微信:17817817816 QQ:515138

快速回复 返回顶部 返回列表