引入依赖
pom文件中添加依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</dependency>
</dependencies>
程序启动器
// 启动类上添加注解SpringBootApplication
@SpringBootApplication
public class HelloWorld {
public static void main(String[] args) {
// 传入两个参数 1:由@SpringBootApplication注解标注的启动类 2:main方法的参数
SpringApplication.run(HelloWorld.class, args);
}
}
编写控制层的Controller类
// 同以往MVC框架开发,编写controller
@RestController
public class HelloWorldController {
@RequestMapping("/index")
public String hello() {
return "Hello World";
}
}
运行启动类
运行启动类中的main方法即可
spring-boot内部集成的tomcat已运行在8080端口
访问localHost:8080/index