博客
关于我
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/

你可能感兴趣的文章
POJ 2186:Popular Cows Tarjan模板题
查看>>
POJ 2229 Sumsets(递推,找规律)
查看>>
poj 2236
查看>>
POJ 2243 Knight Moves
查看>>
POJ 2262 Goldbach's Conjecture
查看>>
POJ 2362 Square DFS
查看>>
poj 2386 Lake Counting(BFS解法)
查看>>
poj 2387 最短路模板题
查看>>
POJ 2391 多源多汇拆点最大流 +flody+二分答案
查看>>
POJ 2403
查看>>
poj 2406 还是KMP的简单应用
查看>>
POJ 2431 Expedition 优先队列
查看>>
Qt笔记——获取位置信息的相关函数
查看>>
POJ 2484 A Funny Game(神题!)
查看>>
POJ 2486 树形dp
查看>>
POJ 2488:A Knight's Journey
查看>>
SpringBoot为什么易学难精?
查看>>
poj 2545 Hamming Problem
查看>>
poj 2723
查看>>
poj 2763 Housewife Wind
查看>>