废话不多说,直接上图:

IDEA创建SpringBoot项目简单实例

IDEA创建SpringBoot项目简单实例

 

IDEA创建SpringBoot项目简单实例

IDEA创建SpringBoot项目简单实例

IDEA创建SpringBoot项目简单实例

 

IDEA创建SpringBoot项目简单实例

我们来新建一个Controller类(这里注意Controller类要放在DemoApplication的下一级目录):

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("index")
public class IndexController {


   @GetMapping("view")
   public String showView() {
      return "Hello Spring";
   }
   
}

 

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 http://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.1.3.RELEASE</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>1.8</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>

然后就可以启动项目:

IDEA创建SpringBoot项目简单实例

访问,默认是8080端口:

IDEA创建SpringBoot项目简单实例

相关文章:

  • 2021-11-16
  • 2022-01-05
  • 2021-11-21
  • 2021-09-05
  • 2021-06-13
猜你喜欢
  • 2021-11-29
  • 2021-12-01
  • 2022-12-23
  • 2021-12-14
  • 2021-07-03
相关资源
相似解决方案