SpringBoot学习--环境搭建

SpringBoot学习–环境搭建

SpringBoot的优点:

  • 快速构建项目
  • 对主流开发框架无配置集成
  • 项目可独立运行,无须外部以来Servlet容器
  • 提供运行时的应用监控
  • 极大地提高了开发和部署的效率
  • 与云计算天然集成

SpringBoot的缺点:

  • 对JSP的支持不友好,SpringBoot官方推荐使用thymeleaf

环境要求

项目构建

1.在eclipse中,通过file->new->other->spring stater project

这里写图片描述

2.点击next

这里写图片描述

3.勾选web模块支持

这里写图片描述

4.项目构建完成,其中DemoApplication.java是自动生成的SpringBoot启动类

这里写图片描述

5.打开DemoApplication.java文件,添加hello方法。这里采用SpringBoot推荐的@RestController注解,其实就是@Cotroller和@ResponseBody的集合。注意:如果想要另建一个Controller文件,请将该Controller所在的包放于DemoApplication.java同包之下,否则该Controller中的方法无法被访问。

扫描二维码关注公众号,回复: 179085 查看本文章
package com.gss.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/*@SpringBootApplication注解是Spring Boot的核心注解,它其实是一个组合注解,具体的可以参考SpringBoot的源码*/
@SpringBootApplication
@RestController
public class DemoApplication {

    @RequestMapping("/hello")
    public String hello() {
        return "Hello SpringBoot";
    }

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

6.直接run Java Application启动SpringBoot应用

7.浏览器上访问地址,这里的8099端口号可以在application.properties文件中进行配置

这里写图片描述

猜你喜欢

转载自blog.csdn.net/gu18724001186/article/details/80228370