spring JdbcTemplate在spring的ioc中使用
package com.com.jdbctemplate; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate; /**
* spirng JdbcTemplate在spring中的ioc中使用
*/
public class JDBCTemplateDemo2 {
public static void main(String[] args) {
//1.获取spirng的核心容器
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
//2.获取对象
JdbcTemplate jt = ac.getBean("jdbcTemplate", JdbcTemplate.class);
//3.执行操作
jt.execute("insert into account(name,money)values('eee',2000)");
}
}
xml文件的ioc配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--配置JdbcTemplate对象-->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--配置数据源 使用spring的内置数据源-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/spring"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
</beans>
spring JdbcTemplate在spring的ioc中使用的更多相关文章
- Spring JdbcTemplate详解及项目中的运用
1.Spring对不同的持久化支持: Spring为各种支持的持久化技术,都提供了简单操作的模板和回调 ORM持久化技术 模板类 JDBC org.springframework.jdbc.core. ...
- 04 Spring:01.Spring框架简介&&02.程序间耦合&&03.Spring的 IOC 和 DI&&08.面向切面编程 AOP&&10.Spring中事务控制
spring共四天 第一天:spring框架的概述以及spring中基于XML的IOC配置 第二天:spring中基于注解的IOC和ioc的案例 第三天:spring中的aop和基于XML以及注解的A ...
- 【SSH系列】深入浅出spring IOC中三种依赖注入方式
spring的核心思想是IOC和AOP,IOC-控制反转,是一个重要的面向对象编程的法则来消减计算机程序的耦合问题,控制反转一般分为两种类型,依赖注入和依赖查找,依赖什么?为什么需要依赖?注入什么?控 ...
- Spring系列(三):Spring IoC中各个注解的理解和使用
原文链接:1. http://www.cnblogs.com/xdp-gacl/p/3495887.html 2. http://www.cnblogs.com/xiaoxi/p/5935 ...
- spring IOC中三种依赖注入方式
Spring的核心思想是IOC和AOP,IOC-控制反转,是一个重要的面向对象编程的法则,用来消减计算机程序之间的耦合问题,控制反转一般分为两种类型,依赖注入和依赖查找,依赖什么?为什么需要依赖?注入 ...
- spring IOC中四种依赖注入方式
在spring ioc中有三种依赖注入,分别是:https://blog.csdn.net/u010800201/article/details/72674420 a.接口注入:b.setter方法注 ...
- Spring IoC中各个注解的理解和使用
一.把在Spring的xml文件中配置bean改为Spring的注解来配置bean 传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的 ...
- 深入浅出spring IOC中三种依赖注入方式
深入浅出spring IOC中三种依赖注入方式 spring的核心思想是IOC和AOP,IOC-控制反转,是一个重要的面向对象编程的法则来消减计算机程序的耦合问题,控制反转一般分为两种类型,依赖注入和 ...
- Spring入门2. IoC中装配Bean
Spring入门2. IoC中装配Bean 20131125 前言: 上一节学习了Spring在JavaProject中的配置,通过配置文件利用BeanFactory和ApplicationConte ...
随机推荐
- ThinkPHP 删除数据
ThinkPHP删除数据使用delete方法,例如: 直线电机价格 $Form = M('Form'); $Form->delete(5); 表示删除主键为5的数据,delete方法可以删除单个 ...
- Spring简洁总结
Spring简洁总结 要的对象不是自己建的,而是IOC容器(XML文件)给的,我们通过getbean来调用. 依赖注入的话就是对象(bean)的成员的赋值不是我们手动完成,而是容器(XML文件)给我 ...
- linux 每天一个命令
Nginx [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use) 使用命令关闭占用80端口的程序 sudo fuser ...
- CMS 源码解读
CMS 是”Content Management System” 的缩写,意为” 内容管理系统”. 内容管理系统是企业信息化建设和电子政务的新宠,也是一个相对较新的市场.对于内容管理,业界还没有一个统 ...
- [原创]新版PageOffice V4.0为什么用弹出窗口的方式打开文件?
前的包含文档处理功能的Web办公系统,在打开文档的时候,一部分系统是采用Office文档嵌入到主窗口页面中右侧工作区域的方式,另一部分系统采用的是弹出新的浏览器窗口,里面完整的嵌入Office文件的打 ...
- 08_springmvc数据回显和@ModelAttribute注解详解
一.数据回显 提交后,如果出现错误,将刚才提交的数据回显到刚才的提交页面. 二.pojo数据回显方法 1.springmvc默认对pojo数据进行回显. pojo数据传入controller方法后,s ...
- 03_Spring Bean的装配模式_基于Annotation配置方式
前言 在Spring中尽管使用XML配置文件可以实现Bean的装配工作,但如果应用中Bean的数量较多,会导致XML配置文件过于臃肿,从而给维护和升级带来一定的困难.从JDK 5开始提供了名为Anno ...
- PKU_3624(0-1背包)
题目:http://poj.org/problem?id=3624 分析:这是一个0-1背包的问题. #include<stdio.h>#include<string.h>in ...
- SprigBoot中的 WebMvcConfigurer与 WebMvcConfigurerAdapter和 WebMvcConfigurationSupport
WebMvcConfigurationAdapter 过时? 在SpringBoot2.0之后的版本中WebMvcConfigurerAdapter过时了,所以我们一般采用的是如下的两种的解决的方法. ...
- Spring 调度工具Quartz cron 表达式的格式
http://chinaxxren.iteye.com/blog/839630 Quartz cron 表达式的格式十分类似于 UNIX cron 格式,但还是有少许明显的区别.区别之一就是 Quar ...