Spring系列六:JdbcTemplate

JdbcTemplate

  • 🦒看一個實際需求
  • 🦒官方文檔
  • 🦒基本介紹
  • 🦒使用實例
    • 📕需求說明
    • 📕代碼演示

🦒看一個實際需求

實際需求: 如果程序員就希望使用spring框架來做項目, spring框架如何處理對數據庫的操作呢?

  1. 方案1: 使用前面做項目開發的JdbcUtils
  2. 方案2: 其實spring提供了一個操作數據庫(表)功能強大的類JdbcTemplate. 我們可以同ioc容器來配置一個jdbcTemplate對象, 使用它來完成對數據庫表的各種操作.

🦒官方文檔

官方文檔: spring-framework-5.3.8\docs\javadoc-api\index.html

在這里插入圖片描述
在這里插入圖片描述

🦒基本介紹

1.通過Spring可以配置數據源, 從而完成對數據表的操作

2.JdbcTemplateSpring提供的訪問數據庫的技術. 可以將JDBC的常用操作封裝為模板方法. [JdbcTemplate類圖]

🦒使用實例

📕需求說明

我們使用spring的方式來完成 JdbcTemplate 配置和使用

📕代碼演示

找到前面我們搭建的spring項目, 在此項目上學習 JdbcTemplate.

1.引入使用JdbcTemplate需要的jar包

2.創建數據庫 spring 和表 monster

1)管理員打開cmd窗口, 開啟數據庫服務. 別忘了, 這很重要 安裝Mysql5.7
在這里插入圖片描述

2)sql代碼

-- 創建數據庫
CREATE DATABASE spring;
USE spring;
-- 創建表
CREATE TABLE monster (id INT UNSIGNED PRIMARY KEY,`name` VARCHAR(64) NOT NULL DEFAULT '',skill VARCHAR(64) NOT NULL DEFAULT ''
)CHARSET=utf8;
INSERT INTO monster VALUES(100, '孫悟空', '金箍棒');
INSERT INTO monster VALUES(200, '紅孩兒', '三昧真火');
INSERT INTO monster VALUES(300, '鐵扇公主', '芭蕉扇');

3.創建配置文件 src/jdbc.properties
JdbcTemplate會使用到DataSource, 而DataSource可以拿到連接去操作數據庫

在這里插入圖片描述

jdbc.user=root
jdbc.pwd=zzw
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/spring

4.創建配置文件 src/JdbcTemplate_ioc.xml

在這里插入圖片描述在這里插入圖片描述

通過屬性文件配置bean, 參考

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"><!--引入外部的jdbc.properties文件--><context:property-placeholder location="classpath:jdbc.properties"/><!--配置數據源對象-DataSource--><bean class="com.mchange.v2.c3p0.ComboPooledDataSource" id="dataSource"><!--給數據源對象配置屬性值--><property name="user" value="${jdbc.user}"/><property name="password" value="${jdbc.pwd}"/><property name="driverClass" value="${jdbc.driver}"/><property name="jdbcUrl" value="${jdbc.url}"/></bean>
</beans>

5.新建測試類com.zzw.spring.test.JdbcTemplateTest

