一 ssh框架知识点回顾
1-1. Hibernate(持久层)
持久层封装与数据库相关的操作
示例:
public class BookDao
{
public void save(Book book){
//创建配置对象
Configuration config = new Configuration().configure();
//创建服务注册对象
ServiceRegistry serviceRegistry =
new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
//创建sessionFactory
SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
//创建session对象,使用getCurrentSession无需显示的关闭对象
Session session = sessionFactory.openSession();
//创建事务对象
Transaction tx = session.beginTransaction();
session.save(book);
tx.commit();
session.close();
}
}
1-2. Spring(业务层)
业务层实现具体的业务逻辑,接收用户请求调用相应的持久层代码实现业务需求。
示例:
public class BookService
{
//持久层定义的类,封装对数据库的相关操作
private BookDao bookDao;
//Spring通过setter方法进行IOC注入
public void setBookDao(BookDao bookDao){
this.bookDao = bookDao;
}
public void save(){
bookDao.save(book);
}
}
xml配置文件
...
<bean id="bookDao" class="packagename.BookDao"></bean>
<bean id="bookService" class="packagename.BookService">
<property name="bookDao" ref="bookDao" />
</bean>
...
1-3. web层(Struts2)
示例:
public class BookAction extends ActionSupport implements ModelDriven<Book>
//实现ModelDriven接口,是使用驱动模型的方式传递数据
{
private Book book = new book();
public Book getModel(){
//使用模型驱动的方式
return book;
}
//调用spring的业务层代码,若Struts2整合了spring则无需这么复杂
public String save(){
XebApplicationContext wap = WebApplicationContextUtils.getWebApplicationContext(...);
BookService bs = wap.getBean("bookService");
bs.save();
}
}
二 ssh框架的相应jar包
https://yunpan.cn/ckj3tzYqfjB2W 访问密码 5871
2-1. Struts2的基本jar包
- 下载Struts2的资源包,在其apps目录下有一个Struts2-blank.war的工程压缩包,使用解压工具打开,在其WEB-INF>lib文件夹下的jar包就是Struts2开发所需的基本jar包。
- 了解在Struts2的lib目录下的其他jar包
- struts2-convention-plugin.jar是struts2的注解开发jar包。
- struts2-spring-plugin.jar是struts2用于整合spring的jar包。
2-2. hibernate需要的jar包
- hibernate根目录下的hibernate.jar
- hibernate/lib/required文件夹下的所有jar包
- hibernate/lib/jpa文件夹下的所有jar包。注:JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中。
- 日志记录:slf4j的jar包整合log4j的jar包。hibernate的request文件夹下只有slf4j的jar包。log4j的jar包可在引入spring所需jar包时引入
- 数据库驱动包JDBC
2-3. spring所需jar包
- spring的基本开发需要引入其libs文件夹下的一下jar包
- spring-beans.jar
- spring-context.jar
- spring-core.jar
- spring-expression.jar
- 引入spring日志记录相应的包,在spring-framework-dependencies依赖库文件夹下。
- org.apache.log4j/com.springsource.org.apache.log4j/x.x.xx文件夹下的jar包
- 进行日志整合的jar包(不进行具体的日志记录):在dependencies依赖库文件夹下的org.apache.commons/com.springsource.org.apache.commons.logging文件夹下的jar包。
- springAOP需要引入的jar包
- 在spring的libs文件夹下的spring-aop.jar
- 在spring的libs文件夹下的spring-aspects.jar(整合aspectJ的包)
- 引入aop联盟额一些操作:dependencies依赖库文件夹下的org.aopalliance/xxxx/xxx文件夹下的jar包
- aspectJ的包:dependencies依赖库文件夹下的org.aspectj/com.springsource.org.asprctj.weaver/x.x.x文件夹下的jar包
- spring的libs目录下的一些整合包:
- 事务管理的包:spring-tx.jar
- jdbc模板的包:spring-jdbc.jar
- 整合hibernate的包:spring-orm.jar
- 整合web项目:spring-web.jar
- 整合Junit单元测试:spring-text.jar
- 整合Struts的包:spring-struts.jar(以在引入Struts2所需包时引入了Struts2整合spring的包,所以无需再引入此包)
- 如果想使用连接池的话导入连接池的jar包。在spring的dependencies依赖库文件夹下com.mchange.c3p0/xxx/xxx文件夹下的jar包
- 下载slf4j的开发包,在其解压缩文件夹中找到slf4j-log4j.jar(slf4j整合log4j)
2-4. 各种jar包的maven依赖坐标
<dependencys>
<dependency><groupId>org.lucee</groupId><artifactId>antlr</artifactId><version>2.7.6</version></dependency>
<dependency><groupId>asm</groupId><artifactId>asm</artifactId><version>3.3</version></dependency>
<dependency><groupId>asm</groupId><artifactId>asm-commons</artifactId><version>3.3</version></dependency>
<dependency><groupId>asm</groupId><artifactId>asm-tree</artifactId><version>3.3</version></dependency>
<dependency><groupId>not find</groupId><artifactId>com.springsource.com.mchange.v2.c3p0</artifactId><version>0.9.1.2</version></dependency>
<dependency><groupId>not find</groupId><artifactId>com.springsource.org.aopalliance</artifactId><version>1.0.0</version></dependency>
<dependency><groupId>not find</groupId><artifactId>com.springsource.org.apache.commons.logging</artifactId><version>1.1.1</version></dependency>
<dependency><groupId>not find</groupId><artifactId>com.springsource.org.apache.log4j</artifactId><version>1.2.15</version></dependency>
<dependency><groupId>not find</groupId><artifactId>com.springsource.org.aspectj.weaver</artifactId><version>1.6.8.RELEASE</version></dependency>
<dependency><groupId>commons-collections</groupId><artifactId>commons-collections</artifactId><version>3.1</version></dependency>
<dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.2.2</version></dependency>
<dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.0.1</version></dependency>
<dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.1</version></dependency>
<dependency><groupId>org.lucee</groupId><artifactId>commons-logging</artifactId><version>1.1.1</version></dependency>
<dependency><groupId>org.lucee</groupId><artifactId>dom4j</artifactId><version>1.6.1</version></dependency>
<dependency><groupId>org.freemarker</groupId><artifactId>freemarker</artifactId><version>2.3.19</version></dependency>
<dependency><groupId>not find</groupId><artifactId>hibernate-jpa-api</artifactId><version>2.0-1.0.0.Final</version>
</dependency><dependency><groupId>not find</groupId><artifactId>hibernate3</artifactId><version></version></dependency>
<dependency><groupId>javassist</groupId><artifactId>javassist</artifactId><version>3.11.0.GA</version></dependency>
<dependency><groupId>javassist</groupId><artifactId>javassist</artifactId><version>3.12.0.GA</version></dependency>
<dependency><groupId>org.atteo.moonshine</groupId><artifactId>jta</artifactId><version>1.1</version></dependency>
<dependency><groupId>ognl</groupId><artifactId>ognl</artifactId><version>3.0.6</version></dependency>
<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>1.6.1</version></dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>4.0.0.RELEASE</version></dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-aspects</artifactId><version>4.0.0.RELEASE</version></dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>4.0.0.RELEASE</version></dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.0.0.RELEASE</version></dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>4.0.0.RELEASE</version></dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-expression</artifactId><version>4.0.0.RELEASE</version></dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>4.0.0.RELEASE</version></dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-orm</artifactId><version>4.0.0.RELEASE</version></dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>4.0.0.RELEASE</version></dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>4.0.0.RELEASE</version></dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>4.0.0.RELEASE</version></dependency>
<dependency><groupId>org.apache.struts</groupId><artifactId>struts2-core</artifactId><version>2.3.12</version></dependency>
<dependency><groupId>org.apache.struts</groupId><artifactId>struts2-spring-plugin</artifactId><version>2.3.12</version></dependency>
<dependency><groupId>org.apache.struts.xwork</groupId><artifactId>xwork-core</artifactId><version>2.3.12</version></dependency>
</dependencys>