Spring Boot 框架概述

1. 簡介

Spring Boot 是由 Pivotal 團隊開發的一個用于簡化 Spring 應用開發的框架。它通過提供默認配置、嵌入式服務器和自動配置等特性,讓開發者能夠更快速地構建獨立的、生產級別的 Spring 應用。
Spring Boot 的主要特點包括:

  • 快速創建獨立的 Spring 應用
  • 內嵌 Tomcat、Jetty 或 Undertow 等服務器
  • 提供 “starter” 依賴簡化構建配置
  • 自動配置 Spring 和第三方庫
  • 提供生產就緒型特性,如指標監控、健康檢查等
  • 無需 XML 配置

2. 環境準備

2.1 JDK 安裝

Spring Boot 要求 JDK 8 或更高版本。你可以從 Oracle 官方網站或 OpenJDK 下載并安裝適合你操作系統的 JDK。
安裝完成后,驗證 JDK 版本:

bash
java -version

2.2 Maven 或 Gradle 安裝

Spring Boot 項目可以使用 Maven 或 Gradle 進行構建。
Maven 安裝

  1. 從 Maven 官方網站下載最新版本的 Maven
  2. 解壓下載的文件到本地目錄
  3. 配置環境變量 MAVEN_HOME 和 PATH
  4. 驗證 Maven 安裝:
bash
mvn -version

Gradle 安裝

  1. 從 Gradle 官方網站下載最新版本的 Gradle
  2. 解壓下載的文件到本地目錄
  3. 配置環境變量 GRADLE_HOME 和 PATH
  4. 驗證 Gradle 安裝:
bash
gradle -v

3、快速開始

3.1 使用 Spring Initializr 創建項目**

Spring Initializr 是一個基于 Web 的工具,可以幫助你快速創建 Spring Boot 項目骨架。

  1. 訪問 Spring Initializr
  2. 配置項目元數據:
    。Project: 選擇 Maven Project 或 Gradle Project
    。Language: 選擇 Java
    。Spring Boot: 選擇合適的版本
    。Group 和 Artifact: 填寫項目的包名和名稱
  3. 添加依賴:
    。至少添加 “Spring Web” 依賴
    。根據需要添加其他依賴,如 “Spring Data JPA”、“Thymeleaf” 等
  4. 點擊 “Generate” 按鈕下載項目壓縮包
  5. 解壓下載的文件到本地目錄

3.2 項目結構

使用 Spring Initializr 創建的項目結構通常如下:

plaintext
src/main/java/com/example/demo/DemoApplication.javaresources/application.propertiesstatic/templates/test/java/com/example/demo/DemoApplicationTests.java
pom.xml 或 build.gradle

3.3 第一個 Spring Boot 應用

下面是一個簡單的 Spring Boot Web 應用示例:

java
package com.example.demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);
}@GetMapping("/hello")
public String hello() {return "Hello, Spring Boot!";
}

}
這個應用包含:

  • @SpringBootApplication 注解:標識這是一個 Spring Boot 應用
  • main 方法:應用的入口點,啟動 Spring Boot 應用
  • @RestController 注解:標識這是一個 RESTful 控制器
  • @GetMapping 注解:處理 HTTP GET 請求

3.4 運行應用

你可以通過以下方式運行 Spring Boot 應用:
使用命令行
在項目根目錄下執行:

bash
mvn spring-boot:run

bash
gradle bootRun

使用 IDE
在 IDE 中打開項目,找到 DemoApplication 類,運行其 main 方法。
應用啟動后,訪問 http://localhost:8080/hello,你應該能看到 “Hello, Spring Boot!” 的響應。

4. 核心特性

4.1 自動配置

Spring Boot 的自動配置是其核心特性之一。它根據你項目中添加的依賴和配置,自動配置 Spring 應用的各種組件。
例如,如果你添加了 “Spring Data JPA” 依賴,Spring Boot 會自動配置一個 DataSource 和 JPA 實體管理器。
你可以通過 @SpringBootApplication 注解啟用自動配置,該注解包含了 @EnableAutoConfiguration 注解。
如果你想禁用某些自動配置,可以使用 @SpringBootApplication 的 exclude 屬性:

java
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class DemoApplication {// ...
}

4.2 Starter 依賴

