zoukankan      html  css  js  c++  java
  • SpringBoot 快速入门

    使用SpringBoot实现一个简单功能,使用maven搭建:

      浏览器发送hello请求,服务器接受请求并处理,响应Hello World字符串;

    1.创建Maven工程

    2.在pom.xml里面引入springboot依赖

    1 <parent>
    2     <groupId>org.springframework.boot</groupId>
    3     <artifactId>spring-boot-starter-parent</artifactId>
    4     <version>2.1.3.RELEASE</version>
    5  </parent>

    3.添加spring-boot启动器依赖

    1 <dependencies>
    2     <dependency>
    3         <groupId>org.springframework.boot</groupId>
    4         <artifactId>spring-boot-starter-web</artifactId>
    5     </dependency>
    6 </dependencies>

     4.编写一个主程序;启动Spring Boot应用 

    1 //@SpringBootApplication 来标注一个主程序类,说明这是一Spring Boot应用 
    2 @SpringBootApplication 
    3 public class HelloWorldMainApplication {        
    4        public static void main(String[] args) {           
    5        // Spring应用启动起来         
    6 SpringApplication.run(HelloWorldMainApplication.class,args);     
    7 }
    8 }

    5.编写相关的Controller、Service 

    1 @Controller 
    2 public class HelloController {       
    3     @ResponseBody     
    4     @RequestMapping("/hello")     
    5     public String hello(){         
    6          return "Hello World!";    
    7     } 
    8 }

    6.运行主程序测试 ,启动HelloWorldMainApplication这个类

    1 //在地址栏上面输入
    2 localhost:8080/hello

    小知识:

           第5个步骤上面的使用为@controller这个常规写法,在SpringBoot里面可以将@controller和@ResponseBody  结合使用,写成@RestController

  • 相关阅读:
    splice九重天
    数组
    数组方法valueOf的用武之地
    已经有一个项目的源码如何将其推送到远程服务器
    【holm】并行Linq(PLinq)
    【holm】C# 使用Stopwatch准确测量程序运行时间
    【holm】url,href,src三者之间的关系
    【holm】C#线程监视器Monitor类使用指南
    【holm】MySQL锁机制
    【holm】MySQL事务的使用
  • 原文地址:https://www.cnblogs.com/pcliu/p/11099079.html
Copyright © 2011-2022 走看看