I. Development Environment
1.Eclipse STS
2.maven 3.6.0 (Maven installation and configuration, etc. will not be discussed here, not a small partner can Baidu)
3.jdk1.8
4.SpringBoot2.1.5
II. Construction of Spring Boot project
1. Using maven to build SpringBoot project
When you first create a project, it will take a long time to download SpringBoot2.1.5 related jar package, need to be patient
2.SpringBoot starter
It is actually a collection jar package of so-called springBoot starter. SprigBoot offers a total of 44 starters.
2.1spring-boot-starter-web
Support full-stack web development, including romcat and springMVC such as jar
2.2 spring-boot-starter-jdbc
Set in a spring supported manner jdbc jar package database
2.3 spring-boot-starter-redis
Redis supports key-value store database operations
Three, Spring Boot entry HelloWorld
1. Write HelloWorld return of Controller
package com.example.demo.controller; import java.util.HashMap; import java.util.Map; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class HelloWorldController { @RequestMapping("/hello") @ResponseBody public Map<String, Object> showHelloWorld(){ Map<String, Object> map = new HashMap<>(); map.put("msg", "HelloWorld"); return map; } }
2.编写SpringBoot 启动类(创建工程的时候会自动生成一个启动器类)
package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
3.关于编写启动器需要注意的问题
启动器存放的位置。启动器可以和controller位于同一个包下,或者位于controller的上一级包中,但是不能放到controller的平级以及子包下。
4.启动SpringBoot
5.浏览器查看结果
总结
这就是SpringBoot的helloworld的入门程序,是不是特别简单,相比以前的开发少了很多的配置,只需要在pom.xml中添加一个web的启动器即可完成所有配置,但缺点在于第一次配置启动器,eclipse会自动下载相关的jar包,很耗时间。下一篇介绍如何在SpringBoot中整合WEB开发。