摘要: <?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframewor 阅读全文
posted @ 2011-12-30 15:21 tazi 阅读(1167) 评论(0) 推荐(0) 编辑
摘要: JdbcTemplate jdbcTemplate==new JdbcTemplate(source);//传入DataSource类型的参数它封装了jdbc中Connection对象的取得,Statement对象的建立,异常的处理,Statement和Connection的关闭等操作。它是线程安全的。如:jdbcTemplate.update("delete from person where id=?", new Object[]{id}, new int[]{Types.INTEGER});其中第三个参数可以省略。或者使用PreparedStatementCreato 阅读全文
posted @ 2011-12-30 15:19 tazi 阅读(593) 评论(0) 推荐(0) 编辑
摘要: 1.Spring单个连接的数据源为<bean id="simpleDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost: 阅读全文
posted @ 2011-12-30 14:49 tazi 阅读(276) 评论(0) 推荐(0) 编辑
摘要: 不用在配置文件中配置Bean,使Bean交给容器管理。1.加入context命名空间<context:component-scan base-package="com.service"/>此配置加入了很多相关的注解处理器。也包括<context:annotation-config/>所对应的处理器。2.定义base-package,使Spring自动扫描该包以及所有子包中的所有的标注了某些注解的类。3.在类上根据类的作用分别用@Service(业务层)、@Controller,@Repository(DAO层),@Component(通用)4.get 阅读全文
posted @ 2011-12-30 12:23 tazi 阅读(231) 评论(0) 推荐(0) 编辑
摘要: 注入依赖对象有手工装配(推荐)和自动装配的方式。手工装配可在xml中,也可用注解方式。1.Setter2.构造器方式1 <bean id="pDao" class="PersonDaoBean"/>2 <bean id="ps" class="PersonServiceBean">3 <constructor-arg index="0" type="PersonDao" ref="pDao"/>4 <constru 阅读全文
posted @ 2011-12-30 10:22 tazi 阅读(230) 评论(0) 推荐(0) 编辑
摘要: 1.Bean的作用域默认Bean的作用域是singleton,另外还有prototype(每次都创建新的实例)2.Bean什么时候被创建singleton类型的Bean默认是在Spring容器启动时创建,prototype在getBean时创建可以修改这种行为:在<bean>中的lazy-init="default","false","true"或者在<beans >属性default-lazy-init="false"3.Bean初始化时执行某个方法 init-method="& 阅读全文
posted @ 2011-12-30 08:38 tazi 阅读(252) 评论(0) 推荐(0) 编辑