springboot 创建第一个简单的web案例。
使用工具idea;java8;maven-3.5.4
1、使用idea创建一个project ,选择Spring Initializr ,下一步,下一步,选择web项,下一步,finish.
2、pom.xml用来配置依赖,打开后能看到有web的相关依赖
<dependencies>
<!--web相关依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--测试类test依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
3、在DemoApplication类的同目录下创建一个ControllerDemo类如下
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/test")
public class ControllerDemo {
@RequestMapping("/demo01")
public String demo01(){
return "hello world!";
}
}
4、启动DemoApplication.java 该类在创建工程时自动生成
5、运行程序时查看日志端口为8080,使用浏览器进行访问:http://localhost:8080/test/demo01
这样一个简单的springbootweb案例就完成了。