框架搭建 [idea]

Exisi 2022-09-28 15:01:03
Categories: Tags:
  1. 新建spring boot项目

 

  1. 导入相关环境依赖

 

  1. 构建后的目录

 

构建后的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/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

 

    <parent>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-parent</artifactId>

        <version>2.6.0</version>

        <relativePath/> <!-- lookup parent from repository -->

    </parent>

 

    <groupId>com.example</groupId>

    <artifactId>demo</artifactId>

    <version>0.0.1-SNAPSHOT</version>

    <name>demo</name>

    <description>Demo project for Spring Boot</description>

    <properties>

        <java.version>11</java.version>

    </properties>

 

    <dependencies>

<!-- web项目的起步依赖 -->

        <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>

 

  1. 完善目录结构

 

  1. 编写MainController

@RestController

public class Maincontroller {

 

    @RequestMapping("/demo")

    public String hello(){

       return "Hello,Spring boot";

    }

}

 

 

  1. 运行DemoApplicaton.java

@SpringBootApplication

public class DemoApplication {

 

    public static void main(String[] args) {

        SpringApplication.run(DemoApplication.class, args);

    }

}

        运行结果:

 

  1. 访问localhost:8080/demo