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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈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…