Spring Boot 快速创建Hello Wolrd
1. 用eclipse创建java maven项目
2.创建HelloController类 , src/main/java/hello/HelloController.java
package hello;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/hello-world")
public class HelloController {
@RequestMapping(method=RequestMethod.GET)
public @ResponseBody String index() {
return "Hello World!";
}
}
3.创建Application 类 ,src/main/java/hello/Application.java
package hello;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.SpringApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
4.在 src/main/resources/application.properties 添加 server.port=8080
5.运行 Application.java
6. 打开浏览器访问 http://localhost:18080/hello-world 能看到 Hello Wolrd! 成功
浙公网安备 33010602011771号