博客
关于我
maven整合Struts2-Spring-Hibernate
阅读量:378 次
发布时间:2019-03-05

本文共 6255 字,大约阅读时间需要 20 分钟。

配置文件

pom.xml

4.0.0
com.sram
MavenAndSSH
0.0.1-SNAPSHOT
war
4.2.4.RELEASE
5.0.7.Final
2.3.24
org.springframework
spring-context
${spring.version}
org.springframework
spring-aspects
${spring.version}
org.springframework
spring-orm
${spring.version}
org.springframework
spring-test
${spring.version}
org.springframework
spring-web
${spring.version}
org.hibernate
hibernate-core
${hibernate.version}
org.apache.struts
struts2-core
${struts.version}
org.apache.struts
struts2-spring-plugin
${struts.version}
org.springframework
spring-context
org.springframework
spring-aspects
org.springframework
spring-orm
org.springframework
spring-test
org.springframework
spring-web
org.hibernate
hibernate-core
mysql
mysql-connector-java
5.1.6
runtime
c3p0
c3p0
0.9.1.2
org.apache.struts
struts2-core
org.apache.struts
struts2-spring-plugin
javax.servlet
servlet-api
2.5
provided
javax.servlet
jsp-api
2.0
provided
org.slf4j
slf4j-log4j12
1.7.2
junit
junit
4.9
test
javax.servlet
jstl
1.2
com.alibaba
fastjson
1.1.15
org.apache.commons
commons-lang3
3.4
org.apache.maven.plugins
maven-compiler-plugin
1.7
1.7
UTF-8

web.xml

MavenAndSSH
index.html
struts
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts
/*
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:applicationContext.xml

struts.xml

/index.jsp

applicationContext.xml

hibernate.cfg.xml

org.hibernate.dialect.MySQL5Dialect
true
true
update

Customer.hbm.xml实体类的配置文件,通过配置方式

db.properties

jdbc.driverClass = com.mysql.jdbc.Driverjdbc.jdbcUrl=jdbc:mysql://localhost:3306/mavenjdbc.user=rootjdbc.password=root

代码

action中的代码

public class CustomerAction extends ActionSupport {	//action中因为在配置文件中注入了service层的对象,所以在这儿可以引用,但是需要天机set方法	private CustomerService customerService;	public void setCustomerService(CustomerService customerService) {		this.customerService = customerService;	}			//前台传入的请求参数保存到值栈中,,在这儿可以获取	private String custId;	public void setCustId(String custId) {		this.custId = custId;	}	//根据主键查询	public String findOne() throws Exception {		Customer customer = customerService.findOne(custId);		ActionContext.getContext().getValueStack().push(customer);		return SUCCESS;	}	}

service层的代码

public class CustomerServiceImpl implements CustomerService {	private CustomerDao customerDao;	public void setCustomerDao(CustomerDao customerDao) {		this.customerDao = customerDao;	}	public Customer findOne(String custId) {		return customerDao.findOne(custId);	}}

DAO层的代码

//继承HibernateDaoSupport public class CustomerDaoImpl extends HibernateDaoSupport implements CustomerDao {	public Customer findOne(String custId) {		return this.getHibernateTemplate().get(Customer.class, custId);	}	}

转载地址:http://lsrg.baihongyu.com/

你可能感兴趣的文章
MySQL 精选 60 道面试题(含答案)
查看>>
mysql 索引
查看>>
MySQL 索引失效的 15 种场景!
查看>>
MySQL 索引深入解析及优化策略
查看>>
MySQL 索引的面试题总结
查看>>
mysql 索引类型以及创建
查看>>
MySQL 索引连环问题,你能答对几个?
查看>>
Mysql 索引问题集锦
查看>>
Mysql 纵表转换为横表
查看>>
mysql 编译安装 window篇
查看>>
mysql 网络目录_联机目录数据库
查看>>
MySQL 聚簇索引&&二级索引&&辅助索引
查看>>
Mysql 脏页 脏读 脏数据
查看>>
mysql 自增id和UUID做主键性能分析,及最优方案
查看>>
Mysql 自定义函数
查看>>
mysql 行转列 列转行
查看>>
Mysql 表分区
查看>>
mysql 表的操作
查看>>
mysql 视图,视图更新删除
查看>>
MySQL 触发器
查看>>