Spring
2.方便的事务管理: Spring的声明式事务管理力度是类级别,错。spring现在只支持方法级别的织入点,域级别的还没有实现。
3.Spring提供的DAO(数据访问对象)支持主要的目的是便于以标准的方式使用不同的数据访问技术。
4.异常包装:Spring能够包装Hibernate异常,把它们从CheckedException变为RuntimeException; 开发者可选择在恰当的层处理数据中不可恢复的异常,从而避免烦琐的 catch/throw 及异常声明
5.Spring提供的DAO支持了JDBC、JDO和Hibernate
6.Spring提供的DAO(数据访问对象)支持主要的目的是便于以标准的方式使用不同的数据访问技术。 简化 DAO 组件的开发。 Spring提供了一套抽象DAO类供你扩展。这些抽象类提供了一些方法,用来简化代码开发。 IoC 容器的使用,提供了 DAO 组件与业务逻辑组件之间的解耦。所有的 DAO 组件,都由容器负责注入到业务逻辑组件中,其业务组件无须关心 DAO 组件的实现。 面向接口编程及 DAO 模式的使用,提高了系统组件之间的解耦,降低了系统重构的成本。 方便的事务管理: Spring的声明式事务管理力度是方法级。 异常包装:Spring能够包装Hibernate异常,把它们从CheckedException变为RuntimeException; 开发者可选择在恰当的层处理数据中不可恢复的异常,从而避免烦琐的 catch/throw 及异常声明。
7.spring事务可以分为编程式事务和声明式事务
8.spring提供了一个事务的接口 PaltformTractionManager接口,针对不同的事务,spring进行了不同的实现
声明式事务最大的优点就是不需要通过编程的方式管理事务,这样就不需要在业务逻辑代码中掺杂事务管理的代码
1.Spring中涉及到事务管理的API有100多个,核心的只有三个: TransactionDefinition、PlatformTransactionManager、TransactionStatus。所谓事务管理,其实就是“按照给定的事务规则来执行提交或者回滚操作”。“给定的事务规则”就是用 TransactionDefinition 表示的,“按照……来执行提交或者回滚操作”便是用 PlatformTransactionManager 来表示,而 TransactionStatus 用于表示一个运行着的事务的状态。
2.TransactionDefinition, 该接口在前面已经介绍过,它用于定义一个事务。它包含了事务的静态属性,比如:事务传播行为、超时时间等等。Spring 为我们提供了一个默认的实现类:DefaultTransactionDefinition,该类适用于大多数情况。如果该类不能满足需求,可以通过实现 TransactionDefinition 接口来实现自己的事务定义。
3.PlatformTransactionManager 用于执行具体的事务操作。
Public interface PlatformTransactionManager{
TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException;
void commit(TransactionStatus status)throws TransactionException;
void rollback(TransactionStatus status)throws TransactionException;
}
根据底层所使用的不同的持久化 API 或框架,PlatformTransactionManager 的主要实现类大致如下:
DataSourceTransactionManager :适用于使用JDBC和iBatis进行数据持久化操作的情况。
HibernateTransactionManager :适用于使用Hibernate进行数据持久化操作的情况。
JpaTransactionManager :适用于使用JPA进行数据持久化操作的情况。
另外还有JtaTransactionManager 、JdoTransactionManager、JmsTransactionManager等等。
编程式事务需要你在代码中直接加入处理事务的逻辑,可能需要在代码中显式调用beginTransaction()、commit()、rollback()等事务管理相关的方法,如在执行a方法时候需要事务处理,你需要在a方法开始时候开启事务,处理完后。在方法结束时候,关闭事务. 声明式的事务的做法是在a方法外围添加注解或者直接在配置文件中定义,a方法需要事务处理,在spring中会通过配置文件在a方法前后拦截,并添加事务. 二者区别.编程式事务侵入性比较强,但处理粒度更细. 相当于一个是手动事务,另一个是系统自动事务。 编程试事务就是需要手工写代码提交事务,回滚事务等。 声明性事务就是在配置文件里面定义一下什么时候需要事务,到时候系统会自动commit,出异常了自动rollback,不需要在代码里面写commit或者rollback。
spring mvc 和struts2的区别: 1.spring mvc是基于方法的设计,而struts2是基于类的设计。 2.struts2有以自己的interceptor机制,spring mvc用的是独立的AOP方式。 3.spring mvc的方法之间基本上独立的,独享request response数据,struts2所有Action变量是共享的。 4.机制:spring mvc的入口是servlet,而struts2是filter。 5.性能:spring会稍微比struts快。 spring mvc是基于方法的设计 , 而sturts是基于类 , 每次发一次请求都会实例一个action,每个action都会被注入属性,而spring基于方法,粒度更细
8.Struts SpringMVC对比
参数传递:struts是在接受参数的时候,可以用属性来接受参数,这就说明参数是让多个方法共享的。
设计思想上: struts更加符合oop的编程思想 , spring就比较谨慎,在servlet上扩展。 8.intercepter(拦截器)的实现机制:struts有以自己的interceptor机制, spring mvc用的是独立的AOP方式 。
9.Spring通过对AOP的支持,借助log4j等Apache开源组件实现了日志系统。
Servlet
1.基于Servlet API如何实现转向时不在地址栏中显示转向后的地址?forward ( )
7.运用javax.servlet.RequestDispatcher接口的forward方法请求转发
8.Spring框架中的核心思想包括DI,IOC,AOP
9.Spring数据库连接池:DBCP数据源;C3P0数据源;Spring的数据源实现(DriverManagerDataSource);获取JNDI数据源
10..Servlet只包含了init方法
doGet和doPost是HttpServlet中的方法;forward是RequestDispatcher的方法