摘要: 1.ThreadLocal仿代码package com.tazi.aop;import java.util.Collections; import java.util.HashMap; import java.util.Map;public class MyThreadLocal<T> { private Map<Thread,T> values=Collections.synchronizedMap(new HashMap<Thread,T>()); public T get(){ Thread thread=Thread.currentThread(); 阅读全文
posted @ 2012-01-04 09:25 tazi 阅读(273) 评论(0) 推荐(0)
摘要: 1.odbc方式2.jdbc驱动包方式public static void main(String[] args) { try { //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Class.forName("oracle.jdbc.driver.OracleDriver"); //Connection con=DriverManager.getConnection("jdbc:odbc:scott", "scott", "123456"); C 阅读全文
posted @ 2012-01-04 09:23 tazi 阅读(157) 评论(0) 推荐(0)
摘要: 1.加上Context命名空间xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation加上http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"2.要使用注解方式,进行依赖注入。要加上@Resource等注解的解析器<context:annotation-config/>3.要 阅读全文
posted @ 2012-01-04 09:22 tazi 阅读(862) 评论(0) 推荐(0)
摘要: 使用Hibernate 1.Hibernate核心包 hibernate-distribution-3.31.GA hibernate3.jar lib/bytecode/cglib/hiber... 阅读全文
posted @ 2012-01-04 09:21 tazi 阅读(355) 评论(2) 推荐(0)
摘要: <?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 阅读(1177) 评论(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 阅读(606) 评论(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 阅读(284) 评论(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 阅读(240) 评论(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 阅读(234) 评论(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 阅读(268) 评论(0) 推荐(0)