最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

黑馬程序員SpringBoot2全套視頻教程,springboot零基礎(chǔ)到項(xiàng)目實(shí)

2023-09-22 23:29 作者:Wabi-Sabifag  | 我要投稿

# 1.SpringBoot

## 1.Rest風(fēng)格


### 1.1Rest


#### 1.1.1 Rest簡(jiǎn)介


* Rest 表現(xiàn)形式狀態(tài)轉(zhuǎn)換

**傳統(tǒng)風(fēng)格**

- http://localhost/user/getById?id=1


- http://localhost/user/saveUser


**Rest風(fēng)格**

- http://localhost/user/1????????????(查詢單數(shù),刪除用戶信息)


- http://localhost/user????????????????(查詢復(fù)數(shù),添加,修改用戶信息)


**優(yōu)點(diǎn)**


* 隱藏資源訪問(wèn)行為

?

* 書寫簡(jiǎn)化

?


#### 1.1.2 地址欄傳參模式----參數(shù)配置


* method = RequestMethod.GET? ? 查詢

?

* method = RequestMethod.POST ? 保存

?

* method = RequestMethod.DELETE 刪除

?

* method = RequestMethod.HEAD

?

* method = RequestMethod.PUT ? ?更新

?

* method = RequestMethod.OPTIONS

?

* method = RequestMethod.PATCH

?

* method = RequestMethod.TRACE


```

? ? package top.wabisabifag.controller;

? ?

? ?

? ? import org.springframework.web.bind.annotation.*;

? ?

? ? @Controller

? ? public class UserController {

? ?

? ? ? ? @RequestMapping(value = "/users",method = RequestMethod.POST)

? ? ? ? @ResponseBody

? ? ? ? public String save(){

? ? ? ? ? ? System.out.println("user save...");

? ? ? ? ? ? return "{'module':'user save'}";

? ? ? ? }

? ?

? ? ? ? /**

? ? ? ? ?* {id} ? ? ? ? ? ? 代表請(qǐng)求格式,對(duì)應(yīng)方法的傳參值

? ? ? ? ?* @PathVariable ? ?指定 id 的所取值,url地址傳給方法

? ? ? ? ?*/

? ? ? ? @RequestMapping(value = "/users/{id}",method = RequestMethod.DELETE)

? ? ? ? @ResponseBody

? ? ? ? public String delete(@PathVariable Integer id){

? ? ? ? ? ? System.out.println("user delete..."+id);

? ? ? ? ? ? return "{'module':'user delete'}";

? ? ? ? }

? ?

? ? ????@RequestMapping(value = "/users",method = RequestMethod.PUT)

? ? ? ? @ResponseBody

? ? ? ? public String update(@RequestBody User user){

? ? ? ? ? ? System.out.println("user update..."+user);

? ? ? ? ? ? return "{'module':'user update'}";

? ? ? ? }

? ?

? ? ????/*

? ? ? ? * @RequestMethod.GET ?專門查詢語(yǔ)句

? ? ? ? */

? ? ? ? @RequestMapping(value = "/users/{id}",method = RequestMethod.GET)

? ? ? ? @ResponseBody

? ? ? ? public String getById(@PathVariable Integer id){

? ? ? ? ? ? System.out.println("user getById..."+id);

? ? ? ? ? ? return "{'module':'user getById'}";

? ? ? ? }

? ?

? ? ? ? @RequestMapping(value = "/users",method = RequestMethod.GET)

? ? ? ? @ResponseBody

? ? ? ? public String getAll(){

? ? ? ? ? ? System.out.println("user getAll...");

? ? ? ? ? ? return "{'module':'user getAll'}";

? ? ? ? }

? ? }

```


總結(jié):


????區(qū)別


* @RequestParam 用于接受 url 地址傳參或表單傳參

?

* @RequestBody 用于接受json數(shù)據(jù)

?

* @PathVariable 用于接收路徑參數(shù),使用 {name} 描述路徑參數(shù)

?


????應(yīng)用


