Spring Boot-構建Spring Boot 第一個demo

構建Spring Boot 第一個demo

 

  1. 打開Spring官網提供的網址:https://start.spring.io/
  2. 按照自己的要求填寫需要的信息

     
  3. 解壓下載的文件,文件結構如下:
  4. 解壓的項目導入IDE中,(以STS爲例),導入後刪除不必要的文件,最後如下:

    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>

   

    <groupId>com.xiangty</groupId>

    <artifactId>springboot-starter</artifactId>

    <version>0.0.1-SNAPSHOT</version>

    <name>springboot-starter</name>

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

   

   

    <parent>

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

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

        <version>2.1.3.RELEASE</version>

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

    </parent>

 

    <properties>

        <java.version>1.8</java.version>

    </properties>

 

    <dependencies>

        <dependency>

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

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

        </dependency>

       

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

 

     5.編寫HelloController
     

package com.xiangty.controller;

 

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

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

 

@RestController

public class HelloController {

    @RequestMapping("/hello")

    public Object hello() {

        return "Hello SpringBoot";

    }   

}

     6.啓動項目
     

     

 

     7.瀏覽器輸入localhost:8080/hello
     

如有錯誤請指正,謝謝。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章