SpringAI 1.0.0發布:打造企業級智能聊天應用

官方文檔

gitee的demo

1、前言

2025年5月,SpringAI 1.0.0終于正式發布。這不僅是另一個普通的庫,更是將Java和Spring推向AI革命前沿的戰略性舉措。給Java生態帶來了強大且全面的AI工程解決方案。眾多企業級應用在SpringBoot上運行關鍵業務,而SpringAI 1.0.0的發布,將賦予開發者將應用程序與前沿AI模型無縫連接的能力!

官方文檔中已提供了眾多能力的說明,旨在簡化大模型的應用程序的開發。

另外,開源大模型的選擇(如deepseekR1(0528版)),不同蒸餾模型的選擇,可參考github上的開源大模型排行榜

2、運行環境

SpringAI基于spingboot3.x版本,需要JDK17以上。

    <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.4.5</version><relativePath/> <!-- lookup parent from repository --></parent><dependencyManagement><dependencies><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-bom</artifactId><version>1.0.0</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>

3、Api-Key申請

SpringAI提供多種AI提供商的便攜式Model,包括各類多模態:圖像識別、語音識別、視頻識別,以及最基本的LLM文本對話,例如:Claude、OpenAI、DeepSeek、ZhiPu等。

本文使用智譜AI的大模型演示,新用戶可獲得有期限的免費次數

也可以使用本地安裝大模型:https://ollama.com/。通過ollama,就不再需要環境(大模型很多都是依賴Python環境)

4、完整pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.4.5</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>spring-ai-demo</artifactId><version>0.0.1-SNAPSHOT</version><name>spring-ai-demo</name><description>Demo project for Spring Boot</description><properties><java.version>17</java.version><fastjson.version>2.0.53</fastjson.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- 智譜 --><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-model-zhipuai</artifactId></dependency><!-- deepseek --><!--<dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-model-deepseek</artifactId></dependency>--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>com.alibaba.fastjson2</groupId><artifactId>fastjson2</artifactId><version>${fastjson.version}</version></dependency><!--mcp server--><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-mcp-server</artifactId></dependency><!--即支持sse,也支持stdio--><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-mcp-client-webflux</artifactId></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-bom</artifactId><version>1.0.0</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>16</source><target>16</target></configuration></plugin></plugins></build></project>

阿里的大模型pom=sping-ai-alibaba-starter-dashscope

5、application.properties文件

server:servlet:context-path: /aispring:application:name: spring-ai-demoai:chat:client:# 禁用默認chat clientenabled: falsezhipuai:# 從環境變量取api-key: ${API_KEY_ZHIPUAI}chat:options:model: glm-4-plustemperature: 0.7data:redis:host: localhostport: 6379password: 123123!lettuce:pool:min-idle: 0max-idle: 8max-active: 8max-wait: -1ms

6、特性與Demo

6.1、最簡單的對話

配置ChatClient

    /*** 默認client*/@Beanpublic ChatClient zhiPuAiChatClient(ZhiPuAiChatModel chatModel) {return ChatClient.create(chatModel);}

定義接口


/*** 最簡單的chat** @author stone* @date 2025/6/26 16:11*/
@RestController
@RequestMapping("/case1")
@Slf4j
public class Case1Controller {@Resource@Qualifier("zhiPuAiChatClient")private ChatClient chatClient;/*** 直接獲取結果*/@GetMapping("/chat")public String chat(@RequestParam("input") String input) {// input=講個笑話return this.chatClient.prompt().user(input).call().content();}/*** 轉化實體*/@GetMapping("/entity")public List<ActFilm> entity(@RequestParam("input") String input) {// input=生成劉德華和劉亦菲的10部電影return this.chatClient.prompt().user(input).call().entity(new ParameterizedTypeReference<List<ActFilm>>() {});}/*** 流式響應*/@GetMapping(value = "/flux", produces = MediaType.TEXT_EVENT_STREAM_VALUE)public Flux<String> flux(@RequestParam("input") String input) {// input=講個笑話return this.chatClient.prompt().user(input).stream().content();}/*** 動態輸入*/@GetMapping(value = "/fluxDynamic", produces = MediaType.TEXT_EVENT_STREAM_VALUE)public Flux<String> fluxDynamic(@RequestParam("input") String input, @RequestParam("name") String name) {return this.chatClient.prompt().user(promptUserSpec -> promptUserSpec.text("告訴我中國有多少叫{name}的人").param("name", name)).stream().content();}}

.user,也就是用戶提示詞

.call,同步方式響應,也就是一整個結果返回

.stream,流式響應,調整為sse方式(text/event-stream)

6.2、默認系統文本

預定義chatClient,設置系統提示詞

