SpringBoot 流水筆記 一

1、 啓動一個hello。

 使用maven 進行構建?pom.xml 文件構建如下,構建一個web啓動器。

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
 </parent>
<dependencyManagement>
   
 <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
</dependencyManagement>

2、打印Hello., MVC 風格

 1> 構建啓動器類

package com.fandong.weapon;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;

@EnableAutoConfiguration
@ComponentScan
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class);
    }
}
@EnableAutoConfiguration : 表示使用約定的配置
@ComponentScan: 表示掃描包。

2> 構建helloController

package com.fandong.weapon.Controller;

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

@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }
}

啓動spring boot 類

3、在瀏覽器輸入: localhost:8080/hello

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