spring boot之hello world!

1.使用idea搭建spring boot項目工程,選擇Spring Initializr,選中jdk然後next
在這裏插入圖片描述
2.輸入Group,Artifact,選中Maven Project,然後next
在這裏插入圖片描述
3.選擇web->web 然後next,再finish
在這裏插入圖片描述
4.搭建後項目目錄如下
在這裏插入圖片描述
DemoApplication.java爲項目啓動入口

package com.example.demo;

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

@SpringBootApplication
public class DemoApplication {
	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
}

在DemoApplication.java所在包或所在包的子包下創建HelloController.java

package com.example.demo;

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

@RestController
public class HelloController {
    @RequestMapping("/")
    public String hello(){
        return "hello world!";
    }
}

運行項目,起來後在瀏覽器輸入如下地址即可訪問。
在這裏插入圖片描述

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