* 后期開發(fā),發(fā)送請(qǐng)求超過(guò)一個(gè)參數(shù),以json格式,@RequestBody 應(yīng)用為主

?

* 如果發(fā)送非json格式數(shù)據(jù),選用@RequestParam 接收請(qǐng)求參數(shù)

?

* 采用RESTful進(jìn)行開發(fā),當(dāng)參數(shù)較少時(shí),采用@PathVariable 接收請(qǐng)求路徑變量,傳遞 id 值

?


#### 1.1.3 Rest快速開發(fā)

```

? ? package top.wabisabifag.controller;

? ?

? ?

? ? import org.springframework.web.bind.annotation.*;

? ?

? ? @RestController

? ? @ResponseBody

? ? //@RestController

? ? @RequestMapping("/users")

? ? public class UserController {

? ?

? ? ? ? @PostMapping

? ? ? ? public String save(@RequestBody User user){

? ? ? ? ? ? System.out.println("user save...");

? ? ? ? ? ? return "{'module':'user save'}";

? ? ? ? }

? ?

? ? ? ? /**

? ? ? ? ?* {id} ? ? ? ? ? ? 代表請(qǐng)求格式,對(duì)應(yīng)方法的傳參值

? ? ? ? ?* @PathVariable ? ?指定 id 路徑 的 所取值

? ? ? ? ?*/

? ? ? ? @DeleteMapping("/{id}")

? ? ? ? public String delete(@PathVariable Integer id){

? ? ? ? ? ? System.out.println("user delete..."+id);

? ? ? ? ? ? return "{'module':'user delete'}";

? ? ? ? }

? ? ? ? @PutMapping

? ? ? ? public String update(@RequestBody User user){

? ? ? ? ? ? System.out.println("user update..."+user);

? ? ? ? ? ? return "{'module':'user update'}";

? ? ? ? }

? ?

? ? ? ? /*

? ? ? ? * @RequestMethod.GET ?專門查詢語(yǔ)句

? ? ? ? */

? ? ? ? @GetMapping("/{id}")

? ? ? ? public String getById(@PathVariable Integer id){

? ? ? ? ? ? System.out.println("user getById..."+id);

? ? ? ? ? ? return "{'module':'user getById'}";

? ? ? ? }

? ?

? ? ? ? @GetMapping

? ? ? ? public String getAll(){

? ? ? ? ? ? System.out.println("user getAll...");

? ? ? ? ? ? return "{'module':'user getAll'}";

? ? ? ? }

? ?

? ? }

```

主要點(diǎn):


????簡(jiǎn)化


* @RestController????????????等價(jià)@ResponseBody < < ==== > > @RestController (目的:省略重復(fù))

* value = "/users" 省略:value 但不能省略傳遞的 {name} 值

* method = RequestMethod. { } @...Mapping代替


?????單值 和 POJO值 的傳值方式


* @PathVariable 單值傳輸

?

* @RequestBody POJO值傳輸



## 2.基礎(chǔ)配置

