Spring中JdbcTemplate即Jdbc封装工具类的使用
Spring中JdbcTemplate即Jdbc封装工具类的使用Spring中封装好的工具类叫作模板(Template)导入的坐标为:<dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.
·
Spring中JdbcTemplate即Jdbc封装工具类的使用
Spring中封装好的工具类叫作模板(Template)

导入的坐标为:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
快速入门:

变为:
public class JdbcDemo {
@Test
public void fun(){
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
JdbcTemplate jdbcTemplate = context.getBean(JdbcTemplate.class);
int i = jdbcTemplate.update("insert into jdbc values (?,?)", 123, "张佳成");
System.out.println(i);
}
}
然后可以抽取Properties工具类,前面都讲过

插入/修改/删除操作
在JdbcTemplate中插入操作/修改操作/删除操作。都归结为update操作。
查询操作
- 查询所有

- 查询一个

更多推荐


所有评论(0)