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

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

Maven项目配置与代码解析

项目概述

本文将详细介绍一个基于Maven的Spring+Struts项目的配置文件及代码实现。该项目主要涉及前端Struts框架、后端Spring框架以及数据库的配置管理。


pom.xml:项目依赖与版本管理

项目的核心配置文件是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}
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:Web应用配置

web.xml文件主要负责配置Web应用的过滤器、上下文参数以及Struts的核心过滤器。

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

struts.xml:Struts配置

struts.xml文件定义了项目的Struts配置,包括包名、动作等。

/index.jsp

applicationContext.xml:Spring应用上下文配置

applicationContext.xml文件配置了Spring的应用上下文,包括数据源、事务管理等。


hibernate.cfg.xml:Hibernate配置

hibernate.cfg.xml文件配置了Hibernate的连接信息、事务管理等。

org.hibernate.dialect.MySQL5Dialect
true
true
update

Customer.hbm.xml:实体类映射文件

Customer.hbm.xml文件定义了Customer实体类的数据库映射。


db.properties:数据库连接配置

db.properties文件配置了数据库的连接信息。

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

代码解析

action层代码

public class CustomerAction extends ActionSupport {    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层代码

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

总结

以上就是本项目的主要配置文件及代码实现。通过合理配置项目依赖、数据库连接以及应用上下文,确保了项目的稳定运行和高效管理。

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

你可能感兴趣的文章
Objective-C实现hanoiTower汉诺塔算法(附完整源码)
查看>>
Objective-C实现hardy ramanujana定理算法(附完整源码)
查看>>
Objective-C实现harmonic series调和级数算法(附完整源码)
查看>>
Objective-C实现harris算法(附完整源码)
查看>>
Objective-C实现HashTable哈希表算法(附完整源码)
查看>>
Objective-C实现haversine distance斜距算法(附完整源码)
查看>>
Objective-C实现heap sort堆排序算法(附完整源码)
查看>>
Objective-C实现heaps algorithm堆算法(附完整源码)
查看>>
Objective-C实现heap堆算法(附完整源码)
查看>>
Objective-C实现Heap堆算法(附完整源码)
查看>>
Objective-C实现hexagonal numbers六边形数算法(附完整源码)
查看>>
Objective-C实现hidden layers neural network浅层神经网络算法(附完整源码)
查看>>
Objective-C实现highest response ratio next高响应比优先调度算法(附完整源码)
查看>>
Objective-C实现hill climbing爬山法用来寻找函数的最大值算法(附完整源码)
查看>>
Objective-C实现Hill密码加解密算法(附完整源码)
查看>>
Objective-C实现histogram stretch直方图拉伸算法(附完整源码)
查看>>
Objective-C实现Hopcroft算法(附完整源码)
查看>>
Objective-C实现horizontal projectile motion平抛运动算法(附完整源码)
查看>>
Objective-C实现hornerMethod霍纳法算法(附完整源码)
查看>>
Objective-C实现Horn–Schunck光流算法(附完整源码)
查看>>