Spring Boot 的 Starter 依賴是一組方便的依賴描述符,你可以將它們添加到項目中。你只需要添加所需的 Starter,Spring Boot 會自動處理所有相關依賴。
常見的 Starter 依賴包括:

  • spring-boot-starter-web: 構建 Web 應用,包括 RESTful 服務
  • spring-boot-starter-data-jpa: 使用 JPA 進行數據庫訪問
  • spring-boot-starter-security: 添加 Spring Security 安全功能
  • spring-boot-starter-test: 用于測試 Spring Boot 應用
  • spring-boot-starter-thymeleaf: 使用 Thymeleaf 模板引擎

4.3 嵌入式服務器

Spring Boot 支持嵌入式服務器,這意味著你不需要部署 WAR 文件到外部服務器,而是可以將應用打包成一個可執行的 JAR 文件,其中包含嵌入式服務器。
默認情況下,Spring Boot 使用 Tomcat 作為嵌入式服務器。你可以通過添加相應的依賴來切換到 Jetty 或 Undertow:

xml
<!-- 使用 Jetty 替代 Tomcat -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId></exclusion></exclusions>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

4.4 配置屬性
Spring Boot 提供了多種方式來配置應用屬性:

  1. application.properties 文件:位于 src/main/resources 目錄下
  2. application.yml 文件:與 application.properties 類似,但使用 YAML 格式
  3. 命令行參數
  4. 環境變量
  5. 自定義配置類

示例 application.properties 文件:

properties
server.port=8081
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=secret

你可以通過 @Value 注解或 @ConfigurationProperties 注解來注入配置屬性:

java
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component
public class MyConfig {@Value("${server.port}")private int port;// getter 和 setter
}

5. 數據訪問

Spring Boot 提供了多種數據訪問方式,包括 JDBC、JPA 和 NoSQL 等。

5.1 使用 Spring Data JPA

Spring Data JPA 是訪問關系型數據庫的推薦方式。它簡化了 JPA 的使用,提供了豐富的 Repository 接口。
以下是使用 Spring Data JPA 的基本步驟:

添加依賴:

xml
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><scope>runtime</scope>
</dependency>

定義實體類:

java
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String email;// 構造方法、getter 和 setter
}

創建 Repository 接口:

java
import org.springframework.data.jpa.repository.JpaRepository;public interface UserRepository extends JpaRepository<User, Long> {// 可以添加自定義查詢方法User findByName(String name);
}
使用 Repository:
java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;@Component
public class DataLoader implements CommandLineRunner {
private final UserRepository userRepository;@Autowired
public DataLoader(UserRepository userRepository) {this.userRepository = userRepository;
}@Override
public void run(String... args) throws Exception {userRepository.save(new User("John Doe", "john@example.com"));userRepository.save(new User("Jane Doe", "jane@example.com"));
}
}

5.2 使用 JDBC Template

如果你更喜歡使用 JDBC,可以使用 Spring 的 JdbcTemplate:

java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;@Repository
public class UserJdbcRepository {
private final JdbcTemplate jdbcTemplate;@Autowired
public UserJdbcRepository(JdbcTemplate jdbcTemplate) {this.jdbcTemplate = jdbcTemplate;
}public User findById(Long id) {return jdbcTemplate.queryForObject("SELECT * FROM users WHERE id = ?",(rs, rowNum) -> new User(rs.getLong("id"),rs.getString("name"),rs.getString("email")),id);
}

}

6. Web 開發

Spring Boot 提供了強大的 Web 開發支持,包括 RESTful 服務和 Web 應用開發。

6.1 RESTful 服務

以下是一個簡單的 RESTful 控制器示例:

java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.util.List;@RestController
@RequestMapping("/api/users")
public class UserController {
private final UserRepository userRepository;@Autowired
public UserController(UserRepository userRepository) {this.userRepository = userRepository;
}@GetMapping
public List<User> findAll() {return userRepository.findAll();
}@GetMapping("/{id}")
public User findById(@PathVariable Long id) {return userRepository.findById(id).orElseThrow(() -> new RuntimeException("User not found"));
}@PostMapping
public User save(@RequestBody User user) {return userRepository.save(user);
}@DeleteMapping("/{id}")
public void delete(@PathVariable Long id) {userRepository.deleteById(id);
}

}

6.2 視圖模板

Spring Boot 支持多種視圖模板引擎,如 Thymeleaf、Freemarker 和 JSP 等。
以下是使用 Thymeleaf 的示例:
添加依賴:

xml
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId>
創建控制器:
java
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;@Controller
public class HomeController {
@GetMapping("/")
public String home(Model model) {model.addAttribute("message", "Welcome to Spring Boot!");return "home";
}
}

