博客
关于我
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与Oracle的数据迁移注意事项,另附转换工具链接
查看>>
mysql丢失更新问题
查看>>
MySQL两千万数据优化&迁移
查看>>
MySql中 delimiter 详解
查看>>
MYSQL中 find_in_set() 函数用法详解
查看>>
MySQL中auto_increment有什么作用?(IT枫斗者)
查看>>
MySQL中B+Tree索引原理
查看>>
mysql中cast() 和convert()的用法讲解
查看>>
mysql中datetime与timestamp类型有什么区别
查看>>
MySQL中DQL语言的执行顺序
查看>>
mysql中floor函数的作用是什么?
查看>>
MySQL中group by 与 order by 一起使用排序问题
查看>>
mysql中having的用法
查看>>
MySQL中interactive_timeout和wait_timeout的区别
查看>>
mysql中int、bigint、smallint 和 tinyint的区别、char和varchar的区别详细介绍
查看>>
mysql中json_extract的使用方法
查看>>
mysql中json_extract的使用方法
查看>>
mysql中kill掉所有锁表的进程
查看>>
mysql中like % %模糊查询
查看>>
MySql中mvcc学习记录
查看>>