【干货】如何快速构建SpringBoot Web服务
1 创建Maven工程
2 添加SpringBoot的起步依赖添加Maven依赖,项目要继承SpringBoot的起步依赖spring-boot-starter-parent<!--所有的springboot工程都必须继承spring-boot-starter-parent--><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.1.RELEASE</version></parent><!--web功能的起步依赖--><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;@SpringBootApplicationpublic class MySpringBootApplication {public static void main(String[] args) {SpringApplication.run(MySpringBootApplication.class);}}4 编写Controller在引导类MySpringBootApplication同级包或者子级包中创建QuickStartControllerimport org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;@Controllerpublic class QuickController {@RequestMapping("/quick")@ResponseBodypublic String quick(){return "ni hao springboot";}}5 Web资源 配置
6 项目结构
7 测试执行SpringBoot起步类的主方法,控制台打印日志。
打开浏览器访问url地址为:http://localhost:8085/testops/quick以上就是SpingBoot构建Web服务的流程,你是不是也觉得很简单,那就动起手来吧......微信号 : TestOps知乎:@TestOps云层