一、SpringBoot 介紹
- 第一次接觸和學習Spring框架的時候,是不是需要配置很多的XML文件。當Spring越來越用上手的時候,有沒有被這些繁瑣的配置感到厭煩?每次新建項目都要進行反覆的粘貼操作。如果你已經厭煩了這些操作,那你就必須來學習學習SpringBoot了。當然,如果你還喜歡那種配置,那註定你將與發展脫軌。
- 爲什麼我們要學習Springboot?原因是Spring Boot讓我們的Spring應用變的更輕量化。比如:你可以僅僅依靠一個Java類來運行一個Spring引用。你也可以打包你的應用爲jar並通過使用
java
-jar
來運行你的Spring Web應用。 - Spring Boot的主要優點:
爲所有Spring開發者更快的入門
開箱即用,提供各種默認配置來簡化項目配置
內嵌式容器簡化Web項目
沒有冗餘代碼生成和XML配置的要求
二、Hello World 程序
1、HelloController.java
package cn.lemon.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Description: TODO
* @author: lemon
* @date: 2020年06月28日 11:53
*/
/**
* @Controller : 標記在類上,說明這個類是SpringMVC Controller對象,分發處理器將會掃描使用了該註解的類的方法,返回頁面
* @RestController = @Controller + @ResponseBody 也就是 @RestController 返回的是 JSON數據格式的數據
*/
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello() {
return "hello world!!";
}
}
地址欄輸入:http://localhost:8080/hello