Spring Boot的简单入门

Spring Boot的主要优势:web

  • 为全部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





    org.springframework.boot
    spring-boot-starter-web

  • 建立控制器Controller

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

@Controller
public class helloController {app

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

}maven

  • 建立一个引导类
    主要做用是做为启动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);
}
}spring-boot

  • 运行效果以下:
    code

  • 在web端访问 http://localhost:8080/hello
    xml

相关文章
相关标签/搜索