博客
关于我
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、HBase 和 Elasticsearch:特点与区别详解
查看>>
MySQL、Redis高频面试题汇总
查看>>
MYSQL、SQL Server、Oracle数据库排序空值null问题及其解决办法
查看>>
mysql一个字段为空时使用另一个字段排序
查看>>
MySQL一个表A中多个字段关联了表B的ID,如何关联查询?
查看>>
MYSQL一直显示正在启动
查看>>
MySQL一站到底!华为首发MySQL进阶宝典,基础+优化+源码+架构+实战五飞
查看>>
MySQL万字总结!超详细!
查看>>
Mysql下载以及安装(新手入门,超详细)
查看>>
MySQL不会性能调优?看看这份清华架构师编写的MySQL性能优化手册吧
查看>>
MySQL不同字符集及排序规则详解:业务场景下的最佳选
查看>>
Mysql不同官方版本对比
查看>>
MySQL与Informix数据库中的同义表创建:深入解析与比较
查看>>
mysql与mem_细说 MySQL 之 MEM_ROOT
查看>>
MySQL与Oracle的数据迁移注意事项,另附转换工具链接
查看>>
mysql丢失更新问题
查看>>
MySQL两千万数据优化&迁移
查看>>
MySql中 delimiter 详解
查看>>
MYSQL中 find_in_set() 函数用法详解
查看>>
MySQL中auto_increment有什么作用?(IT枫斗者)
查看>>