Spring Boot的简单入门

Spring Boot的主要优点:

  • 为所有Spring开发者更快的入门
  • 开箱即用,提供各种默认配置来简化项目配置
  • 内嵌式容器简化Web项目
  • 没有冗余代码生成和XML配置的要求
    创建基础项目:
  • 首先创建maven项目
  • 配置maven环境
    <--在pom.xml中添加Spring Boot相关的父级依赖 spring-boot-starter-parent提供了项目相关的默认依赖,使用它之后,常用的包可以省去version标签-->

    org.springframework.boot
    spring-boot-starter-parent
    2.0.6.RELEASE
<!-- Add typical dependencies for a web application -->
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
  • 创建控制器Controller

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class helloController {

@ResponseBody
@RequestMapping("/hello")
public String hello(){
    return "hello world!";
}

}

  • 创建一个引导类
    主要作用是作为启动Spring Boot项目的入口
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;

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

posted @ 2019-07-31 20:45  夜舞123  阅读(99)  评论(0编辑  收藏  举报