使用idea搭建spring boot + maven工程並執行hello world!
阿新 • • 發佈:2018-11-04
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!";
}
}
執行專案,起來後在瀏覽器輸入如下地址即可訪問。