创建第一个SpringBoot

定义:
spring Boot是Spring社区发布的一个开源项目,旨在帮助开发者快速并且更简单的构建项目。大多数SpringBoot项目只需要很少的配置文件。


特质:
spring是一个全栈的开发框架,核心是IOC,AOP。springboot是为了简化spring开发而生的。


创建第一个SpringBoot 项目:
1 安装Gradle 插件。(翻墙)
2 创建Gradle 项目,并且为web项目。

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@RestController
@EnableAutoConfiguration
public class Example {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Example.class, args);
    }

}

The @RestController and @RequestMapping annotations are Spring MVC annotations (they are not specific to Spring Boot). See the MVC section in the Spring Reference Documentation for more details.
@RestController 和@RequestMapping 都是Spring MVC里面的注解。

简单来讲就系:
@RestController

    @ResponseBody和@Controller的合集

@RequestMapping

    提供路由信息,负责URL到Controller中的具体函数的映射。

@EnableAutoConfiguration

   The second class-level annotation is @EnableAutoConfiguration. This annotation tells Spring Boot to “guess” how you will want to configure Spring, based on the jar dependencies that you have added. Since spring-boot-starter-web added Tomcat and Spring MVC, the auto-configuration will assume that you are developing a web application and setup Spring accordingly.
   这个大概意思是,SpringBoot会尝试根据你添加的jar包,帮你配置Spring应用。由于spring-boot-starter-web已经添加了Tomcat和Spring MVC,所以会springboot 会帮你自动配置。

最后一个就系主方法:
java入口,通过SpringApplication类调用run()方法,会自动配置tomcat web server的。也就是相当于我们开启了tomcat服务器一样。

启动浏览器,输入 localhost:8080.就可以看到 Hello World!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值