快速上手Spring boot
2018-12-04 11:24
309 查看
Spring boot的设计出发点就是简化配置、简化开发,我们来看看用Spring boot如何简单几步就迅速搭建起一个web工程。
- 用Spring Initializr创建一个新工程,填好group、artifact等。
- 选择Web,点下一步就OK了。
- pom.xml中默认会有spring-boot-starter-web和spring-boot-starter-test两个依赖和spring boot的maven插件spring-boot-maven-plugin。
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
- 其实现在就可以运行WebApplication来启动Web项目了。
如果没有修改application.properties,默认spring使用的是tomcat的8080端口,只是访问起来那是个404页面。 - 我们再加个controller就好了,为了省事可以放在WebApplication里面。
@SpringBootApplication @RestController public class WebApplication { @RequestMapping("/") public String index() { return "Spring boot!"; } @RequestMapping("/hello/{name}") public String index(@PathVariable String name) { return "hello " + name + "!"; } public static void main(String[] args) { SpringApplication.run(WebApplication.class, args); } }
- 运行程序,打开浏览器,输入localhost:8080/ 或者 localhost:8080/hello/srpingboot 就可以看到结果!
相关文章推荐
- Spring Boot 2.0 WebFlux 上手系列课程:快速入门(一)
- Scala开发者的Spring-Boot快速上手指南 02:Scala惯用法
- Scala开发者的Spring-Boot快速上手指南 01
- 如何快速上手Spring Boot?
- 如何快速上手Spring Boot?
- Spring Boot 快速上手(八)集成Thymeleaf
- [转]Spring Boot 揭秘与实战(一) 快速上手
- Spring Boot 快速上手(七)集成ActiveMQ
- Spring Boot 快速上手(二)基本配置
- Spring Boot 快速上手(一)快速搭建
- SpringBoot快速上手
- 004-Spring boot 快速入门-项目搭建与启动、SpringBootApplication
- springboot快速实战搭建篇
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(一)Spring Boot介绍
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- 4000 教你十分钟快速搭建springBoot项目实战
- Spring-Boot快速搭建web项目详细总结
- 快速创建一个基于Gradle构建的SpringBoot Web项目(SpringBoot-01)
- Spring基础:快速入门spring boot(10):spring boot + sonarqube +jacoco