【學習 spring boot 第二天】編寫 Hello World
啓動 工程的三種方式
- java -jar 啓動方式
# 工程目錄下面進行工程編譯 cmd
gradle build
# 或使用 gardle w build
gradlew build
# 進度 編譯後的 jar 包目錄
cd build/libs
java -jar xxx.jar 啓動
- 使用 gradle 自帶的 spring boot 集成插件啓動
# 進入工程目錄 cmd
gradle runBoot
- 使用 java 文件啓動
編寫 hello world
新建目錄的約定。如果註解掃描不到 則 請求 URL 404
package com.laowan.blog.initializrstart.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @version V1.0
* @Title: HelloWorldController
* @Package
* @Description:
* @author: runoob
* @date:
*/
@RestController
public class HelloWorldController {
@RequestMapping("/hello" )
public String hello(){
return "hello world";
}
}