本文提供Struts2整合Spring Hibernate的CRUD的实例的源代码
1. 数据库脚本,数据库采用MySQL 5.0
|
CREATE TABLE `user` ( `id` int(11) NOT NULL auto_increment, `username` varchar(32) NOT NULL, `password` varchar(32) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
2. 几个重要的文件
web.xml
|
xsi:schemaLocation="[url=http://java.sun.com/xml/ns/javaee]http://java.sun.com/xml/ns/javaee[/url] [url=http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd]http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd[/url]"> <!-- spring的应用上下文 --> <!-- struts2 过滤器 --> org.apache.struts2.dispatcher.FilterDispatcher <!-- spring的监听器,以便在启动时就自动加载spring的配置 --> org.springframework.web.context.ContextLoaderListener <!-- OpenSessionInViewFilter过滤器 --> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter |
applicationContext.xml
struts.xml
|
<!-- 此constant设置临时文件存放目录,因为默认的default.properties中没有指定 --> <!-- 将action托管给spring --> |
3. 本实例仅实现CRUD功能,没有实现其他的处理,如数据校验、国际化、分页等.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29870867/viewspace-1328545/ ,如需转载,请注明出处,否则将追究法律责任。