一.SpringBoot2 的基礎:
學習要求
? 熟悉Spring基礎
? 熟悉Maven使用
環境要求
? Java8及以上
? Maven 3.3及以上:https://docs.spring.io/spring-boot/docs/current/reference/html/getting-started.html#getting-started-system-requirements
學習資料
? 檔案地址: https://www.yuque.com/atguigu/springboot
? 檔案不支持舊版本IE、Edge瀏覽器,請使用chrome或者firefox
? 視頻地址: http://www.gulixueyuan.com/ https://www.bilibili.com/video/BV19K4y1L7MT?p=1
? 原始碼地址:https://gitee.com/leifengyang/springboot2
二.SpringBoot2的案例入門
1、系統要求
? Java 8 & 兼容java14 .
? Maven 3.3+
? idea 2019.1.2
1.1、maven設定
<mirrors>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>
2、HelloWorld
需求:瀏覽發送/hello請求,回應 Hello,Spring Boot 2
2.1、創建maven工程
2.2、引入依賴
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
2.3、創建主程式
/**
* 主程式類
* @SpringBootApplication:這是一個SpringBoot應用
*/
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class,args);
}
}
2.4、撰寫業務
@RestController
public class HelloController {
@RequestMapping("/hello")
public String handle01(){
return "Hello, Spring Boot 2!";
}
}
2.5、測驗
直接運行main方法
2.6、簡化配置
application.properties
server.port=8888
2.7、簡化部署
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
把專案打成jar包,直接在目標服務器執行即可,
注意點:
? 取消掉cmd的快速編輯模式
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/248856.html
標籤:Java
上一篇:redis探秘:選擇合適的資料結構,減少80%的記憶體占用,這些點你get到了嗎?
下一篇:深入淺出AQS之共享鎖模式