創建 Thymeleaf 模板文件 src/main/resources/templates/home.html:
html
預覽

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head><title>Home Page</title>
</head>
<body><h1 th:text="${message}">Default Message</h1>
</body>
</html>

7. 安全 Spring Boot 集成了 Spring Security 提供強大的安全功能

7.1 添加安全依賴

xml
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId>
</dependency>

添加此依賴后,Spring Boot 會自動配置基本的安全策略,所有 HTTP 端點都會被保護,需要進行身份驗證才能訪問。

7.2 自定義安全配置

你可以通過創建一個配置類來自定義安全配置:

java
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {http.authorizeRequests().antMatchers("/public/**").permitAll().anyRequest().authenticated().and().formLogin().loginPage("/login").permitAll().and().logout().permitAll();return http.build();
}@Bean
public PasswordEncoder passwordEncoder() {return new BCryptPasswordEncoder();
}
}

這個配置類做了以下事情:
允許訪問 /public/** 路徑下的資源
要求所有其他請求進行身份驗證
自定義登錄頁面
配置密碼編碼器

8. 測試

Spring Boot 提供了豐富的測試支持,包括集成測試和單元測試。

8.1 添加測試依賴

xml
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope>
</dependency>

8.2 單元測試示例

java
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;@SpringBootTest
public class UserServiceTest {
@Autowired
private UserService userService;@MockBean
private UserRepository userRepository;@Test
public void testFindByName() {User user = new User("John Doe", "john@example.com");when(userRepository.findByName("John Doe")).thenReturn(user);User result = userService.findByName("John Doe");assertEquals("John Doe", result.getName());
}
}

8.3 Web 集成測試示例

java
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.web.servlet.MockMvc;@WebMvcTest(UserController.class)
public class UserControllerTest {
@Autowired
private MockMvc mockMvc;@Test
public void testFindAll() throws Exception {mockMvc.perform(get("/api/users")).andExpect(status().isOk()).andExpect(content().contentType("application/json"));
}
}

9. 部署

Spring Boot 應用可以以多種方式部署:

9.1 作為可執行 JAR 部署

這是最常見的部署方式。將應用打包成一個可執行的 JAR 文件,包含所有依賴和嵌入式服務器:

bash
mvn clean package
java -jar target/myapp-0.0.1-SNAPSHOT.jar

9.2 部署到外部服務器

如果你想部署到外部服務器,需要將項目打包成 WAR 文件:
修改 pom.xml 或 build.gradle,將打包方式改為 WAR
排除嵌入式 Tomcat 依賴
添加 Servlet API 依賴
創建一個 ServletInitializer 類
示例 ServletInitializer 類:

java
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {return application.sources(DemoApplication.class);
}
}

9.3 Docker 容器部署

將 Spring Boot 應用打包到 Docker 容器中是一種流行的部署方式:
創建 Dockerfile:
dockerfile
FROM openjdk:17-jdk-slim
COPY target/myapp-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT [“java”,“-jar”,“/app.jar”]
構建 Docker 鏡像:
bash
docker build -t myapp .
運行 Docker 容器:
bash
docker run -p 8080:8080 myapp

10. 生產就緒特性

Spring Boot 提供了許多生產就緒特性,幫助你監控和管理應用:

10.1 Actuator

Spring Boot Actuator 提供了生產就緒端點,幫助你監控和管理應用:
添加依賴:

xml
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

常用端點:
/actuator/health:應用健康狀態
/actuator/info:應用信息
/actuator/metrics:應用指標
/actuator/loggers:日志配置
/actuator/env:環境變量

10.2 自定義健康檢查

你可以通過實現 HealthIndicator 接口來添加自定義健康檢查:

java
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;@Component
public class MyHealthIndicator implements HealthIndicator {
@Override
public Health health() {// 執行健康檢查boolean isHealthy = checkSystem();if (isHealthy) {return Health.up().build();} else {return Health.down().withDetail("Error", "System is not healthy").build();}
}private boolean checkSystem() {// 實現健康檢查邏輯return true;
}
}

11. 總結

Spring Boot 是一個強大的框架,它大大簡化了 Spring 應用的開發過程。通過自動配置、Starter 依賴和嵌入式服務器等特性,開發者可以更快速地構建和部署生產級別的應用。
本文介紹了 Spring Boot 的基本概念、核心特性、數據訪問、Web 開發、安全、測試、部署以及生產就緒特性等方面的內容。希望這些信息對你學習和使用 Spring Boot 有所幫助。

12. 參考資料

Spring Boot 官方文檔
Spring 官方網站
Spring Boot 實戰
Spring Boot 教程

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/79171.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/79171.shtml
英文地址,請注明出處:http://en.pswp.cn/web/79171.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

機器學習第二講:對比傳統編程:解決復雜規則場景

機器學習第二講&#xff1a;對比傳統編程&#xff1a;解決復雜規則場景 資料取自《零基礎學機器學習》。 查看總目錄&#xff1a;學習大綱 關于DeepSeek本地部署指南可以看下我之前寫的文章&#xff1a;DeepSeek R1本地與線上滿血版部署&#xff1a;超詳細手把手指南 一、場景…

Jackson Databind

Jackson Databind 是 Java 生態中處理 JSON 數據的核心庫之一&#xff0c;主要用于實現 Java 對象與 JSON 數據之間的序列化與反序列化。它是 Jackson 庫家族的一部分&#xff0c;通常與 jackson-core 和 jackson-annotations 一起使用&#xff0c;共同完成 JSON 處理任務。 核…

MySQL 中的事務隔離級別有哪些?

MySQL 支持四種標準的事務隔離級別&#xff0c;從低到高依次為&#xff1a;讀未提交&#xff08;READ UNCOMMITTED&#xff09;、讀已提交&#xff08;READ COMMITTED&#xff09;、可重復讀&#xff08;REPEATABLE READ&#xff09; 和 串行化&#xff08;SERIALIZABLE&#x…

RAG優化知識庫檢索(1):基礎概念與架構

1. 引言 大語言模型(LLM)常常面臨著知識時效性、幻覺生成、定制化難等挑戰,檢索增強生成(Retrieval-Augmented Generation, RAG)技術作為解決這些問題的有效方案,正在成為AI應用開發的標準架構。 本文將從基礎概念入手,全面介紹RAG技術的核心原理、標準架構與組件,以及評…

安卓工程build.gradle中的Groovy的常見知識點

文章目錄 變量定義函數定義函數調用閉包參數APK輸出配置多channel配置依賴配置關鍵總結常見混淆點groovy高度兼容java 變量定義 def debugCdnUrl "\"http://xxx\"" //變量賦值函數定義 def getTime() { // 函數定義&#xff08;def 是 Groovy 中定義變…

阿里云 SLS 多云日志接入最佳實踐:鏈路、成本與高可用性優化

作者&#xff1a;裘文成&#xff08;翊韜&#xff09; 摘要 隨著企業全球化業務的擴展&#xff0c;如何高效、經濟且可靠地將分布在海外各地的應用與基礎設施日志統一采集至阿里云日志服務 (SLS) 進行分析與監控&#xff0c;已成為關鍵挑戰。 本文聚焦于阿里云高性能日志采集…

deep seek簡介和解析

deepseek大合集&#xff0c;百度鏈接:https://pan.baidu.com/s/10EqPTg0dTat1UT6I-OlFtg?pwdw896 提取碼:w896 一篇文章帶你全面了解deep seek 目錄 一、deep seek是什么 DeepSeek-R1開源推理模型&#xff0c;具有以下特點&#xff1a; 技術優勢&#xff1a; 市場定位&…

在ISOLAR A/B 工具使用UDS 0x14服務清除單個DTC故障的配置

在ISOLAR A/B 工具使用UDS 0x14服務清除單個DTC故障的配置如下圖所示 將DemClearDTCLimitation參數改成DEM_ALL_SUPPORTED_DTCS 此時0x14 服務就可以支持單個DTC的故障清除&#xff0c; 如果配置成 DEM_ONLY_CLEAR_ALL_DTCS 則只能夠用0x14服務清楚所有DTC。

Redis面試 實戰貼 后面持續更新鏈接

redis是使用C語言寫的。 面試問題列表&#xff1a; Redis支持哪些數據類型&#xff1f;各適用于什么場景&#xff1f; Redis為什么采用單線程模型&#xff1f;優勢與瓶頸是什么&#xff1f; RDB和AOF持久化的區別&#xff1f;如何選擇&#xff1f;混合持久化如何實現&#x…

Selenium自動化測試工具常見函數

目錄 前言 一、什么是自動化&#xff1f; 二、元素的定位 三、測試對象的操作 3.1輸入文本send_keys() 3.2按鈕點擊click() 3.3清除文本clear() 3.4獲取文本信息text 3.5獲取頁面的title與URL 四、窗口 4.1窗口的切換switch_to.window() 4.2窗口大小設置 …

seata 1.5.2 升級到2.1.0版本

一、部署1.5.2 1、解壓縮 tar -xvf apache-seata-***-incubating-bin.tar.gz 2、修改conf下的application.yml 只需要修改seata下的此配置&#xff0c;然后再nacos中添加其它配置&#xff0c;下面是application.yml的配置&#xff1a; server:port: 7091spring:applic…

Vue知識框架

一、Vue 基礎核心 1. 響應式原理 數據驅動&#xff1a;通過 data 定義響應式數據&#xff0c;視圖自動同步數據變化。 2、核心機制 Object.defineProperty&#xff08;Vue 2.x&#xff09;或 Proxy&#xff08;Vue 3.x&#xff09;實現數據劫持。依賴收集&#xff1a;追蹤…

Nginx靜態資源增加權限驗證

Nginx靜態資源增加權限驗證 一、前言二、解決思路2.1、方式一2.2、方式二三、代碼3.1、方式一3.1.1、前端代碼3.1.2、后端代碼3.1.3、Nginx調整3.1.4、注意事項3.2.方式二四、參考資料一、前言 在項目開發的過程中,項目初期,及大部分小型項目都是使用共享磁盤進行靜態文件的…

分析NVIDIA的股價和業績暴漲的原因

NVIDIA自2016年以來股價與業績的持續高增長&#xff0c;是多重因素共同作用的結果。作為芯片行業的領軍企業&#xff0c;NVIDIA抓住了技術、戰略、市場與行業趨勢的機遇。以下從技術創新、戰略布局、市場需求、財務表現及外部環境等維度&#xff0c;深入分析其成功原因&#xf…

更換芯片后因匝數比變化,在長距離傳輸時出現通訊問題。我將從匝數比對信號傳輸的影響、阻抗匹配等方面分析可能原因,并給出相應解決方案。

匝數比影響信號幅度與相位&#xff1a;原 HM1188 芯片匝數比 1:1&#xff0c;信號在變壓器原副邊傳輸時幅度基本不變&#xff1b;更換為 XT1188 芯片&#xff08;匝數比 1:2&#xff09;后&#xff0c;根據變壓器原理&#xff0c;副邊輸出信號幅度會變為原邊的 2 倍。短距離 10…

Python引領前后端創新變革,重塑數字世界架構

引言:Python 在前后端開發的嶄新時代 在當今數字化時代,軟件開發領域持續創新,而 Python 作為一門功能強大、應用廣泛的編程語言,正引領著前后端開發的變革浪潮。Python 以其簡潔易讀的語法、豐富的庫和框架生態系統,以及強大的跨領域適用性,在計算機領域占據了舉足輕重…

IP SSL證書常見問題助您快速實現HTTPS加密

一、什么是IP SSL證書&#xff1f; IP SSL證書是一種專門用于保護基于IP地址的網站或服務器的SSL證書。與傳統的域名SSL證書不同&#xff0c;它不需要綁定域名&#xff0c;而是直接與公網IP地址關聯。當用戶訪問該IP地址時&#xff0c;瀏覽器與服務器之間會建立加密連接&#…

「Mac暢玩AIGC與多模態27」開發篇23 - 多任務摘要合成與提醒工作流示例

一、概述 本篇基于興趣建議輸出的方式&#xff0c;擴展為支持多任務輸入場景&#xff0c;介紹如何使用 LLM 對用戶輸入的多項待辦事項進行摘要整合、生成重點提醒&#xff0c;并保持自然語言風格輸出&#xff0c;適用于任務總結、進度引導、日程提醒等輕量型任務生成場景。 二…

前端自學入門:HTML 基礎詳解與學習路線指引

在互聯網的浪潮中&#xff0c;前端開發如同構建數字世界的基石&#xff0c;而 HTML 則是前端開發的 “入場券”。對于許多渴望踏入前端領域的初學者而言&#xff0c;HTML 入門是首要挑戰。本指南將以清晰易懂的方式&#xff0c;帶大家深入了解 HTML 基礎&#xff0c;并梳理前端…

js 兩個數組中的指定參數(id)相同,為某個對象設置disabled屬性

在JavaScript中&#xff0c;如果想要比較兩個數組并根據它們的id屬性來設置某個對象的disabled屬性為true&#xff0c;你可以使用幾種不同的方法。這里我將介紹幾種常用的方法&#xff1a; 方法1&#xff1a;使用循環和條件判斷 const array1 [{ id: 1, name: Item 1 },{ id…