Spring Boot系列教程一:实现Hello World
2019-06-03 19:40
309 查看
一、利用idea创建一个project
- file->New->project
- Spring initializr -> https://start.spring.io
- 指定自己的工程名
- 选择web 和spring boot版本,可以在pom.xml文件中修改
**
5.pom.xml自动生成的
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <!--父工程--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.springboot</groupId> <artifactId>helloword</artifactId> <version>1.0-SNAPSHOT</version> <name>helloword</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <!--引入web依赖--> <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> </project>
二、编码
- 新建HelloController类
@RestController //@RestController =@Controller+@ResponseBody public class HelloController { @RequestMapping("/hello") //添加映射关系 public String hello(){ return "Hello World"; }
- 工程目录结构
三、启动测试
启动工程,springboot集成了tomcat
可以在application.properties中修改tomcat端口。server.port=8090
测试:成功输出
相关文章推荐
- Spring Boot系列教程二:创建第一个web工程 hello world
- Spring Boot系列教程三:使用devtools实现热部署
- Spring Boot系列教程五:使用properties配置文件实现多环境配置
- Spring Boot系列教程五:使用properties配置文件实现多环境配置
- Spring Boot系列教程三:使用devtools实现热部署
- Spring Boot系列01-Spring Boot + maven 实现Hello World
- Spring Boot系列教程二:创建第一个web工程 hello world
- Spring Boot系列教程三:使用devtools实现热部署
- Spring Boot系列教程五:使用properties配置文件实现多环境配置
- 补习系列-springboot 实现拦截的五种姿势
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- springboot系列教程(二)——Banner、CommandLineRunner、Arguments、Exit
- SpringBoot系列(十一)条件注解的底层实现
- Springboot微服务开发教程系列:开发入门
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- SpringBoot2.0系列教程(二)Sprignboot使用Druid连接池
- SpringBoot入门系列:第一篇 Hello World
- Spring Boot系列(十二)Spring Boot整合ActiveQ实现消息收发和订阅