[SpringBoot文檔地址](https://docs.spring.io/spring-boot/docs/current/reference/html/)

### 2.1 屬性配置


[SpringBoot Appilcation.properties文檔地址](https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#appendix.application-properties)


#### 2.1.1 Springboot 多種屬性配置(文件優(yōu)先級(jí)遞減)

- .properties

? + server.port=80

- .yml

? + server:

? ? ? port: 80

- .yaml

? + server:

? ? ? port: 80

##### 1.yml格式

1. 多層級(jí)屬性名

```

a:

? b:

? ? C: 1145137

```

2. 數(shù)組屬性名

```

likes:

? - games

? - foods

? - books


# 縮略模式

likes:[games,foods,books]

```


3. 對(duì)象數(shù)組屬性名

```

users:

? - name: zhangsan

? ? age: 18

? - name: Jhon

? ? age: 16


# 縮略模式

users:[{name:zhangsan,age:18},{name:Jhon,age:16}]

```


##### 2.數(shù)據(jù)讀取

```

@value("${users.name}")

private String name;


@value("${likes[1]}")

private String games;


@value("${users[1].name}")

private String name;



application.properties

----------------------

baseDir: c:\windows


# 使用 ${value} 引用數(shù)據(jù)

tempDir: ${baseDir}\temp

---------------------

```

屬性值(value)用 "\"轉(zhuǎn)義字符 的會(huì)不顯示

使用 “spring\boot\text.txt"


##### 3.封裝數(shù)據(jù)

1. 全配置封裝

```

//自動(dòng)裝配

@Autowired

private Environment environment;


environment.getProperty("users[0].name");

```

2. 針對(duì)性封裝

```

spring:

? datasource:

? ? url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false

? ? username: root

? ? password: 123456

? ? driver: com.mysql.jdbc.Driver


---------------------


# 1.創(chuàng)建類,封裝數(shù)據(jù)

package top.wabisabifag.POJO;


import org.springframework.boot.context.properties.ConfigurationProperties;

import org.springframework.stereotype.Component;


# 2.Spring加載數(shù)據(jù)對(duì)象,告訴Spring加載信息

@Component

@ConfigurationProperties(prefix = "spring.datasource")

public class MyDataSource {

? ? private String url;

? ? private String username;

? ? private String password;

? ? private String driver;


? ? @Override

? ? public String toString() {

? ? ? ? return "MyDataSource{" +

? ? ? ? ? ? ? ? "url='" + url + '\'' +

? ? ? ? ? ? ? ? ", username='" + username + '\'' +

? ? ? ? ? ? ? ? ", password='" + password + '\'' +

? ? ? ? ? ? ? ? ", driver='" + driver + '\'' +

? ? ? ? ? ? ? ? '}';

? ? }


? ? public String getUrl() {

? ? ? ? return url;

? ? }


? ? public void setUrl(String url) {

? ? ? ? this.url = url;

? ? }


? ? public String getUsername() {

? ? ? ? return username;

? ? }


? ? public void setUsername(String username) {

? ? ? ? this.username = username;

? ? }


? ? public String getPassword() {

? ? ? ? return password;

? ? }


? ? public void setPassword(String password) {

? ? ? ? this.password = password;

? ? }


? ? public String getDriver() {

? ? ? ? return driver;

? ? }


? ? public void setDriver(String driver) {

? ? ? ? this.driver = driver;

? ? }

}


---------------------------------


# 3.使用Spring獲取的信息

@Autowired

private MyDataSource myDataSource;


```


#### 2.1.2 修改服務(wù)器端口

```

# 配置服務(wù)器端口

server.port=80


# 修改Spring啟動(dòng)的banner


# 關(guān)閉Spring Logo

spring.main.banner-mode=off

# 將text,png等文件轉(zhuǎn)化為二維圖

#spring.banner.image.location=1.png


# 控制日志


# 輸出日志級(jí)別

#logging.level.root=debug

# 在出錯(cuò)時(shí)輸出日志

logging.level.root=error

```



## 3.第三方技術(shù)整合


### 1.JUnit

```

package top.wabisabifag.dao.Impl;


import org.springframework.stereotype.Repository;

import top.wabisabifag.dao.BookDao;


/* 3.接受Spring管理 */

@Repository

public class BookDaoImpl implements BookDao {

? ? @Override

? ? public void save() {

? ? ? ? System.out.println("BookDao testing");

? ? }

}


-------------------------------


package top.wabisabifag.test;


import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.boot.test.context.SpringBootTest;

import top.wabisabifag.dao.BookDao;


/* 4.獲取Spring管理聲明 */

@SpringBootTest

public class SpringBootJUnitApplicationTests {

? ? /*1.注入測(cè)試對(duì)象*/

? ? @Autowired

? ? private BookDao bookDao;


? ? /*2.執(zhí)行測(cè)試方法*/

? ? @Test

? ? void contextLoads(){

? ? ? ? bookDao.save();

? ? }

}

```

1. 當(dāng)test 測(cè)試路徑無(wú)法對(duì)應(yīng)java 源代碼路徑


? @SpringBootTest(classes = BookDaoImpl.class)來(lái)申明源碼

? ?

```

@SpringBootTest(classes = BookDaoImpl.class)

```

? @RunWith(設(shè)置運(yùn)行器)

? @ContextConfiguration(class = .... ) ? ?//配置引導(dǎo)類或配置類


+ ContextConfiguration 用于在當(dāng)前包下查找聲明類


### 2.Mybatis

```

-------pom 獲取MP依賴-----------

?<dependency>

? ? ? <groupId>com.baomidou</groupId>

? ? ? <artifactId>mybatis-plus-boot-starter</artifactId>

? ? ? <version>3.4.2</version>

? ? </dependency>

--------繼承 BaseMapper-------

package top.wabisabifag.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import org.apache.ibatis.annotations.Mapper;

import org.apache.ibatis.annotations.Select;

import top.wabisabifag.POJO.Book;


@Mapper ? ? ? ? ? // ?繼承 BaseMapper

public interface BookDao extends BaseMapper {

? ? public void save();

? ? @Select("select * from smbms_user where userid = #{id} ")

? ? public Book getById(int id);

}


----------使用MP方法--------------


package top.wabisabifag.test;


import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.boot.test.context.SpringBootTest;

import top.wabisabifag.dao.BookDao;

import top.wabisabifag.dao.Impl.BookDaoImpl;


@SpringBootTest(classes = BookDaoImpl.class)

public class SpringBootJUnitApplicationTests {

? ? /*1.注入測(cè)試對(duì)象*/

? ? @Autowired

? ? private BookDao bookDao;


? ? /*2.執(zhí)行測(cè)試方法*/

? ? @Test

? ? void contextLoads(){

? ? ? ? bookDao.save();

? ? ? ? bookDao.getById(1);

? ? }

? ? @Test

? ? void contextLoadsPlus(){

? ? ? ? System.out.println(bookDao.selectById(2));

? ? }

}


--------配置文件中相關(guān)數(shù)據(jù)庫(kù)表名稱映射-----------


#配置MP相關(guān)數(shù)據(jù)庫(kù)名稱

mybatis-plus:

? global-config:

? ? db-config:

? ? ? table-prefix: tb_



```

### 4.Lombok

```

-------pom 獲取Lombok依賴--------

<dependency>

? ? ? <groupId>org.projectlombok</groupId>

? ? ? <artifactId>lombok</artifactId>

? ? </dependency>


--------POJO 實(shí)體類注解省略Get,Set--------

package top.wabisabifag.domain;


import lombok.AllArgsConstructor;

import lombok.Data;

import lombok.NoArgsConstructor;

import lombok.ToString;


@Data ?// ?@Getter @Setter

@NoArgsConstructor ?// 無(wú)參構(gòu)造

@AllArgsConstructor // 有參構(gòu)造

@ToString ?

public class User {

? ? private int id;

? ? private String userCode;

}




```

主要:

- @Getter @Setter 等價(jià)于 @Data


### 5.Druid

```

------pom 獲取Druid依賴------

<dependency>

? ? ? <groupId>com.alibaba</groupId>

? ? ? <artifactId>druid-spring-boot-starter</artifactId>

? ? ? <version>1.1.23</version>

? ? </dependency>


-------配置--------

通用配置:

spring:

? datasource:

? ? url: jdbc:mysql://localhost:3306/smbms_db?useUnicode=true&characterEncoding=UTF-8&useSSL=false

? ? username: root

? ? password: 123456

? ? driver-class-name: com.mysql.jdbc.Driver

? ? type: com.alibaba.druid.pool.DruidDataSource


整合配置:

spring:

? datasource:

? ? druid:

? ? ? url: jdbc:mysql://localhost:3306/smbms_db?useUnicode=true&characterEncoding=UTF-8&useSSL=false

? ? ? username: root

? ? ? password: 123456

? ? ? driver-class-name: com.mysql.jdbc.Driver

```






## 2.SSMP整合案例


+ 實(shí)體類開發(fā) ? ? ? ? ? ? ? ?使用Lombok 快速制作實(shí)體類

+ Dao 開發(fā) ? ? ? ? ? ? ? ? ?整合MyBatisPlus ,制作數(shù)據(jù)層測(cè)試類

+ Service 開發(fā) ? ? ? ? ? ? ?基于MyBatisPlus 進(jìn)行增量開發(fā),制作業(yè)務(wù)層測(cè)試類

+ Controller 開發(fā) ? ? ? ? ? 基于Restful 開發(fā),使用PostMan 測(cè)試接口功能

+ Controller 開發(fā) ? ? ? ? ? 前后端開發(fā)協(xié)議制作

+ 頁(yè)面開發(fā) ? ? ? ? ? ? ? ? ?基于VUE,Element制作,前后端聯(lián),頁(yè)面數(shù)據(jù)處理

? ? - CRUD 分頁(yè),查詢操作

+ 項(xiàng)目異常處理

+ 按條件查詢 ? ? ? ? ? ? ? ?頁(yè)面功能調(diào)整,Controller修正功能,Service修正功能


### SMMP源代碼

[源代碼]()









## 3.SpringBoot維護(hù)


### 1.工程運(yùn)行


#### 1.Windows jar 包執(zhí)行

```

1. 執(zhí)行jar 包: java -jar packageName

2. 查詢端口: netstat -ano

3. 查詢指定端口: netstat -ano |findstr "端口號(hào)"

4. 根據(jù)進(jìn)程PID 查詢進(jìn)程名稱: tasklist |findstr "進(jìn)程號(hào)PID號(hào)"

5. 根據(jù)PID 殺死任務(wù): tasklist /F /PID "進(jìn)程PID號(hào)"

6. 根據(jù)進(jìn)程名稱殺死任務(wù): taskkill -f -t -im "進(jìn)程名稱" ? ? 進(jìn)程名稱有多個(gè)相同的

```

#### 2.Linux jar 包執(zhí)行

```

1. 啟動(dòng)后端: nohup java -jar jarPackageName > server.log 2>&1 &

```

#### 3.臨時(shí)屬性配置

```

1. 執(zhí)行jar 包: java -jar packageName --server.port=8080 --spring.datasouce.druid.password=root


2.

@SpringBootApplication

@MapperScan("top.wabisabifag.dao")/*使用@MapperScan可以指定要掃描的Mapper類的包的路徑*/

@ComponentScan(basePackages={"top.wabisabifag"})

public class application {

? ? public static void main(String[] args) {

? ? ? ? // 線程安全問(wèn)題

? ? ? ? // SpringApplication.run(application.class,args);

? ? ? ? // 不接受外部臨時(shí)參數(shù)

? ? ? ? SpringApplication.run(application.class);

? ? }

}


3. application.yml 的雙配置


文件位置: ?1. web/springboot.jar/resources/application.yml ?

? ? ? ? ? ?2. web/springboot.jar/resources/config/application.yml

? ? ? ? ? ?3. web/application.yml

? ? ? ? ? ?4. web/config/application.yml


? ? 重 ?復(fù): 文件優(yōu)先級(jí)配置高覆蓋低的;

? ? 不重復(fù): 互不干擾;


? ? 權(quán)限等級(jí): 逐級(jí)上升(4 > 3 > 2 > 1)

? ? 文件內(nèi)config/ .yml ?> 文件外 .properties


```


#### 4.多環(huán)境開發(fā)

##### 1. YAML

```

# 一、應(yīng)用環(huán)境

spring:

? profiles:

? ? active: pro

---

# 二、設(shè)置環(huán)境

# 1. 公共環(huán)境



# 2. 自定義環(huán)境

spring:

? profiles: pro

server:

? port:80

---

spring:

? profiles: dev

server:

? port:81

---

spring:

? config:

? ? activate:

? ? ? on-profiles: test

server:

? port:82


```

###### YAML 弊端

1.--- : 分割線是格式需求

2.容易暴露信息,安全有問(wèn)題


###### YAML 優(yōu)化

生成配置文件:

? ? application-dev.yml

? ? application-pro.yml

? ? application-test.yml

? ? 可以獨(dú)立配置文件定義環(huán)境;

? ? 獨(dú)立配置文件便于線上系統(tǒng)維護(hù)更新并保障系統(tǒng)安全性;



##### 2. properties

- 文件內(nèi)容格式

```

spring.profiles=pro

server.port=80

---

spring.profiles=dev

server.port=81

---

spring.profiles=test

spring.profiles=82

```

- 生成配置文件:

? ? application-dev.properties

? ? application-pro.properties

? ? application-test.properties


##### 3. 獨(dú)立的功能配置文件

- 根據(jù)功能 對(duì)配置文件的信息拆分

? ? + application-devDB.yml

? ? + application-devRedis.yml

? ? + application-devMVC.yml

- application.yml 中使用include 屬性在激活指定環(huán)境 條件下,同時(shí)對(duì)多環(huán)境進(jìn)行加載

? ? + application.yml 后加載

? ? ```

? ? spring:

? ? ? profiles:

? ? ? ? active: dev

? ? ? ? include: devDB,devRedis,devMVC

? ? ```

###### 優(yōu)化 include 無(wú)法動(dòng)態(tài)更改問(wèn)題

? ? + application.yml 前加載

SpringBoot 2.4.X 后:

```

spring:

? ? ? profiles:

? ? ? ? active: dev

? ? ? ? group:

? ? ? ? ? "dev": devDB,devRedis,devMVC

? ? ? ? ? "pro": proDB,proRedis,proMVC

? ? ? ? ? "test": testDB,testRedis,testMVC

```



##### 4. 多環(huán)境開發(fā)控制(Maven)

1. pom.xml

```

? <!--設(shè)置多環(huán)境-->

? <profiles>

? ? <profile>

? ? ? ? <id>env_dev</id>

? ? ? ? <properties>

? ? ? ? ? <profile.active>dev</profile.active>

? ? ? ? </properties>

? ? ? <!--設(shè)置默認(rèn)啟動(dòng)-->

? ? ? ? <activation>

? ? ? ? ? <activeByDefault>true</activeByDefault>

? ? ? ? </activation>

? ? </profile>


? ? <profile>

? ? ? <id>env_pro</id>

? ? ? <properties>

? ? ? ? <profile.active>pro</profile.active>

? ? ? </properties>

? ? </profile>

? </profiles>

```

2. application.yml

```

spring:

? ? ? profiles:

? ? ? ? <!-- 使用Maven 的環(huán)境配置的格式 "@....@" -->

? ? ? ? active: @profile.active@

? ? ? ? group:

? ? ? ? ? "dev": devDB,devRedis,devMVC

? ? ? ? ? "pro": proDB,proRedis,proMVC

? ? ? ? ? "test": testDB,testRedis,testMVC

```

- ieda 對(duì)Maven 環(huán)境的更改無(wú)法生效,需要手動(dòng)編譯compile




#### 5. 日志


##### 1. 日志設(shè)置

1. 代碼中使用日志工具記錄日志

```

@RestController

@RequestMapping("/users")

@CrossOrigin

public class UserController {

? ? private static final Logger log = (Logger) LoggerFactory.getLogger(UserController.class);


? ? @GetMapping("/{id}")

? ? public User getById(@PathVariable Integer id){

? ? ? ? // application.yml ? debug:true

? ? ? ? log.debug("debug...");

? ? ? ? log.info("info...");

? ? ? ? log.warning("warn...");

? ? ? ? log.error();

? ? ? ? log.fatal();

? ? ? ? return userService.getById(id);

? ? }

}

```

2. 設(shè)置日志級(jí)別

```

# 開啟debug模式,輸出調(diào)試信息,常用于檢查系統(tǒng)運(yùn)行狀況

debug: true


# 設(shè)置日志級(jí)別 root表示根節(jié)點(diǎn),整體應(yīng)用日志級(jí)別

logging:

? level:

? ? root:

? ? ? error

? ? ? # 設(shè)置某包的日志級(jí)別

? ? ? top.wabisabifag.controller: debug

? ? ? # 設(shè)置分組,對(duì)某個(gè)祖設(shè)置日志級(jí)別

? ? ? enable:warn

```


##### 2. 日志工具 (動(dòng)態(tài)和繼承)

1. 設(shè)置日志對(duì)象

```

package top.wabisabifag.controller.Logger;


import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import top.wabisabifag.controller.UserController;


public class LoggerClass {

? ? private Class clazz = null;

? ? public static ?Logger log;

? ? public LoggerClass(){

? ? ? ? clazz = this.getClass();

? ? ? ? log = LoggerFactory.getLogger(UserController.class);

? ? }

}

```


2. 日志工具引入控制層

```

package top.wabisabifag.controller.Logger;


import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.*;


@Slf4j ? ? ?// 開啟日志

@RestController

@RequestMapping("/users")

@CrossOrigin

public class UserController3 extends LoggerClass {

? ? ? @GetMapping("/{id}")

? ? public String getById(@PathVariable Integer id){

? ? ? ? log.debug("debug...");

? ? ? ? log.info("info...");

? ? ? ? log.warning("warn...");

? ? ? ? log.error("error...");

? ? ? ? log.fatal();

? ? ? ? return "springboot is running... 2";

? ? }

}

```


##### 3. 日志輸出格式

1. 控制臺(tái)日志輸出

```

# 日志配置

logging:

? level:

? ? root:

? ? ? error

? pattern:

? ? console: "%d %clr(5p) --- [%16t] %clr(%-40.40c){red} :%m %n"

```

- d 日期

- p 信息的級(jí)別

- %clr(%5p) ?顏色設(shè)置

- %5p ?占據(jù)的長(zhǎng)度 ?

- [%16 t] 運(yùn)行的文件

- %-40 左對(duì)齊

- .40c 截?cái)嗪螅菁{40長(zhǎng)度

- m 消息

- n 換行


2. 日志記錄

```

# 日志配置

logging:

? level:

? ? root:

? ? ? error

? # 控制臺(tái)日志輸出

? pattern:

? ? console: "%d %clr(5p) --- [%16t] %clr(%-40.40c){red} :%m %n"

? # 日志文件記錄

? file:

? ? name: server.log

? # 日志分期記錄

? logback:

? ? rollingpolicy:

? ? ? max-file-size: 3KB

? ? ? file-name-pattern: server.%d{yyyy-MM-dd}.%i.log

? ? ? # 輸出格式: server.2023-09-20.0.log

```



## 4.SpringBoot 應(yīng)用開發(fā)

### 1. 熱部署

```

<dependency>

? ? ? <groupId>org.springframework.boot</groupId>

? ? ? <artifactId>spring-boot-devtools</artifactId>

? ? </dependency>

```

在IEDA激活熱部署: Ctrl + F9 ?

黑馬程序員SpringBoot2全套視頻教程,springboot零基礎(chǔ)到項(xiàng)目實(shí)的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
上饶市| 凌源市| 项城市| 惠州市| 通化县| 台南市| 门源| 鹤壁市| 台南县| 井陉县| 长岛县| 凤庆县| 合山市| 桂阳县| 重庆市| 方城县| 将乐县| 青浦区| 黄大仙区| 白河县| 临夏县| 北京市| 西林县| 峨眉山市| 扎鲁特旗| 泸西县| 新余市| 监利县| 高阳县| 宁阳县| 天门市| 商城县| 汝州市| 忻州市| 靖安县| 始兴县| 大庆市| 穆棱市| 台东县| 金寨县| 长宁县|