zl程序教程

您现在的位置是:首页 >  后端

当前栏目

SpringBoot快速入门

2023-09-14 09:14:24 时间

SpringBoot快速入门

参考网站

创建Maven项目

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

pom.xml

配置信息如下

<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 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>SpringBootStudy</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>Archetype - SpringBootStudy</name>
  <url>http://maven.apache.org</url>

<!--  springboot工程需要继承的父工程-->
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.4</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>

  <dependencies>
<!--    web开发的起步依赖-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>
</project>

创建文件结构

在这里插入图片描述

HelloController

package com.study.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 Spring Boot !";
    }
}

HelloApplication

package com.study;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/*
* 引导类:SpringBoot项目的入口
* */
@SpringBootApplication
public class HelloApplication {
    public static void main(String[] args) {
        SpringApplication.run(HelloApplication.class, args);
    }
}

运行结果

在这里插入图片描述

访问网址

在这里插入图片描述