第一步创建maven项目
第二步导入springboot所需要的依赖以及父项目
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
第三步我们需要标注一个springBoot主程序类
@SpringBootApplication
//这里用注解
public class helloworld {
public static void main(String[] args) {
//然后让它跑起来
SpringApplication.run(helloworld.class,args);
}
}
第四步写一个controller接受客户端请求
@Controller
public class test {
@ResponseBody
@RequestMapping("hello")
public String test1(){
return "hello,word";
}
}
最后运行,在浏览器输入localhost:8080/hello。结果如下图
我们在导入依赖时,我们还导入了一个父项目,而导入这个父项目的作用就是让我们在导入依赖时不用写版本号了。通过查看父项目Ctrl+鼠标左键,可看到。
我们还导入了一个依赖,依赖作用是能够帮助我们省去web模块的依赖,也可以通过Ctrl+鼠标左键 看到。
这里还有一点就是关于starters,springboot将每一个应用场景封装成了每一个starters,我们只需要引入每一个starters相关场景的依赖,就能够使用了,例如上面的starters-web,就帮我们省去了tomcat以及springMvc的配置。