![](http://static.blog.csdn.net/images/category_icon.jpg)
版权声明:本文为本人辛苦原创文章,如果需要转载,请注明出处,谢谢!!!
SSH框架整合
1 Struts2+Spring+Hibernate导包
Struts2导入jar包:
* struts2/apps/struts2-blank.war/WEB-INF/lib/*.jar
导入与spring整合的jar
* struts2/lib/struts2-spring-plugin-2.3.15.3.jar--- 整合Spring框架
* struts2/lib/struts2-json-plugin-2.3.15.3.jar--- 整合AJAX
* struts2/lib/struts2-convention-plugin-2.3.15.3.jar--- 使用Struts2注解开发.
Spring导入jar包:
Spring3.2 开发最基本jar包
spring-beans-3.2.0.RELEASE.jar
spring-context-3.2.0.RELEASE.jar
spring-core-3.2.0.RELEASE.jar
spring-expression-3.2.0.RELEASE.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.apache.log4j-1.2.15.jar
AOP开发
spring-aop-3.2.0.RELEASE.jar
spring-aspects-3.2.0.RELEASE.jar
com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
Spring Jdbc开发
spring-jdbc-3.2.0.RELEASE.jar
spring-tx-3.2.0.RELEASE.jar
Spring事务管理
spring-tx-3.2.0.RELEASE.jar
Spring整合其他ORM框架
spring-orm-3.2.0.RELEASE.jar
Spring在web中使用
spring-web-3.2.0.RELEASE.jar
Spring整合Junit测试
spring-test-3.2.0.RELEASE.jar
hibernate的jar包导入:
* 核心包:hibernate3.jar
* lib/required/*.jar
* lib/jpa/*.jar
* 引入hibernate整合日志系统的jar包:
* 数据连接池:
* 数据库驱动:
二级缓存:(可选的.)
* backport-util-concurrent.jar
* commons-logging.jar
* ehcache-1.5.0.jar
2 配置文件
2.1 web.xml
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <p><!-- 配置Spring的监听器 --></p><p><listener></p><p><!-- 监听器默认加载的是WEB-INF/applicationContext.xml --></p><p><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></p><p></listener></p><p> </p><p><!-- 指定Spring框架的配置文件所在的位置 --></p><p><context-param></p><p><param-name>contextConfigLocation</param-name></p><p><param-value>classpath:applicationContext.xml</param-value></p><p></context-param></p>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 配置Spring的监听器 -->
<listener>
<!-- 监听器默认加载的是WEB-INF/applicationContext.xml -->
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 指定Spring框架的配置文件所在的位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
2.2 struts.xml
- <struts>
- <constant name="struts.devMode" value="true" />
- <package name="default" namespace="/" extends="struts-default">
- </package>
- </struts>
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
</package>
</struts>
2.3 加入配置文件
applicationContext.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd">
- <!-- 零障碍整合 在spring配置文件中引入hibernate的配置文件 -->
- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
- </bean>
- <!-- 配置Action -->
- <bean id="bookAction" class="com.sihai.action.BookAction" scope="prototype">
- <property name="bookService" ref="bookService"/>
- </bean>
- <!-- Service的配置 -->
- <bean id="bookService" class="com.sihai.service.BookService">
- <property name="bookDao" ref="bookDao"/>
- </bean>
- <!-- DAO的配置 -->
- <bean id="bookDao" class="com.sihai.dao.BookDao">
- <property name="sessionFactory" ref="sessionFactory"/>
- </bean>
- <!-- 管理事务 -->
- <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
- <property name="sessionFactory" ref="sessionFactory"/>
- </bean>
- <!-- 注解开启事务 -->
- <tx:annotation-driven transaction-manager="transactionManager"/>
- </beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 零障碍整合 在spring配置文件中引入hibernate的配置文件 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
</bean>
<!-- 配置Action -->
<bean id="bookAction" class="com.sihai.action.BookAction" scope="prototype">
<property name="bookService" ref="bookService"/>
</bean>
<!-- Service的配置 -->
<bean id="bookService" class="com.sihai.service.BookService">
<property name="bookDao" ref="bookDao"/>
</bean>
<!-- DAO的配置 -->
<bean id="bookDao" class="com.sihai.dao.BookDao">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 管理事务 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 注解开启事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
Log4j.properties
- ### direct log messages to stdout ###
- log4j.appender.stdout=org.apache.log4j.ConsoleAppender
- log4j.appender.stdout.Target=System.out
- log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
- log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
- ### direct messages to file mylog.log ###
- log4j.appender.file=org.apache.log4j.FileAppender
- log4j.appender.file.File=c:/mylog.log
- log4j.appender.file.layout=org.apache.log4j.PatternLayout
- log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
- ### set log levels - for more verbose logging change 'info' to 'debug' ###
- log4j.rootLogger=info, stdout
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### direct messages to file mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c:/mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=info, stdout
Hibernate的配置:
hibernate.cfg.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <!-- 必须去配置的属性 -->
- <!-- 配置数据库连接的基本信息: -->
- <property name="hibernate.connection.driver_class">
- com.mysql.jdbc.Driver
- </property>
- <property name="hibernate.connection.url">
- jdbc:mysql:///ssh1
- </property>
- <property name="hibernate.connection.username">root</property>
- <property name="hibernate.connection.password">123</property>
- <!-- Hibernate的方言 -->
- <!-- 生成底层SQL不同的 -->
- <property name="hibernate.dialect">
- org.hibernate.dialect.MySQLDialect
- </property>
- <!-- 可选的属性 -->
- <!-- 显示SQL -->
- <property name="hibernate.show_sql">true</property>
- <!-- 格式化SQL -->
- <property name="hibernate.format_sql">true</property>
- <property name="hibernate.connection.autocommit">false</property>
- <!-- hbm:映射 to DDL: create drop alter -->
- <property name="hibernate.hbm2ddl.auto">update</property>
- <!-- C3P0连接池设定-->
- <!-- 使用c3po连接池 配置连接池提供的供应商-->
- <property name="connection.provider_class">
- org.hibernate.connection.C3P0ConnectionProvider
- </property>
- <!--在连接池中可用的数据库连接的最少数目 -->
- <property name="c3p0.min_size">5</property>
- <!--在连接池中所有数据库连接的最大数目 -->
- <property name="c3p0.max_size">20</property>
- <!--设定数据库连接的过期时间,以秒为单位,
- 如果连接池中的某个数据库连接处于空闲状态的时间超过了timeout时间,就会从连接池中清除 -->
- <property name="c3p0.timeout">120</property>
- <!--每3000秒检查所有连接池中的空闲连接 以秒为单位-->
- <property name="c3p0.idle_test_period">3000</property>
- <!-- 通知Hibernate加载那些映射文件 -->
- <mapping resource="cn/itcast/vo/Book.hbm.xml" />
- </session-factory>
- </hibernate-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 必须去配置的属性 -->
<!-- 配置数据库连接的基本信息: -->
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql:///ssh1
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123</property>
<!-- Hibernate的方言 -->
<!-- 生成底层SQL不同的 -->
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<!-- 可选的属性 -->
<!-- 显示SQL -->
<property name="hibernate.show_sql">true</property>
<!-- 格式化SQL -->
<property name="hibernate.format_sql">true</property>
<property name="hibernate.connection.autocommit">false</property>
<!-- hbm:映射 to DDL: create drop alter -->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- C3P0连接池设定-->
<!-- 使用c3po连接池 配置连接池提供的供应商-->
<property name="connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</property>
<!--在连接池中可用的数据库连接的最少数目 -->
<property name="c3p0.min_size">5</property>
<!--在连接池中所有数据库连接的最大数目 -->
<property name="c3p0.max_size">20</property>
<!--设定数据库连接的过期时间,以秒为单位,
如果连接池中的某个数据库连接处于空闲状态的时间超过了timeout时间,就会从连接池中清除 -->
<property name="c3p0.timeout">120</property>
<!--每3000秒检查所有连接池中的空闲连接 以秒为单位-->
<property name="c3p0.idle_test_period">3000</property>
<!-- 通知Hibernate加载那些映射文件 -->
<mapping resource="cn/itcast/vo/Book.hbm.xml" />
</session-factory>
</hibernate-configuration>
映射:
格式:类名.hbm.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
- <hibernate-mapping>
- <class name="com.sihai.vo.Book" table="book">
- <id name="id">
- <generator class="native"/>
- </id>
- <property name="name"/>
- <property name="price"/>
- </class>
- </hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.sihai.vo.Book" table="book">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="price"/>
</class>
</hibernate-mapping>
3 Struts2和Spring的整合
3.1.新建包结构:
com.sihia.action
com.sihia.service
com.sihia.dao
com.sihia.vo
3.2创建实体类:
Book
- package com.sihia.vo;
- public class Book {
- private Integer id;
- private String name;
- private Double price;
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public Double getPrice() {
- return price;
- }
- public void setPrice(Double price) {
- this.price = price;
- }
- }
package com.sihia.vo;
public class Book {
private Integer id;
private String name;
private Double price;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
}
3.3.新建一个jsp页面:
addBook.jsp
- <s:form action="book_add" namespace="/" method="post" theme="simple">
- 图书名称:<s:textfield name="name"/><br/>
- 图书价格:<s:textfield name="price"/><br/>
- <s:submit value="添加图书"/>
- </s:form>
<s:form action="book_add" namespace="/" method="post" theme="simple">
图书名称:<s:textfield name="name"/><br/>
图书价格:<s:textfield name="price"/><br/>
<s:submit value="添加图书"/>
</s:form>
3.4.编写Action:
- public class BookAction extends ActionSupport implements ModelDriven<Book>{
- // 模型驱动类
- private Book book = new Book();
- public Book getModel() {
- return book;
- }
- // 处理请求的方法:
- public String add(){
- System.out.println("web层的添加执行了...");
- return NONE;
- }
- }
public class BookAction extends ActionSupport implements ModelDriven<Book>{
// 模型驱动类
private Book book = new Book();
public Book getModel() {
return book;
}
// 处理请求的方法:
public String add(){
System.out.println("web层的添加执行了...");
return NONE;
}
}
3.5.配置struts.xml
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
- "http://struts.apache.org/dtds/struts-2.3.dtd">
- <struts>
- <constant name="struts.devMode" value="true" />
- <package name="default" namespace="/" extends="struts-default">
- <action name="book_*" class="bookAction" method="{1}">
- </action>
- </package>
- </struts>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<action name="book_*" class="bookAction" method="{1}">
</action>
</package>
</struts>
4 Struts2和Spring的整合两种方式
4.1 Struts2自己管理Action:(方式一)
- <action name="book_*" class="com.sihia.action.BookAction" method="{1}">
<action name="book_*" class="com.sihia.action.BookAction" method="{1}">
4.2 Action交给Spring管理:(方式二)
可以在<action>标签上通过一个伪类名方式进行配置:
- <action name="book_*" class="bookAction" method="{1}"></action>
<action name="book_*" class="bookAction" method="{1}"></action>
在spring的配置文件中:
- <!-- 配置Action -->
- <bean id="bookAction" class="com.sihai.action.BookAction"></bean>
<!-- 配置Action -->
<bean id="bookAction" class="com.sihai.action.BookAction"></bean>
注意:Action交给Spring管理一定要配置scope=”prototype”
4.3 Web层获得Service:
传统方式:
* 获得WebApplicationContext对象.
* 通过WebAppolicationContext中getBean(“”);
实际开发中:
* 引入了struts2-spring-plugin-2.3.15.3.jar
* 有一个配置文件 : struts-plugin.xml
开启常量 :
<constant name="struts.objectFactory" value="spring" />
引发另一个常量的执行:(Spring的工厂类按照名称自动注入)
struts.objectFactory.spring.autoWire = name
5 Spring整合Hibernate:
Spring整合Hibernate框架的时候有两种方式:
5.1 零障碍整合:(一)
可以在Spring中引入Hibernate的配置文件.
1.通过LocalSessionFactoryBean在spring中直接引用hibernate配置文件
- <!-- 零障碍整合 在spring配置文件中引入hibernate的配置文件 -->
- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
- </bean>
<!-- 零障碍整合 在spring配置文件中引入hibernate的配置文件 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
</bean>
2.Spring提供了Hibernate的模板.只需要将HibernateTemplate模板注入给DAO.
DAO继承HibernateDaoSupport.
- <!-- DAO的配置 -->
- <bean id="bookDao" class="com.sihai.dao.BookDao">
- <property name="sessionFactory" ref="sessionFactory"/>
- </bean>
<!-- DAO的配置 -->
<bean id="bookDao" class="com.sihai.dao.BookDao">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
改写DAO:继承HibernateDaoSupport类.
- public class BookDao extends HibernateDaoSupport{
- public void save(Book book) {
- System.out.println("DAO层的保存图书...");
- this.getHibernateTemplate().save(book);
- }
- }
public class BookDao extends HibernateDaoSupport{
public void save(Book book) {
System.out.println("DAO层的保存图书...");
this.getHibernateTemplate().save(book);
}
}
3.创建一个映射文件 :
- <hibernate-mapping>
- <class name="com.sihai.vo.Book" table="book">
- <id name="id">
- <generator class="native"/>
- </id>
- <property name="name"/>
- <property name="price"/>
- </class>
- </hibernate-mapping>
<hibernate-mapping>
<class name="com.sihai.vo.Book" table="book">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="price"/>
</class>
</hibernate-mapping>
4.别忘记事务管理:
事务管理器:
- <!-- 管理事务 -->
- <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
- <property name="sessionFactory" ref="sessionFactory"/>
- </bean>
<!-- 管理事务 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
5.注解管理事务:
- <!-- 注解开启事务 -->
- <tx:annotation-driven transaction-manager="transactionManager"/>
<!-- 注解开启事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
6.在业务层类上添加一个注解:
@Transactional
5.2 没有Hibernate配置文件的形式(二)
不需要Hibernate配置文件的方式,将Hibernate配置文件的信息直接配置到Spring中.
Hibernate配置文件中的信息 :
* 连接数据库基本参数:
* Hibernate常用属性:
* 连接池:
* 映射:
把Hibernate配置文件整合Spring中:
连接池:
- <!-- 引入外部属性文件. -->
- <context:property-placeholder location="classpath:jdbc.properties"/>
- <!-- 配置c3p0连接池 -->
- <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
- <property name="driverClass" value="${jdbc.driver}"/>
- <property name="jdbcUrl" value="${jdbc.url}"/>
- <property name="user" value="${jdbc.user}"/>
- <property name="password" value="${jdbc.password}"/>
- </bean>
<!-- 引入外部属性文件. -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置c3p0连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
Hibernate常用属性:
- <!-- 配置Hibernate的属性 -->
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
- <prop key="hibernate.show_sql">true</prop>
- <prop key="hibernate.format_sql">true</prop>
- <prop key="hibernate.hbm2ddl.auto">update</prop>
- <prop key="hibernate.connection.autocommit">false</prop>
- </props>
- </property>
<!-- 配置Hibernate的属性 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.connection.autocommit">false</prop>
</props>
</property>
映射
- <!-- <property name="mappingResources">
- <list>
- <value>cn/itcast/vo/Book.hbm.xml</value>
- </list>
- </property> -->
- <property name="mappingDirectoryLocations">
- <list>
- <value>classpath:cn/itcast/vo</value>
- </list>
- </property>
<!-- <property name="mappingResources">
<list>
<value>cn/itcast/vo/Book.hbm.xml</value>
</list>
</property> -->
<property name="mappingDirectoryLocations">
<list>
<value>classpath:cn/itcast/vo</value>
</list>
</property>
6 HibernateTemplate的API:
Serializable save(Object entity) :保存数据
void update(Object entity) :修改数据
void delete(Object entity) :删除数据
<T> T get(Class<T> entityClass, Serializable id) :根据ID进行检索.立即检索
<T> T load(Class<T> entityClass, Serializable id) :根据ID进行检索.延迟检索.
List find(String queryString, Object... values) :支持HQL查询.直接返回List集合.
List findByCriteria(DetachedCriteria criteria) :离线条件查询.
List findByNamedQuery(String queryName, Object... values):命名查询的方式.
-
顶
- 2
-
踩
- 0