public class JdbcTemplateTest {@Testpublic void testDataSourceByJdbcTemplate() {//獲取容器ApplicationContext ioc =new ClassPathXmlApplicationContext("JdbcTemplate_ioc.xml");//在這里打個斷點System.out.println("ok");}
}

在這里插入圖片描述
在這里插入圖片描述

public class JdbcTemplateTest {@Testpublic void testDataSourceByJdbcTemplate() {//獲取容器ApplicationContext ioc =new ClassPathXmlApplicationContext("JdbcTemplate_ioc.xml");//因為ComboPooledDataSource類實現了DataSource接口, 所以我們可以用接口類型來獲取 comboPooledDataSource對象DataSource dataSource = ioc.getBean(DataSource.class);Connection connection = dataSource.getConnection();//獲取到connection=com.mchange.v2.c3p0.impl.NewProxyConnection@2cd2a21fSystem.out.println("獲取到connection=" + connection);connection.close();System.out.println("ok");}
}

6.配置JdbcTemplate_ioc.xml, 將數據源分配給JdbcTemplate bean

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"><!--引入外部的jdbc.properties文件--><context:property-placeholder location="classpath:jdbc.properties"/><!--配置數據源對象-DataSource--><bean class="com.mchange.v2.c3p0.ComboPooledDataSource" id="dataSource"><!--給數據源對象配置屬性值--><property name="user" value="${jdbc.user}"/><property name="password" value="${jdbc.pwd}"/><property name="driverClass" value="${jdbc.driver}"/><property name="jdbcUrl" value="${jdbc.url}"/></bean><!--配置JdbcTemplate對象--><!--JdbcTemplate會使用到DataSource, 而DataSource可以拿到連接去操作數據庫--><bean class="org.springframework.jdbc.core.JdbcTemplate" id="jdbcTemplate"><!--給JdbcTemplate對象配置dateSource--><property name="dataSource" ref="dataSource"/></bean>
</beans>

7.修改JdbcTemplateTest.java, 通過JdbcTemplate對象完成添加一個新的 monster

public class JdbcTemplateTest {@Testpublic void addDataByJdbcTemplate() {//獲取到容器ApplicationContext ioc =new ClassPathXmlApplicationContext("JdbcTemplate_ioc.xml");//獲取JdbcTemplate對象, 這里我們先 debug一下System.out.println("ok");}
}

在這里插入圖片描述

public class JdbcTemplateTest {@Testpublic void addDataByJdbcTemplate() {//獲取到容器ApplicationContext ioc =new ClassPathXmlApplicationContext("JdbcTemplate_ioc.xml");//獲取JdbcTemplate對象 [按類型獲取]JdbcTemplate jdbcTemplate = ioc.getBean(JdbcTemplate.class);//1.添加方式①//String sql = "insert into monster values(400, '陸小千', '魔幻手機')";//jdbcTemplate.execute(sql);//2.添加方式② ?占位符, 可以防止sql注入String sql = "insert into monster values(?, ?, ?)";//affected表示 執行后表受影響的行數int affected = jdbcTemplate.update(sql, 500, "金角大王", "紫金紅葫蘆");System.out.println("add success afftected=" + affected);}
}

在這里插入圖片描述

8.修改JdbcTemplateTest.java, 通過JdbcTemplate對象完成更新一個 monsterskill

public class JdbcTemplateTest {//測試通過JdbcTemplate對象完成修改數據@Testpublic void updateDataByJdbcTemplate() {//獲取到容器ApplicationContext ioc =new ClassPathXmlApplicationContext("JdbcTemplate_ioc.xml");//獲取JdbcTemplate對象JdbcTemplate jdbcTemplate = ioc.getBean(JdbcTemplate.class);//組織SQLString sql = "update monster set skill = ? where id = ?";//假使修改后的數據和修改前的數據一樣, 也認為是修改成功了一條語句, affected返回 1, 因為它沒有判斷要修改的數據int affected = jdbcTemplate.update(sql, "美人計", 300);System.out.println("update ok affected=" + affected);}
}

9.修改JdbcTemplateTest.java, 通過JdbcTemplate對象完成批量添加兩個 monster 白蛇精和豬八戒

public class JdbcTemplateTest {//測試通過JdbcTemplate對象完成批量添加數據//這里有一個使用API的技巧/*** 說明* 1.對于某些類, 有很多API, 使用的步驟* 2.使用技巧: (1)先確定API名字 (2)根據API提供相應的參數 [組織參數]*           (3)把自己的調用思路清晰 (4)根據API, 可以推測類的用法和功能*/@Testpublic void addBatchDataByJdbcTemplate() {//獲取到容器ApplicationContext ioc =new ClassPathXmlApplicationContext("JdbcTemplate_ioc.xml");//獲取JdbcTemplate對象JdbcTemplate jdbcTemplate = ioc.getBean(JdbcTemplate.class);//1.先確定, 猜測API名稱 update -> batchUpdate [如果出現問題,再重新找]//public int[] batchUpdate(String sql, List<Object[]> batchArgs){}//2.準備參數 [構建實參]String sql = "insert into monster values(?, ?, ?)";List<Object[]> batchArgs = new ArrayList<>();batchArgs.add(new Object[]{600, "鼠鼠", "偷吃糧食"});batchArgs.add(new Object[]{700, "貓貓", "抓老鼠"});//3.調用//說明: 返回結果是一個數組, 每個元素對應上面的sql語句對表的影響記錄數int[] ints = jdbcTemplate.batchUpdate(sql, batchArgs);//輸出for (int anInt : ints) {System.out.println("anInt=" + anInt);}System.out.println("batch add ok~");}
}

10.查詢 id=100monster 并封裝到 Monster 實體對象

1)創建Monster實體類, 跳轉

2)這里有一個知識點: 給字段起別名, 應對應實體類的屬性. 我們在前面的家居購項目中遇到過

在這里插入圖片描述

public class JdbcTemplateTest {/*** 查詢id=100的monster對象封裝到Monter實體對象[在實際開發中非常有用]*/@Testpublic void selectDataByJdbcTemplate() {//獲取到容器ApplicationContext ioc =new ClassPathXmlApplicationContext("JdbcTemplate_ioc.xml");//獲取JdbcTemplate對象JdbcTemplate jdbcTemplate = ioc.getBean(JdbcTemplate.class);//1.確定API query -> queryForObject//public <T> T queryForObject(String sql, RowMapper<T> rowMapper, @Nullable Object... args)//2.準備參數String sql = "SELECT id AS monsterId, `name`, skill FROM monster WHERE id = ?";//使用了RowMapper 接口來對返回的數據, 進行一個封裝 底層使用的反射 -> setter方法//細節: 你查詢的記錄的表的字段需要和 Monster對象的字段名保持一致RowMapper<Monster> rowMapper = new BeanPropertyRowMapper<>();//3.調用Monster monster = jdbcTemplate.queryForObject(sql, rowMapper, 100);//輸出System.out.println("monster=" + monster);System.out.println("query ok~");}
}

3)結果報錯: java.lang.IllegalStateException: Mapped class was not specified

4)修正代碼

RowMapper<Monster> rowMapper = new BeanPropertyRowMapper<>(Monster.class);

5)運行結果
在這里插入圖片描述11.查詢 id>=200monster 并封裝到 Monster 實體對象

