步骤:
(1)在pom.xml文件中引入相关依赖;
(2)新建启动类App.java
(3)编写HelloWorldController;
1、加入相关依赖:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> </parent>
<properties> <java.version>1.7</java.version> </properties>
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
</dependencies>
|
2、新建启动类App.java。
1 2 3 4 5 6 7
| @SpringBootApplication public class App { public static void main(String[] args) { SpringApplication.run(App.class) ; } }
|
3、新增HelloWorldController.java:
1 2 3 4 5 6 7 8
| @RestController public class HelloWorldController { @RequestMapping("/hello") public String index() { return "Hello World"; } }
|
运行App.java,控制台出现如下提示:
Tomcat started on port(s): 8080 (http)。
说明启动成功!端口号默认为8080。
浏览器输入:http://127.0.0.1:8080/hello
出现如下结果:
Success!