    /*** 參數-占位符的默認系統文本*/@Beanpublic ChatClient paramTextChatClient(ZhiPuAiChatModel chatModel) {return ChatClient.builder(chatModel).defaultSystem("你是一個智能聊天機器人,用 {role} 的角度回答問題").build();}/*** 默認系統文本*/@Beanpublic ChatClient defaultTextChatClient(ZhiPuAiChatModel chatModel) {return ChatClient.builder(chatModel).defaultSystem("你是一個智能聊天機器人,用邪惡女巫的角度回答問題").build();}

定義接口


/*** 默認系統文本** @author stone* @date 2025/6/30 15:11*/
@RestController
@RequestMapping("/case2")
@Slf4j
public class Case2Controller {@Resource@Qualifier("defaultTextChatClient")private ChatClient defaultTextChatClient;/*** 默認系統文本*/@GetMapping(value = "/flux", produces = MediaType.TEXT_EVENT_STREAM_VALUE)public Flux<String> flux(@RequestParam("input") String input) {// input=講個笑話return this.defaultTextChatClient.prompt().user(input).stream().content();}@Resource@Qualifier("paramTextChatClient")private ChatClient paramTextChatClient;/*** 動態系統文本*/@GetMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)public Flux<String> chat(@RequestParam("input") String input, @RequestParam("role") String role) {// input=聊一聊圓明園的故事吧,500字以內// role=數學老師/邪惡女巫return this.paramTextChatClient.prompt().system(promptSystemSpec -> promptSystemSpec.param("role", role)).user(input).stream().content();}}

消息類型

提示詞的不同部分,在交互中扮演著獨特和定義明確的角色。


6.3、advisors

提供了強大靈活的攔截式AI交互驅動(配置多個advisor時,前一個做出的更改會傳遞給下一個)


/*** @author stone* @date 2025/6/30 15:41*/
@RestController
@RequestMapping("/case3")
@Slf4j
public class Case3Controller {@Resource@Qualifier("paramTextChatClient")private ChatClient chatClient;/*** 最簡單的advisor=日志* <p>* org.springframework.ai.chat.client.advisor=debug*/@GetMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)public Flux<String> chat(@RequestParam("input") String input, @RequestParam("role") String role) {// input=聊一聊圓明園的故事吧,500字以內// role=邪惡女巫return this.chatClient.prompt().system(promptSystemSpec -> promptSystemSpec.param("role", role)).advisors(new SimpleLoggerAdvisor()).user(input).stream().content();}/*** 自定義打印內容*/@GetMapping(value = "/chat2",produces = MediaType.TEXT_EVENT_STREAM_VALUE)public Flux<String> chat2(@RequestParam("input") String input, @RequestParam("role") String role) {// input=聊一聊圓明園的故事吧,500字以內// role=邪惡女巫return this.chatClient.prompt().system(promptSystemSpec -> promptSystemSpec.param("role", role)).advisors(SimpleLoggerAdvisor.builder().requestToString(req -> "請求參數:" + req.prompt().getUserMessage().getText()).responseToString(resp -> "響應參數:" + resp.getResult().getOutput().getText()).build()).user(input).stream().content();}/*** 定義子類,自定義打印的*/@GetMapping(value = "/chat3",produces = MediaType.TEXT_EVENT_STREAM_VALUE)public Flux<String> chat3(@RequestParam("input") String input, @RequestParam("role") String role) {// input=聊一聊圓明園的故事吧,500字以內// role=邪惡女巫return this.chatClient.prompt().system(promptSystemSpec -> promptSystemSpec.param("role", role)).advisors(new SimpleLogAdvisor()).user(input).stream().content();}/*** 自定義日志打印*/public static class SimpleLogAdvisor extends SimpleLoggerAdvisor {public ChatClientResponse adviseCall(ChatClientRequest chatClientRequest, CallAdvisorChain callAdvisorChain) {log.info("自定義日志,請求參數:{}", chatClientRequest.prompt().getUserMessage().getText());ChatClientResponse chatClientResponse = super.adviseCall(chatClientRequest, callAdvisorChain);log.info("自定義日志,響應結果:{}", chatClientResponse.chatResponse().getResult().getOutput().getText());return chatClientResponse;}public Flux<ChatClientResponse> adviseStream(ChatClientRequest chatClientRequest, StreamAdvisorChain streamAdvisorChain) {log.info("自定義日志,請求參數:{}", chatClientRequest.prompt().getUserMessage().getText());Flux<ChatClientResponse> chatClientResponses = streamAdvisorChain.nextStream(chatClientRequest);return (new ChatClientMessageAggregator()).aggregateChatClientResponse(chatClientResponses, this::logResponse);}private void logResponse(ChatClientResponse chatClientResponse) {log.info("自定義日志,響應結果:{}", chatClientResponse.chatResponse().getResult().getOutput().getText());}}
}


6.4、對話記憶功能

通過多輪對話,實現聊天內存功能,通過實現交互信息的持久化存儲與動態檢索機制

