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

你可能感兴趣的文章
SharePoint 2013 图文开发系列之定义站点模板
查看>>
PCI Express学习篇:Power Management(二)
查看>>
pcie握手机制_【博文连载】PCIe扫盲——Ack/Nak 机制详解(一)
查看>>
PC史上最悲剧的16次失败
查看>>
PC端恶意代码分析Lab1.1-5.1,从零基础到精通,收藏这篇就够了!
查看>>
PC端编辑 但能在PC端模拟移动端预览的富文本编辑器
查看>>
PDB文件:每个开发人员都必须知道的
查看>>
springMVC学习(二)
查看>>
PDF中的Pandoc语法突出显示不起作用
查看>>
pdf从结构新建书签_在PDF文件中怎样创建书签
查看>>
pdf做成翻页电子书_第一弹:常见BOOX电子书阅读器问题解答,这些技能你都会吗?...
查看>>
PDF文字识/编辑?这个工具真的很强大!
查看>>
pdf文档出现乱码如何修改
查看>>
pdf根据模板导出
查看>>
PDF调出本来存在的书签面板
查看>>
pdf转图片、提取pdf文本、提取pdf图片
查看>>
pdo sqlserver
查看>>
PDO中捕获SQL语句中的错误
查看>>
peek和pop的区别
查看>>
Penetration Testing、Security Testing、Automation Testing
查看>>