SpringBoot-Hello,Spring Boot2

SpringBoot-Hello,Spring Boot2

结构:

1.配置pom.xml

<parent>
       <artifactId>spring-tx</artifactId>
       <groupId>org.springframework</groupId>
       <version>4.0.0.RELEASE</version>
   </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

第一次可能会很慢,因为要下载很多依赖

2.创建主类

@SpringBootApplication
public class MainApplication {
    public static void main(String[] args) {
        SpringApplication.run(MainApplication.class,args);
    }
}

3.创建控制类

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String handler01(){
        return "Hello,Spring Boot2";
    }
}

4.注解解释

@SpringBootApplication:告诉springboot这是一个springboot应用

@RestController是以下注解的组合注解

  • @Target(ElementType.TYPE)
  • @Retention(RetentionPolicy.RUNTIME)
  • @Documented
  • @Controller
  • @ResponseBody:将controller的方法返回的对象通过适当的转换器转换为指定的格式之后,写入到response对象的body区,通常用来返回JSON数据或者是XML数据。

@RequestMapping:在Spring MVC 中使用 @RequestMapping 来映射请求,也就是通过它来指定控制器可以处理哪些URL请求,相当于Servlet中在web.xml中配置

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值