    public Case4Controller(ZhiPuAiChatModel chatModel,ChatMemory chatMemory) {this.chatClient = ChatClient.builder(chatModel).defaultAdvisors(PromptChatMemoryAdvisor.builder(chatMemory).build()).build();}private ChatClient chatClient;

基于JVM內存;設置唯一信息,通過常量區分不同的用戶對話

    /*** 對話記憶功能-基于內存* <p>* MessageWindowChatMemory:默認最大20* InMemoryChatMemoryRepository:使用map*/
//    @GetMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)@GetMapping(value = "/chat")public Flux<String> chat(@RequestParam("input") String input) {// input=我叫什么return this.chatClient.prompt().user(input).stream().content();}/*** 對話記憶功能-區分不同用戶*/@GetMapping(value = "/chat2")public Flux<String> chat2(@RequestParam("input") String input,@RequestParam("userId") String userId) {return this.chatClient.prompt().user(input).advisors(a -> a.param(ChatMemory.CONVERSATION_ID, userId)).stream().content();}

基于Redis的多輪對話記憶功能

/*** @author stone* @date 2025/7/14 10:20*/
@Data
public class ChatBO implements Serializable {/*** 用戶對話唯一標識*/private String chatId;/*** 對話類型*/private String type;/*** 對話內容*/private String text;
}/*** @author stone* @date 2025/7/14 10:19*/
@Slf4j
@Component
public class ChatRedisMemory implements ChatMemory {private static final String KEY_PREFIX = "chat:history:";private final RedisTemplate<String, Object> redisTemplate;public ChatRedisMemory(RedisTemplate<String, Object> redisTemplate) {this.redisTemplate = redisTemplate;}@Overridepublic void add(String conversationId, List<Message> messages) {String key = KEY_PREFIX + conversationId;List<String> list = new ArrayList<>();for (Message msg : messages) {String[] strs = msg.getText().split("</think>");String text = strs.length == 2 ? strs[1] : strs[0];// 轉化ChatBO bo = new ChatBO();bo.setChatId(conversationId);bo.setType(msg.getMessageType().getValue());bo.setText(text);list.add(JSON.toJSONString(bo));}redisTemplate.opsForList().rightPushAll(key, list.toArray());redisTemplate.expire(key, 30, TimeUnit.MINUTES);}@Overridepublic List<Message> get(String conversationId) {String key = KEY_PREFIX + conversationId;Long size = redisTemplate.opsForList().size(key);if (size == null || size == 0) {return Collections.emptyList();}List<Object> listTmp = redisTemplate.opsForList().range(key, 0, -1);List<Message> result = new ArrayList<>();for (Object obj : listTmp) {ChatBO chat = JSON.parseObject(obj.toString(), ChatBO.class);if (MessageType.USER.getValue().equals(chat.getType())) {result.add(new UserMessage(chat.getText()));} else if (MessageType.ASSISTANT.getValue().equals(chat.getType())) {result.add(new AssistantMessage(chat.getText()));} else if (MessageType.SYSTEM.getValue().equals(chat.getType())) {result.add(new SystemMessage(chat.getText()));}}return result;}@Overridepublic void clear(String conversationId) {redisTemplate.delete(KEY_PREFIX + conversationId);}
}
    /*** 基于redis的對話記憶*/@Beanpublic ChatMemory chatMemory(RedisTemplate<String, Object> redisTemplate) {return new ChatRedisMemory(redisTemplate);}
    public Case4Controller(ZhiPuAiChatModel chatModel,ChatMemory chatMemory) {this.chatClient = ChatClient.builder(chatModel).defaultAdvisors(PromptChatMemoryAdvisor.builder(chatMemory).build()).build();}/*** 對話記憶功能-基于redis*/@GetMapping(value = "/chat3")public Flux<String> chat3(@RequestParam("input") String input,@RequestParam("userId") String userId) {return this.chatClient.prompt().user(input).advisors(a -> a.param(ChatMemory.CONVERSATION_ID, userId)).stream().content();}

多層記憶機構,模仿人類,做到近期(清晰),中期(模糊),長期(關鍵點)。這里就引入了向量數據庫和RAG。


6.5、@Tools使用

聲明式Function Calling,將方法轉化為工具。提前告訴大模型,提供了什么tools。太多的tools,可以放到向量數據庫。

第三方提供的tools,比如百度天氣、高德位置,不可能各對接系統去做解析。因此MCP(model content protol)協議,通過JSON-rpc2.0方式(json數據格式),統一格式解析。

/*** tools工具** @author stone* @date 2025/7/4 10:42*/
@Component
@Slf4j
public class OrderTools {/*** 比如在退訂、取消訂單*/@Tool(description = "退訂、取消訂單")public String cancelOrder(@ToolParam(description = "訂單號") String orderNum,@ToolParam(description = "賬號") String userAccount) {log.info("訂單號:{},用戶賬號:{}", orderNum, userAccount);// 執行業務邏輯log.info("處理數據庫...");return "操作成功";}
}

/*** @author stone* @date 2025/7/4 10:40*/
@RestController
@RequestMapping("/case5")
@Slf4j
public class Case5Controller {public Case5Controller(ZhiPuAiChatModel chatModel,ChatMemory chatMemory,OrderTools orderTools) {this.chatClient = ChatClient.builder(chatModel).defaultAdvisors(PromptChatMemoryAdvisor.builder(chatMemory).build()).defaultTools(orderTools).build();}private ChatClient chatClient;/*** tools使用*/@GetMapping("/chat")public String chat(@RequestParam("input") String input) {// input=我要退訂// input=賬號是101,訂單號是XXX1111return this.chatClient.prompt()// 直接方法使用
//                .tools().user(input).call().content();}
}


6.6、調用外部MCP-server

TODO...


6.7、向量數據庫與RAG(檢索增強生成)

TODO...

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

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

相關文章

全球各界關注與討論鴿姆智庫的多維視角分析?

【摘要】全球各界對鴿姆智庫的關注與討論主要集中在以下多維視角&#xff1a; 一、技術創新維度 ?通用思維框架&#xff08;GTF&#xff09;與中文智慧編程系統&#xff08;CWPS&#xff09;? GTF通過模擬人類格式塔認知&#xff0c;實現模式補全與圖形-背景分離功能&#xf…

1??4?? OOP:類、封裝、繼承、多態

文章目錄一、類與實例&#xff1a;從抽象到具體1?? 類&#xff08;Class&#xff09;&#xff1a;抽象的模板2?? 實例&#xff08;Instance&#xff09;&#xff1a;具體的對象3?? __init__ 方法&#xff1a;初始化實例屬性二、封裝&#xff1a;數據與邏輯的“打包”1??…

靜態鏈接 qt 失敗

配置靜態構建 qt 如下所示&#xff0c;執行配置的時候添加 -static 選項即可。 $skiped_modules ("qttools""qtdoc""qttranslations""qtlanguageserver""qtdeclarative""qtquicktimeline""qtquick3d"…

Qt 多線程界面更新策略

在Qt開發中&#xff0c;界面&#xff08;UI&#xff09;更新是高頻操作——無論是后臺任務的進度展示、傳感器數據的實時刷新&#xff0c;還是網絡消息的即時顯示&#xff0c;都需要動態更新界面元素。但Qt對UI操作有一個核心限制&#xff1a;所有UI組件的創建和更新必須在主線…

1.09---區塊鏈節點到底做了什么?從全節點到輕客戶端

鯤志博主出品 Web2 開發者的 Web3 修煉之路 ??【好看的靈魂千篇一律,有趣的鯤志一百六七!】- 歡迎認識我~~ 作者:鯤志說 (公眾號、B站同名,視頻號:鯤志說996) 科技博主:極星會 星輝大使 全棧研發:java、go、python、ts,前電商、現web3 主理人:COC杭州開發者…

Linux線程概念與控制(下)

目錄 前言 2.線程控制 1.驗證理論 2.引入pthread線程庫 3.linux線程控制的接口 3.線程id及進程地址空間布局 4.線程棧 前言 本篇是緊接著上一篇的內容&#xff0c;在有了相關線程概念的基礎之上&#xff0c;我們將要學習線程控制相關話題&#xff01;&#xff01; 2.線程…

力扣面試150題--只出現一次的數字

Day 91 題目描述## 思路 交換律&#xff1a;a ^ b ^ c <> a ^ c ^ b 任何數于0異或為任何數 0 ^ n > n 相同的數異或為0: n ^ n > 0 根據以上 很容易想到做法&#xff0c;將數組中所有的數異或起來&#xff0c;得到的就是只出現一次的數 class Solution {public in…

【運維基礎】Linux 進程調度管理

Linux 進程調度管理 進程調度器 現代計算機系統中既包含只有單個CPU且任何時候都只能處理單個指令的低端系統到具有幾百個cpu、每個cpu有多個核心的高性能超級計算機&#xff0c;可以并行執行幾百個指令。所有這些系統都有一個共同點&#xff1a;系統進程線程數量超出了CPU數量…

深度學習篇---層與層之間搭配

在深度學習中&#xff0c;各種層&#xff08;比如卷積層、激活函數、池化層等&#xff09;的搭配不是隨意的&#xff0c;而是像 “搭積木” 一樣有規律 —— 每一層的作用互補&#xff0c;組合起來能高效提取特征、穩定訓練&#xff0c;最終提升模型性能。下面用通俗易懂的方式…

服務器多線主要是指什么?

在數字化的網絡環境當中&#xff0c;服務器已經成為各個企業提升線上業務發展的重要網絡設備&#xff0c;其中服務器多線則是指一臺服務器中能夠同時接入多個網絡運營商&#xff0c;并且通過智能路由技術實現用戶訪問請求的自動化分配&#xff0c;大大提高了用戶訪問數據信息的…

從0到1學PHP(三):PHP 流程控制:掌控程序的走向

目錄一、條件語句&#xff1a;程序的 “抉擇路口”1.1 if 語句家族&#xff1a;基礎與進階1.2 switch 語句&#xff1a;精準匹配的 “導航儀”二、循環語句&#xff1a;程序的 “重復舞步”2.1 for 循環&#xff1a;有序的 “征程”2.2 while 與 do - while 循環&#xff1a;條…

uni-app框架基礎

闡述 MVC 模式1, MVC與MVVMMVC 他是后端的一個開發思想MVVM是基于MVC中的view這層所分離出來的一種設計模式。MVC架構詳解MVC&#xff08;Model-View-Controller&#xff09;是一種廣泛使用的軟件設計模式&#xff0c;主要用于分離應用程序的業務邏輯、用戶界面和輸入控制。這種…

智慧收銀系統開發進銷存庫存統計,便利店、水果店、建材與家居行業的庫存匯總管理—仙盟創夢IDE

在零售與批發行業的數字化轉型中&#xff0c;當前庫存匯總作為進銷存管理的核心環節&#xff0c;直接影響著企業的資金周轉、銷售決策和客戶滿意度。現代收銀系統已超越傳統的收款功能&#xff0c;成為整合多渠道數據、實現實時庫存匯總的中樞神經。本文將深入剖析便利店、水果…

selenium(WEB自動化工具)

定義解釋 Selenium是一個用于Web應用程序測試的工具。Selenium測試直接運行在瀏覽器中&#xff0c;就像真正的用戶在操作一樣。支持的瀏覽器包括IE&#xff08;7, 8, 9, 10, 11&#xff09;&#xff0c;Mozilla Firefox&#xff0c;Safari&#xff0c;Google Chrome&#xff0…

windows本地使用conda部署Open-webui

前提條件 Open-webui使用python3.11.9 步驟 conda操作也可以參考 安裝python torch、transformer、記錄 1、conda環境 # 創建環境 conda create --name openwebui python3.11.9# 激活環境 conda activate openwebui# 升級pip版本 pip install --upgrade pip# pip安裝openwe…

【Unity筆記04】數據持久化

&#x1f31f; 方案核心思想遵循以下設計原則&#xff1a;數據安全第一&#xff1a;絕不使用明文存儲&#xff0c;采用AES加密算法保護數據。性能優化&#xff1a;使用異步I/O操作&#xff0c;避免阻塞主線程導致游戲卡頓。結構清晰&#xff1a;模塊化設計&#xff0c;職責分離…

深入理解 HTML5 Web Workers:提升網頁性能的關鍵技術解析

深入理解 HTML5 Web Workers&#xff1a;提升網頁性能的關鍵技術解析引言1. 什么是 Web Workers&#xff1f;Web Workers 的特點&#xff1a;2. Web Workers 的使用方式2.1 創建一個 Web Worker步驟 1&#xff1a;創建 Worker 文件步驟 2&#xff1a;在主線程中調用 Worker3. W…

會議室預定系統核心技術:如何用一行SQL解決時間沖突檢測難題

文章目錄 一、為什么時間沖突檢測是預定系統的核心挑戰? 二、黃金法則:兩行線段重疊檢測法 三、四大沖突場景實戰解析(同一會議室) 四、生產環境完整解決方案 1. 基礎沖突檢測函數 2. 預定API處理流程 3. 高級邊界處理技巧 五、性能優化關鍵策略 六、不同數據庫的適配方案 …

13.正則表達式:文本處理的瑞士軍刀

正則表達式&#xff1a;文本處理的瑞士軍刀 &#x1f3af; 前言&#xff1a;當文本遇上神奇的密碼 想象一下&#xff0c;你是一個圖書管理員&#xff0c;面對著一堆亂七八糟的書籍信息&#xff1a; “聯系電話&#xff1a;138-1234-5678”“郵箱地址&#xff1a;zhang.sangm…

linux下c語言訪問mysql數據庫

一、連接數據庫基礎1. 頭文件與庫文件連接 MySQL 需包含的頭文件&#xff1a;#include <mysql/mysql.h> // 部分環境也可用 #include <mysql.h> 編譯鏈接時&#xff0c;Linux 平臺需指定庫名&#xff1a;-lmysqlclient &#xff0c;用于鏈接 MySQL 客戶端函數庫。2…