1 创建Maven工程
2 添加SpringBoot的起步依赖
添加Maven依赖,项目要继承SpringBoot的起步依赖spring-boot-starter-parent
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
3 编写SpringBoot引导类
要通过SpringBoot提供的引导类起步SpringBoot才可以进行访问.
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MySpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(MySpringBootApplication.class);
}
}
4 编写Controller
在引导类MySpringBootApplication同级包或者子级包中创建QuickStartController
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class QuickController {
@RequestMapping(“/quick”)
@ResponseBody
public String quick(){
return "ni hao springboot";
}
}
5 Web资源 配置
6 项目结构
7 测试
执行SpringBoot起步类的主方法,控制台打印日志。
打开浏览器访问url地址为:http://localhost:8085/testops/quick
以上就是SpingBoot构建Web服务的流程,你是不是也觉得很简单,那就动起手来吧….
声明:文中观点不代表本站立场。本文传送门:https://eyangzhen.com/187055.html