在這里插入圖片描述

public class JdbcTemplateTest {/*** 查詢id>=200的monster并封裝到Monster實體對象*/@Testpublic void selectMulDataByJdbcTemplate() {//獲取到容器ApplicationContext ioc =new ClassPathXmlApplicationContext("JdbcTemplate_ioc.xml");//獲取JdbcTemplate對象JdbcTemplate jdbcTemplate = ioc.getBean(JdbcTemplate.class);//1.確定API query//public <T> List<T> query(String sql, RowMapper<T> rowMapper, Object... args)//2.準備參數String sql = "SELECT id AS monsterId, `name`, skill FROM monster WHERE id >= ?";//這個?填進入也可以RowMapper<Monster> rowMapper = new BeanPropertyRowMapper<>(Monster.class);//3.調用List<Monster> monsterList = jdbcTemplate.query(sql, rowMapper, 200);//輸出for (Monster monster : monsterList) {System.out.println("monster=" + monster);}}
}

12.查詢返回結果只有一行一列的值, 比如查詢 id=100 的怪物名
在這里插入圖片描述

public class JdbcTemplateTest {/*** 查詢返回結果只有一行一列的值*/@Testpublic void selectScalarByJdbcTemplate() {//獲取到容器ApplicationContext ioc =new ClassPathXmlApplicationContext("JdbcTemplate_ioc.xml");//獲取JdbcTemplate對象JdbcTemplate jdbcTemplate = ioc.getBean(JdbcTemplate.class);//1.確定API query -> queryForObject//public <T> T queryForObject(String sql, Class<T> requiredType, @Nullable Object... args)//2.準備參數String sql = "SELECT `name` FROM monster WHERE id = ?";//Class<T> requiredType 表示你返回的單行單列的數據類型//3.調用String name = jdbcTemplate.queryForObject(sql, String.class, 100);//輸出System.out.println("name=" + name);System.out.println("ok~");}
}

13.使用 Map 傳入具名參數完成操作, 比如添加 螃蟹精 name 就是具名參數形式, 需要使用 NamedParameterJdbcTemplate

配置JdbcTemplate_ioc.xml, 使用到NamedParameterJdbcTemplate

通過指定構造器配置bean 參考

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"><!--配置NamedParameterJdbcTemplate對象--><bean class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate" id="namedParameterJdbcTemplate"><!--通過構造器, 設置數據源--><constructor-arg name="dataSource" ref="dataSource"/></bean>
</beans>

在這里插入圖片描述

public class JdbcTemplateTest {/*** 使用Map傳入具名參數完成操作, 比如添加*/@Testpublic void testDataByNamedParameterJdbcTemplate() {//獲取到容器ApplicationContext ioc =new ClassPathXmlApplicationContext("JdbcTemplate_ioc.xml");//得到NamedParameterJdbcTemplate beanNamedParameterJdbcTemplate namedParameterJdbcTemplate = ioc.getBean(NamedParameterJdbcTemplate.class);//1.確定API update//public int update(String sql, Map<String, ?> paramMap)//2.準備參數 [:my_id, :name, :skill] 要求按照規定的名字來設置參數String sql = "insert into monster values(:id, :name, :skill)";Map<String, Object> paramMap = new HashMap<>();//給paramMap填寫數據paramMap.put("id", 800);paramMap.put("name", "二郎神");paramMap.put("skill", "哮天犬");//3.調用int affected = namedParameterJdbcTemplate.update(sql, paramMap);//輸出System.out.println("add ok affected=" + affected);}
}

14.使用 sqlparametersource 來封裝具名參數, 還是添加一個 Monster 狐貍精
在這里插入圖片描述
在這里插入圖片描述

public class JdbcTemplateTest {/*** 使用sqlparamtersource 來封裝具名參數, 還是添加一個Monster*/@Testpublic void operDataBySqlparametersource() {//獲取到容器ApplicationContext ioc =new ClassPathXmlApplicationContext("JdbcTemplate_ioc.xml");//得到NamedParameterJdbcTemplate beanNamedParameterJdbcTemplate namedParameterJdbcTemplate = ioc.getBean(NamedParameterJdbcTemplate.class);//1.確定API query//public int update(String sql, SqlParameterSource paramSource)//public BeanPropertySqlParameterSource(Object object)//2.準備參數String sql = "insert into monster values(:id, :name, :skill)";Monster monster = new Monster(900, "妲己", "魅惑");SqlParameterSource sqlParameterSource = new BeanPropertySqlParameterSource(monster);//3.調用int affected = namedParameterJdbcTemplate.update(sql, sqlParameterSource);//輸出System.out.println("add ok affected=" + affected);}
}

結果報錯 No value supplied for the SQL parameter 'id': Invalid property 'id' of bean class [com.zzw.spring.bean.Monster]: Bean property 'id' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

修改代碼

String sql = "insert into monster values(:monterId, :name, :skill)";

15.Dao 對象中使用 Jdbctemplate 完成對數據的操作

1)創建com.zzw.spring.jdbctemplate.dao.MonsterDao.java

@Repository //將MonsterDao注入到spring容器
public class MonsterDao {//注入一個屬性@Resourceprivate JdbcTemplate jdbcTemplate;//完成保存任務public void save(Monster monster) {//組織SQLString sql = "insert into monster values(?, ?, ?)";int affteced =jdbcTemplate.update(sql, monster.getMonsterId(), monster.getName(), monster.getSkill());System.out.println("affected=" + affteced);}
}

2)修改src/JdbcTemplate_ioc.xml, 增加掃描配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"><!--配置要掃描的包--><context:component-scan base-package="com.zzw.spring.jdbctemplate.dao"/><!--引入外部的jdbc.properties文件--><context:property-placeholder location="classpath:jdbc.properties"/><!--配置數據源對象-DataSource--><bean class="com.mchange.v2.c3p0.ComboPooledDataSource" id="dataSource"><!--給數據源對象配置屬性值--><property name="user" value="${jdbc.user}"/><property name="password" value="${jdbc.pwd}"/><property name="driverClass" value="${jdbc.driver}"/><property name="jdbcUrl" value="${jdbc.url}"/></bean><!--配置JdbcTemplate對象--><!--JdbcTemplate會使用到DataSource, 而DataSource可以拿到連接去操作數據庫--><bean class="org.springframework.jdbc.core.JdbcTemplate" id="jdbcTemplate"><!--給JdbcTemplate對象配置dateSource--><property name="dataSource" ref="dataSource"/></bean><!--配置NamedParameterJdbcTemplate對象--><!--<bean class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate" id="namedParameterJdbcTemplate">&lt;!&ndash;通過構造器, 設置數據源&ndash;&gt;<constructor-arg name="dataSource" ref="dataSource"/></bean>-->
</beans>

3)修改JdbcTemplateTest.java, 增加測試方法

public class JdbcTemplateTest {//測試MonsterDao是否生效@Testpublic void monsterDaoSave() {//獲取到容器ApplicationContext ioc =new ClassPathXmlApplicationContext("JdbcTemplate_ioc.xml");MonsterDao monsterDao = ioc.getBean(MonsterDao.class);monsterDao.save(new Monster(1000, "女媧", "女媧補天"));System.out.println("save ok~");}
}

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

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

相關文章

來聊聊JVM中安全點的概念

文章目錄 寫在文章開頭詳解safepoint基本概念什么是安全點?為什么需要安全點JVM如何讓線程跑到最近的安全點線程什么時候需要進入安全點JVM如何保證線程高效進入安全點如何設置安全點用一次GC解釋基于安全點的STW實踐-基于主線程休眠了解安全點的工作過程代碼示例基于日志印證…

搭建 Spark YARN 模式集群指南

在大數據處理領域&#xff0c;Apache Spark 憑借其卓越的性能和易用性廣受青睞。而 YARN&#xff08;Yet Another Resource Negotiator&#xff09;作為 Hadoop 的資源管理框架&#xff0c;能高效管理集群資源。將 Spark 與 YARN 結合&#xff0c;以 YARN 模式搭建集群&#xf…

WPF之Label控件詳解

文章目錄 1. 引言2. Label控件基礎2.1 類繼承結構2.2 Label類定義 3. Label控件的核心屬性3.1 Content屬性3.2 Target屬性3.3 其他常用屬性 4. 標簽樣式與模板自定義4.1 簡單樣式設置4.2 使用Style對象4.3 觸發器使用4.4 使用ControlTemplate完全自定義 5. Label與表單控件交互…

一種改進的YOLOv11網絡,用于無人機視角下的小目標檢測

大家讀完覺得有幫助記得關注和點贊&#xff01;&#xff01;&#xff01; 摘要 隨著無人機&#xff08;UAV&#xff09;和計算機視覺技術的快速發展&#xff0c;從無人機視角進行目標檢測已成為一個重要的研究領域。然而&#xff0c;無人機圖像中目標像素占比極小、物體尺度變…

Adobe Lightroom Classic v14.3.0.8 一款專業的數字攝影后期處理軟件

軟件介紹 Adobe Lightroom Classic 2025中文激活版&#xff08;Adobe桌面照片編輯軟件&#xff09;LRC2025&#xff08;LR2025本地離線版&#xff09;是一款桌面照片編輯器和相冊管理軟件的raw格式編輯軟件&#xff0c;支持各種RAW圖像相機配置&#xff0c;HDR全景照片&#x…

【Statsmodels和SciPy介紹與常用方法】

Statsmodels庫介紹與常用方法 Statsmodels 是一個強大的 Python 庫&#xff0c;專注于統計建模和數據分析&#xff0c;廣泛應用于經濟學、金融、生物統計等領域。它提供了豐富的統計模型、假設檢驗和數據探索工具&#xff0c;適合進行回歸分析、時間序列分析等任務。本文將介紹…

【Rust通用集合類型】Rust向量Vector、String、HashMap原理解析與應用實戰

?? 歡迎大家來到景天科技苑?? &#x1f388;&#x1f388; 養成好習慣&#xff0c;先贊后看哦~&#x1f388;&#x1f388; &#x1f3c6; 作者簡介&#xff1a;景天科技苑 &#x1f3c6;《頭銜》&#xff1a;大廠架構師&#xff0c;華為云開發者社區專家博主&#xff0c;…

SoapUi測試1——REST(WebAPi、Json協議/HTTP、Post通訊方式)接口測試

文章目錄 1背景1.1接口測試工具SoapUi產生背景1.2常見接口類型1.3接口包含內容1.4請求格式 2軟件使用3http、webservice、webapi如何測試3.1REST&#xff08;WebAPi、JSON/HTTP、POST&#xff09;3.2SOAP&#xff08;Webserver、XML/HTTP、POST&#xff09; 1背景 1.1接口測試…

Linux按鍵驅動測試

文章目錄 一、設備節點添加 二、創建驅動文件代碼 2.1 核心數據結構 2.2 按鍵值定義 2.3 關鍵函數實現 三、創建測試文件 四、測試 一、設備節點添加 首先在設備樹文件中添加pinctrl以及在根目錄下添加設備節點。如下&#xff1a; //創建按鍵輸入的pinctrlpinctrl_key: keygrp…

5000元可以運行32B大模型的筆記本

5000元可以運行32B 大模型的筆記本 榮耀筆記本 X14 Plus 銳龍版 R7-8845HS -32G -1T 模型名稱 模型大小 tokens/s qwq-32b-q4 19GB 2.4 Qwen2.5-Coder-14B- Q8 16GB 4 DeepSeek-R1-Distill-Qwen-7B-Q8 8GB 8.1 DeepSeek-R1-Distill-Llama-8B-Q4 5GB 11.7

arm設備樹基礎知識

文章目錄 前言dts片段通用屬性介紹地址大小中斷phandlecompatible mmc節點介紹 前言 arm開發&#xff0c;早晚要了解設備樹 dts片段 interrupt-parent <0x8005>; model "linux,dummy-virt"; #size-cells <0x02>; #address-cells <0x02>; co…

【C++ 核心知識點面試攻略:從基礎到實戰(上位機開發視角)】

一、命名空間&#xff08;Namespace&#xff09;相關問題 問題1&#xff1a;C引入命名空間的核心目的是什么&#xff1f;如何通過命名空間解決命名沖突&#xff1f; 答案&#xff1a; C引入命名空間的核心目的是 避免全局作用域中的命名沖突&#xff0c;通過將變量、函數、類…

線性代數與數據學習

The Functions of Deep Learning (essay from SIAM News, December 2018) Deep Learning and Neural Nets

phpstorm用php連接數據庫報錯

項目場景&#xff1a; phpstorm用php連接數據庫 問題描述 用php使用mysql_connect 的時候報錯了&#xff0c;沒有這個函數 原因分析&#xff1a; php解釋器問題&#xff0c;后來查資料得知mysql_connct只適用于php5.5以下解釋器。一開始用的7&#xff0c;改成5.3以后還是報…

51c大模型~合集122

我自己的原文哦~ https://blog.51cto.com/whaosoft/13877107 #PHYBench 北大物院200人合作&#xff0c;金牌得主超50人&#xff01;PHYBench&#xff1a;大模型究竟能不能真的懂物理&#xff1f; 本項目由北京大學物理學院朱華星老師、曹慶宏副院長統籌指導。基準設計、…

單片機 + 圖像處理芯片 + TFT彩屏 觸摸滑動條控件

觸摸滑動條控件使用說明 一、項目概述 本項目基于單片機和RA8889/RA6809圖形處理芯片的TFT觸摸屏滑動條控件。該控件支持水平和垂直滑動條&#xff0c;可自定義外觀和行為&#xff0c;并支持回調函數進行值變化通知。 硬件平臺&#xff1a;51/ARM均可(測試時使用STC8H8K64U單…

linux離線安裝zsh

下載zsh 下載倉庫后解壓 下載地址&#xff1a;https://github.com/zsh-users/zsh 離線安裝 安裝方法見INSTALL文件 ./configure --prefix[/usr/local] make make install

機器學習中的數據轉換:關鍵步驟與最佳實踐

機器學習中的數據轉換&#xff1a;關鍵步驟與最佳實踐 摘要 &#xff1a;在機器學習領域&#xff0c;數據是模型的核心&#xff0c;而數據的轉換是構建高效、準確模型的關鍵步驟之一。本文深入探討了機器學習中數據轉換的重要性、常見的數據類型及其轉換方法&#xff0c;以及在…

TDR阻抗會爬坡? 別擔心,不是你的錯,你只是不夠了解TDR!

在背板系統或任何長走線設計里&#xff0c;你大概都碰過這畫面&#xff1a; TDR 曲線一開始乖乖在 92 Ω&#xff0c;但越往末端、阻抗越爬越高&#xff0c;來到最高 97 Ω&#xff0c;心里瞬間涼半截 &#x1f612; &#xff0c;「難不成... 板廠又翻車了嗎&#xff1f;」 然…

在另外一臺可以科學下載的電腦用ollama下載模型后,怎么導入到另外一臺服務器的ollama使用

環境&#xff1a; Win10專業版 Ubuntu20.04 問題描述&#xff1a; 在另外一臺可以科學下載的電腦用ollama下載模型后&#xff0c;怎么導入到另外一臺服務器的ollama使用&#xff0c;原電腦win10上的ollama下載的模型,復制到ubuntu20.04的ollama上推理 解決方案&#xff1a;…