{"id":50662,"date":"2023-11-03T12:18:59","date_gmt":"2023-02-16T22:02:07","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-%e7%a4%ba%e4%be%8b\/"},"modified":"2024-05-04T07:19:58","modified_gmt":"2024-05-03T23:19:58","slug":"spring-jdbctemplate-%e7%a4%ba%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-%e7%a4%ba%e4%be%8b\/","title":{"rendered":"Spring JdbcTemplate \u793a\u4f8b"},"content":{"rendered":"<p>Spring JdbcTemplate\u662fSpring JDBC\u5305\u4e2d\u6700\u91cd\u8981\u7684\u7c7b\u3002<\/p>\n<h2>\u6625\u5b63JdbcTemplate<\/h2>\n<ul class=\"post-ul\">\n<li>JDBC produces a lot of boiler plate code, such as opening\/closing a connection to a database, handling sql exceptions etc. It makes the code extremely cumbersome and difficult to read.<\/li>\n<li>Implementing JDBC in the Spring Framework takes care of working with many low-level operations (opening\/closing connections, executing SQL queries, etc.).<\/li>\n<li>Thanks to this, when working with the database in the Spring Framework, we only need to define the connection parameters from the database and register the SQL query, the rest of the work for us is performed by Spring.<\/li>\n<li>JDBC in Spring has several classes (several approaches) for interacting with the database. The most common of these is using the JdbcTemplate class. This is the base class that manages the processing of all events and database connections.<\/li>\n<li>The JdbcTemplate class executes SQL queries, iterates over the ResultSet, and retrieves the called values, updates the instructions and procedure calls, \u201ccatches\u201d the exceptions, and translates them into the exceptions defined in the org.springframwork.dao package.<\/li>\n<li>Instances of the JdbcTemplate class are thread-safe. This means that by configuring a single instance of the JdbcTemplate class, we can then use it for several DAO objects.<\/li>\n<li>When using JdbcTemplate, most often, it is configured in the Spring configuration file. After that, it is implemented using bean in DAO classes.<\/li>\n<\/ul>\n<h3>Spring JdbcTemplate\u793a\u4f8b<\/h3>\n<p>\u8ba9\u6211\u4eec\u6765\u770b\u4e00\u4e2aSpring JdbcTemplate\u7684\u4f8b\u5b50\u7a0b\u5e8f\u3002\u6211\u5728\u8fd9\u91cc\u4f7f\u7528\u7684\u662fPostgresql\u6570\u636e\u5e93\uff0c\u4f46\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u5176\u4ed6\u5173\u7cfb\u6570\u636e\u5e93\uff0c\u6bd4\u5982MySQL\u548cOracle\u3002\u4f60\u53ea\u9700\u8981\u66f4\u6539\u6570\u636e\u5e93\u7684\u914d\u7f6e\uff0c\u5b83\u5c31\u53ef\u4ee5\u6b63\u5e38\u5de5\u4f5c\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4e00\u4e9b\u6837\u672c\u6570\u636e\u6765\u64cd\u4f5c\u3002\u4e0b\u9762\u7684SQL\u67e5\u8be2\u5c06\u521b\u5efa\u4e00\u4e2a\u8868\uff0c\u5e76\u4e3a\u6211\u4eec\u586b\u5145\u4e00\u4e9b\u6570\u636e\u4ee5\u4f9b\u4f7f\u7528\u3002<\/p>\n<pre class=\"post-pre\"><code>create table people (\r\nid serial not null primary key,\r\nfirst_name varchar(20) not null,\r\nlast_name varchar(20) not null,\r\nage integer not null\r\n);\r\n\r\ninsert into people (id, first_name, last_name, age) values\r\n(1, 'Vlad', 'Boyarskiy', 21),\r\n(2,'Oksi', ' Bahatskaya', 30),\r\n(3,'Vadim', ' Vadimich', 32);\r\n<\/code><\/pre>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/656486fda4b2f92e6c73150f\/6-0.png\" alt=\"Spring JdbcTemplate Example\" \/><\/div>\n<h3>Spring JDBC\u7684Maven\u4f9d\u8d56<\/h3>\n<p>\u6211\u4eec\u9700\u8981\u4ee5\u4e0b\u4f9d\u8d56 &#8211; spring-core\u3001spring-context\u3001spring-jdbc \u548c postgresql\u3002\u5982\u679c\u60a8\u4f7f\u7528\u5176\u4ed6\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff0c\u5982MySQL\uff0c\u5219\u9700\u8981\u6dfb\u52a0\u76f8\u5e94\u7684Java\u9a71\u52a8\u7a0b\u5e8f\u4f9d\u8d56\u9879\u3002\u8fd9\u662f\u6211\u4eec\u7684\u6700\u7ec8pom.xml\u6587\u4ef6\u3002<\/p>\n<pre class=\"post-pre\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;project xmlns=\"https:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"https:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txsi:schemaLocation=\"https:\/\/maven.apache.org\/POM\/4.0.0 https:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\r\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\r\n\r\n\t&lt;groupId&gt;com.Olivia.spring&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;JdbcTemplate&lt;\/artifactId&gt;\r\n\t&lt;version&gt;1.0-SNAPSHOT&lt;\/version&gt;\r\n\t&lt;properties&gt;\r\n\t\t&lt;spring.framework&gt;4.3.0.RELEASE&lt;\/spring.framework&gt;\r\n\t\t&lt;postgres.version&gt;42.1.4&lt;\/postgres.version&gt;\r\n\t&lt;\/properties&gt;\r\n\t&lt;dependencies&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.postgresql&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;postgresql&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;${postgres.version}&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-core&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;${spring.framework}&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-context&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;${spring.framework}&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-jdbc&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;${spring.framework}&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t&lt;\/dependencies&gt;\r\n\r\n&lt;\/project&gt;\r\n<\/code><\/pre>\n<h3>Spring\u7684\u6570\u636e\u6e90\u914d\u7f6e<\/h3>\n<p>\u4e0b\u4e00\u6b65\u662f\u521b\u5efaspring\u914d\u7f6e\u7c7b\u6765\u5b9a\u4e49DataSource bean\u3002\u6211\u6b63\u5728\u4f7f\u7528\u57fa\u4e8eJava\u7684\u914d\u7f6e\uff0c\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528spring Bean\u914d\u7f6eXML\u6587\u4ef6\u6765\u5b8c\u6210\u8fd9\u4e00\u6b65\u9aa4\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.Olivia.spring.config;\r\n\r\nimport javax.sql.DataSource;\r\n\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.context.annotation.Bean;\r\nimport org.springframework.context.annotation.ComponentScan;\r\nimport org.springframework.context.annotation.Configuration;\r\nimport org.springframework.context.annotation.PropertySource;\r\nimport org.springframework.core.env.Environment;\r\nimport org.springframework.jdbc.datasource.DriverManagerDataSource;\r\n\r\n@Configuration\r\n@ComponentScan(\"com.Olivia.spring\")\r\n@PropertySource(\"classpath:database.properties\")\r\npublic class AppConfig {\r\n\r\n\t@Autowired\r\n\tEnvironment environment;\r\n\r\n\tprivate final String URL = \"url\";\r\n\tprivate final String USER = \"dbuser\";\r\n\tprivate final String DRIVER = \"driver\";\r\n\tprivate final String PASSWORD = \"dbpassword\";\r\n\r\n\t@Bean\r\n\tDataSource dataSource() {\r\n\t\tDriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();\r\n\t\tdriverManagerDataSource.setUrl(environment.getProperty(URL));\r\n\t\tdriverManagerDataSource.setUsername(environment.getProperty(USER));\r\n\t\tdriverManagerDataSource.setPassword(environment.getProperty(PASSWORD));\r\n\t\tdriverManagerDataSource.setDriverClassName(environment.getProperty(DRIVER));\r\n\t\treturn driverManagerDataSource;\r\n\t}\r\n}\r\n<\/code><\/pre>\n<ul class=\"post-ul\">\n<li>@Configuration \u2013 says that this class is configuration for Spring context.<\/li>\n<li>@ComponentScan(\u201ccom.Olivia.spring\u201d)- specifies the package to scan for component classes.<\/li>\n<li>@PropertySource(\u201cclasspath:database.properties\u201d)- says that properties will be read from database.properties file.<\/li>\n<\/ul>\n<p>\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6\u7684\u5185\u5bb9\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre class=\"post-pre\"><code>driver=org.postgresql.Driver\r\nurl=jdbc:postgresql:\/\/127.0.0.1:5432\/school\r\ndbuser=postgres\r\ndbpassword=postgres\r\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u4f7f\u7528MySQL\u6216\u5176\u4ed6\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff0c\u8bf7\u76f8\u5e94\u5730\u66f4\u6539\u4e0a\u8ff0\u914d\u7f6e\u3002<\/p>\n<h3>Spring\u6846\u67b6\u7684JDBC\u6a21\u578b\u7c7b<\/h3>\n<p>\u4e0b\u4e00\u6b65\u662f\u521b\u5efa\u6a21\u578b\u7c7b\u6765\u6620\u5c04\u6211\u4eec\u7684\u6570\u636e\u5e93\u8868\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.Olivia.model;\r\n\r\npublic class Person {\r\n\tprivate Long id;\r\n\tprivate Integer age;\r\n\tprivate String firstName;\r\n\tprivate String lastName;\r\n\r\n\tpublic Person() {\r\n\t}\r\n\r\n\tpublic Person(Long id, Integer age, String firstName, String lastName) {\r\n\t\tthis.id = id;\r\n\t\tthis.age = age;\r\n\t\tthis.firstName = firstName;\r\n\t\tthis.lastName = lastName;\r\n\t}\r\n\r\n\tpublic Long getId() {\r\n\t\treturn id;\r\n\t}\r\n\r\n\tpublic void setId(Long id) {\r\n\t\tthis.id = id;\r\n\t}\r\n\r\n\tpublic Integer getAge() {\r\n\t\treturn age;\r\n\t}\r\n\r\n\tpublic void setAge(Integer age) {\r\n\t\tthis.age = age;\r\n\t}\r\n\r\n\tpublic String getFirstName() {\r\n\t\treturn firstName;\r\n\t}\r\n\r\n\tpublic void setFirstName(String firstName) {\r\n\t\tthis.firstName = firstName;\r\n\t}\r\n\r\n\tpublic String getLastName() {\r\n\t\treturn lastName;\r\n\t}\r\n\r\n\tpublic void setLastName(String lastName) {\r\n\t\tthis.lastName = lastName;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic String toString() {\r\n\t\treturn \"Person{\" + \"id=\" + id + \", age=\" + age + \", firstName='\" + firstName + '\\'' + \", lastName='\" + lastName\r\n\t\t\t\t+ '\\'' + '}';\r\n\t}\r\n}\r\n<\/code><\/pre>\n<p>\u4e3a\u4e86\u4ece\u6570\u636e\u5e93\u83b7\u53d6\u6570\u636e\uff0c\u6211\u4eec\u9700\u8981\u5b9e\u73b0RowMapper\u63a5\u53e3\u3002\u8be5\u63a5\u53e3\u53ea\u6709\u4e00\u4e2a\u65b9\u6cd5mapRow\uff08ResultSet resultSet\uff0cint i\uff09\uff0c\u8be5\u65b9\u6cd5\u5c06\u8fd4\u56de\u6211\u4eec\u6a21\u578b\u7c7b\uff08\u5373Person\uff09\u7684\u4e00\u4e2a\u5b9e\u4f8b\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.Olivia.model;\r\n\r\nimport java.sql.ResultSet;\r\nimport java.sql.SQLException;\r\n\r\nimport org.springframework.jdbc.core.RowMapper;\r\n\r\npublic class PersonMapper implements RowMapper&lt;Person&gt; {\r\n\r\n\tpublic Person mapRow(ResultSet resultSet, int i) throws SQLException {\r\n\r\n\t\tPerson person = new Person();\r\n\t\tperson.setId(resultSet.getLong(\"id\"));\r\n\t\tperson.setFirstName(resultSet.getString(\"first_name\"));\r\n\t\tperson.setLastName(resultSet.getString(\"last_name\"));\r\n\t\tperson.setAge(resultSet.getInt(\"age\"));\r\n\t\treturn person;\r\n\t}\r\n}\r\n<\/code><\/pre>\n<h3>Spring JDBC DAO \u7c7b<\/h3>\n<p>\u6700\u540e\u4e00\u6b65\u662f\u521b\u5efaDAO\u7c7b\uff0c\u4f7f\u7528SQL\u67e5\u8be2\u5c06\u6211\u4eec\u7684\u6a21\u578b\u7c7b\u6620\u5c04\u5230\u6570\u636e\u5e93\u8868\u3002\u6211\u4eec\u8fd8\u5c06\u4f7f\u7528@Autowired\u6ce8\u89e3\u914d\u7f6e\u6570\u636e\u6e90\uff0c\u5e76\u66b4\u9732\u4e00\u4e9bAPI\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.Olivia.spring.dao;\r\n\r\nimport java.util.List;\r\n\r\nimport com.Olivia.model.Person;\r\n\r\npublic interface PersonDAO {\r\n\tPerson getPersonById(Long id);\r\n\r\n\tList&lt;Person&gt; getAllPersons();\r\n\r\n\tboolean deletePerson(Person person);\r\n\r\n\tboolean updatePerson(Person person);\r\n\r\n\tboolean createPerson(Person person);\r\n}\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>package com.Olivia.spring.dao;\r\n\r\nimport java.util.List;\r\n\r\nimport javax.sql.DataSource;\r\n\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.jdbc.core.JdbcTemplate;\r\nimport org.springframework.stereotype.Component;\r\n\r\nimport com.Olivia.model.Person;\r\nimport com.Olivia.model.PersonMapper;\r\n\r\n@Component\r\npublic class PersonDAOImpl implements PersonDAO {\r\n\r\n\tJdbcTemplate jdbcTemplate;\r\n\r\n\tprivate final String SQL_FIND_PERSON = \"select * from people where id = ?\";\r\n\tprivate final String SQL_DELETE_PERSON = \"delete from people where id = ?\";\r\n\tprivate final String SQL_UPDATE_PERSON = \"update people set first_name = ?, last_name = ?, age  = ? where id = ?\";\r\n\tprivate final String SQL_GET_ALL = \"select * from people\";\r\n\tprivate final String SQL_INSERT_PERSON = \"insert into people(id, first_name, last_name, age) values(?,?,?,?)\";\r\n\r\n\t@Autowired\r\n\tpublic PersonDAOImpl(DataSource dataSource) {\r\n\t\tjdbcTemplate = new JdbcTemplate(dataSource);\r\n\t}\r\n\r\n\tpublic Person getPersonById(Long id) {\r\n\t\treturn jdbcTemplate.queryForObject(SQL_FIND_PERSON, new Object[] { id }, new PersonMapper());\r\n\t}\r\n\r\n\tpublic List&lt;Person&gt; getAllPersons() {\r\n\t\treturn jdbcTemplate.query(SQL_GET_ALL, new PersonMapper());\r\n\t}\r\n\r\n\tpublic boolean deletePerson(Person person) {\r\n\t\treturn jdbcTemplate.update(SQL_DELETE_PERSON, person.getId()) &gt; 0;\r\n\t}\r\n\r\n\tpublic boolean updatePerson(Person person) {\r\n\t\treturn jdbcTemplate.update(SQL_UPDATE_PERSON, person.getFirstName(), person.getLastName(), person.getAge(),\r\n\t\t\t\tperson.getId()) &gt; 0;\r\n\t}\r\n\r\n\tpublic boolean createPerson(Person person) {\r\n\t\treturn jdbcTemplate.update(SQL_INSERT_PERSON, person.getId(), person.getFirstName(), person.getLastName(),\r\n\t\t\t\tperson.getAge()) &gt; 0;\r\n\t}\r\n}\r\n<\/code><\/pre>\n<p>PersonDAOImpl\u7c7b\u4f7f\u7528@Component\u6ce8\u89e3\u8fdb\u884c\u4e86\u6ce8\u89e3\uff0c\u5728\u8fd9\u4e2a\u7c7b\u4e2d\u6211\u4eec\u6709\u4e00\u4e2a\u7c7b\u578b\u4e3aJdbcTemplate\u7684\u5b57\u6bb5\u3002\u5f53\u8c03\u7528\u8be5\u7c7b\u7684\u6784\u9020\u51fd\u6570\u65f6\uff0c\u4e00\u4e2aDataSource\u7684\u5b9e\u4f8b\u5c06\u88ab\u6ce8\u5165\u5176\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efaJdbcTemplate\u7684\u5b9e\u4f8b\u3002\u4e4b\u540e\u6211\u4eec\u53ef\u4ee5\u5728\u6211\u4eec\u7684\u65b9\u6cd5\u4e2d\u4f7f\u7528\u5b83\u3002<\/p>\n<h3>Spring JdbcTemplate \u6d4b\u8bd5\u7a0b\u5e8f<\/h3>\n<p>\u6211\u4eec\u7684Spring JdbcTemplate\u793a\u4f8b\u9879\u76ee\u51c6\u5907\u597d\u4e86\uff0c\u8ba9\u6211\u4eec\u7528\u4e00\u4e2a\u6d4b\u8bd5\u7c7b\u6765\u6d4b\u8bd5\u5427\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.Olivia;\r\n\r\nimport org.springframework.context.annotation.AnnotationConfigApplicationContext;\r\n\r\nimport com.Olivia.model.Person;\r\nimport com.Olivia.spring.config.AppConfig;\r\nimport com.Olivia.spring.dao.PersonDAO;\r\n\r\npublic class Main {\r\n\tpublic static void main(String[] args) {\r\n\t\tAnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);\r\n\r\n\t\tPersonDAO personDAO = context.getBean(PersonDAO.class);\r\n\r\n\t\tSystem.out.println(\"List of person is:\");\r\n\r\n\t\tfor (Person p : personDAO.getAllPersons()) {\r\n\t\t\tSystem.out.println(p);\r\n\t\t}\r\n\r\n\t\tSystem.out.println(\"\\nGet person with ID 2\");\r\n\r\n\t\tPerson personById = personDAO.getPersonById(2L);\r\n\t\tSystem.out.println(personById);\r\n\r\n\t\tSystem.out.println(\"\\nCreating person: \");\r\n\t\tPerson person = new Person(4L, 36, \"Sergey\", \"Emets\");\r\n\t\tSystem.out.println(person);\r\n\t\tpersonDAO.createPerson(person);\r\n\t\tSystem.out.println(\"\\nList of person is:\");\r\n\r\n\t\tfor (Person p : personDAO.getAllPersons()) {\r\n\t\t\tSystem.out.println(p);\r\n\t\t}\r\n\r\n\t\tSystem.out.println(\"\\nDeleting person with ID 2\");\r\n\t\tpersonDAO.deletePerson(personById);\r\n\r\n\t\tSystem.out.println(\"\\nUpdate person with ID 4\");\r\n\r\n\t\tPerson pperson = personDAO.getPersonById(4L);\r\n\t\tpperson.setLastName(\"CHANGED\");\r\n\t\tpersonDAO.updatePerson(pperson);\r\n\r\n\t\tSystem.out.println(\"\\nList of person is:\");\r\n\t\tfor (Person p : personDAO.getAllPersons()) {\r\n\t\t\tSystem.out.println(p);\r\n\t\t}\r\n\r\n\t\tcontext.close();\r\n\t}\r\n}\r\n<\/code><\/pre>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/656486fda4b2f92e6c73150f\/30-0.png\" alt=\"Spring JDBC, Spring JdbcTemplate Example\" \/><\/div>\n<p>\u4e0b\u8f7dSpring JdbcTemplate\u793a\u4f8b\u9879\u76ee\u3002<\/p>\n<p>\u53c2\u8003\u8d44\u6599\uff1aAPI \u6587\u6863<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring JdbcTemplate\u662fSpring JDBC\u5305\u4e2d\u6700\u91cd\u8981\u7684\u7c7b\u3002 \u6625\u5b63JdbcTemplate  [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-50662","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring JdbcTemplate \u793a\u4f8b - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-\u793a\u4f8b\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring JdbcTemplate \u793a\u4f8b\" \/>\n<meta property=\"og:description\" content=\"Spring JdbcTemplate\u662fSpring JDBC\u5305\u4e2d\u6700\u91cd\u8981\u7684\u7c7b\u3002 \u6625\u5b63JdbcTemplate [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-\u793a\u4f8b\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-16T22:02:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-03T23:19:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/656486fda4b2f92e6c73150f\/6-0.png\" \/>\n<meta name=\"author\" content=\"\u6587, \u7fd4\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u6587, \u7fd4\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-%e7%a4%ba%e4%be%8b\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-%e7%a4%ba%e4%be%8b\/\",\"name\":\"Spring JdbcTemplate \u793a\u4f8b - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-02-16T22:02:07+00:00\",\"dateModified\":\"2024-05-03T23:19:58+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/64d5cc7727fffbff2f9a2a8da1de3e5c\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-%e7%a4%ba%e4%be%8b\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-%e7%a4%ba%e4%be%8b\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-%e7%a4%ba%e4%be%8b\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring JdbcTemplate \u793a\u4f8b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/64d5cc7727fffbff2f9a2a8da1de3e5c\",\"name\":\"\u6587, \u7fd4\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/920c3d673e0bccacc98e5e6b7149bb3c22edd8d39cb753e5d7d7e471498118a1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/920c3d673e0bccacc98e5e6b7149bb3c22edd8d39cb753e5d7d7e471498118a1?s=96&d=mm&r=g\",\"caption\":\"\u6587, \u7fd4\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/wenxiang\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-%e7%a4%ba%e4%be%8b\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Spring JdbcTemplate \u793a\u4f8b - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-\u793a\u4f8b\/","og_locale":"zh_CN","og_type":"article","og_title":"Spring JdbcTemplate \u793a\u4f8b","og_description":"Spring JdbcTemplate\u662fSpring JDBC\u5305\u4e2d\u6700\u91cd\u8981\u7684\u7c7b\u3002 \u6625\u5b63JdbcTemplate [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-\u793a\u4f8b\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-02-16T22:02:07+00:00","article_modified_time":"2024-05-03T23:19:58+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/656486fda4b2f92e6c73150f\/6-0.png"}],"author":"\u6587, \u7fd4","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6587, \u7fd4","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-%e7%a4%ba%e4%be%8b\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-%e7%a4%ba%e4%be%8b\/","name":"Spring JdbcTemplate \u793a\u4f8b - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-02-16T22:02:07+00:00","dateModified":"2024-05-03T23:19:58+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/64d5cc7727fffbff2f9a2a8da1de3e5c"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-%e7%a4%ba%e4%be%8b\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-%e7%a4%ba%e4%be%8b\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-%e7%a4%ba%e4%be%8b\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"Spring JdbcTemplate \u793a\u4f8b"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/64d5cc7727fffbff2f9a2a8da1de3e5c","name":"\u6587, \u7fd4","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/920c3d673e0bccacc98e5e6b7149bb3c22edd8d39cb753e5d7d7e471498118a1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/920c3d673e0bccacc98e5e6b7149bb3c22edd8d39cb753e5d7d7e471498118a1?s=96&d=mm&r=g","caption":"\u6587, \u7fd4"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/wenxiang\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/spring-jdbctemplate-%e7%a4%ba%e4%be%8b\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/50662","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=50662"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/50662\/revisions"}],"predecessor-version":[{"id":96917,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/50662\/revisions\/96917"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=50662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=50662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=50662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}