SSH整合注解版(Spring+Struts2+Hibernate)

整体架构:

 

 

pom.xml 引入maven节点:

 <dependencies><!--单测--><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.3</version><scope>test</scope></dependency><!--spring配置--><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.2.0.RELEASE</version></dependency><!--aop使用的jar--><dependency><groupId> org.aspectj</groupId ><artifactId> aspectjweaver</artifactId ><version> 1.8.7</version ></dependency><!--SpringWeb--><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>4.1.8.RELEASE</version></dependency><!--JavaEE--><dependency><groupId>javaee</groupId><artifactId>javaee-api</artifactId><version>5</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>jstl</artifactId><version>1.2</version><scope>runtime</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>4.2.5.RELEASE</version></dependency><!--c3p0--><dependency><groupId>com.mchange</groupId><artifactId>c3p0</artifactId><version>0.9.5.2</version></dependency><!--hibernate jar包--><!--jta的jar包--><dependency><groupId>javax.transaction</groupId><artifactId>jta</artifactId><version>1.1</version></dependency><dependency><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><version>5.0.6.Final</version></dependency><!--Spring-ORM--><dependency><groupId>org.springframework</groupId><artifactId>spring-orm</artifactId><version> 4.2.2.RELEASE</version></dependency><!--Oracle驱动的jar--><dependency><groupId>com.oracle</groupId><artifactId>ojdbc6</artifactId><version>11.2.0.1.0</version></dependency><!--struts2--><dependency><groupId>org.apache.struts</groupId><artifactId>struts2-core</artifactId><version>2.3.4.1</version></dependency><dependency><groupId>org.apache.struts.xwork</groupId><artifactId>xwork-core</artifactId><version>2.3.4.1 </version></dependency><!-- struts2整合spring --><dependency><groupId>org.apache.struts</groupId><artifactId>struts2-spring-plugin</artifactId><version>2.3.4.1</version></dependency><!-- struts注解核心包 --><dependency><groupId>org.apache.struts</groupId><artifactId>struts2-convention-plugin</artifactId><version>2.3.4.1</version></dependency></dependencies><build><resources><resource><directory>src/main/java</directory><includes><include>**/*.xml</include></includes></resource></resources></build>
</project>

  

bean层:

Dog:

@Entity
@Table(name = "Dog")
public class Dog {//ssh 注解版
@Id
@GeneratedValueprivate Integer did;
@Columnprivate String dname;
@Columnprivate Integer dage;public Integer getDid() {return did;}public void setDid(Integer did) {this.did = did;}public String getDname() {return dname;}public void setDname(String dname) {this.dname = dname;}public Integer getDage() {return dage;}public void setDage(Integer dage) {this.dage = dage;}
}

Dao层:
IDogDao:
 
public interface IDogDao {//添加部门public void addDog(Dog dog);}

  


IDogDaoImpl:
@Repository("IDogDao")
public class IDogDaoImpl implements IDogDao {
@Resource(name = "sessionFactory")private SessionFactory sessionFactory;public void addDog(Dog dog) {Session session = sessionFactory.getCurrentSession();session.save(dog);}public SessionFactory getSessionFactory() {return sessionFactory;}public void setSessionFactory(SessionFactory sessionFactory) {this.sessionFactory = sessionFactory;}
}

  

service层:

service:
public interface IDogServices {//添加部门public void addDog(Dog dog);
}

  



IDogServicesImpl:
@Service("IDogServices")
public class IDogServicesImpl implements IDogServices {
@Resource(name = "IDogDao")private IDogDao dao;@Transactionalpublic void addDog(Dog dog) {dao.addDog(dog);}public IDogDao getDao() {return dao;}public void setDao(IDogDao dao) {this.dao = dao;}
}

  

 


action层:
@Controller
@ParentPackage("struts-default")
@Namespace("/")
@Scope("prototype")//多例
public class DogAction extends ActionSupport {private Dog dog;@Resource(name = "IDogServices")private IDogServices dogServices;@Action(value = "/add",results = {@Result(name = "success",location = "/jsp/index.jsp")})public String addDog(){dogServices.addDog(dog);return SUCCESS;}public Dog getDog() {return dog;}public void setDog(Dog dog) {this.dog = dog;}public IDogServices getDogServices() {return dogServices;}public void setDogServices(IDogServices dogServices) {this.dogServices = dogServices;}
}

  

  

配置文件:

applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!--包扫描器-->
<context:component-scan base-package="cn.happy"></context:component-scan><!-- 配置数据源c3p0--><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="${jdbc.driverClassName}"></property><property name="jdbcUrl" value="${jdbc.url}"></property><property name="user" value="${jdbc.username}"></property><property name="password" value="${jdbc.password}"></property></bean>
<!--识别到jdbc.property--><context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder><!--SssionFactory --><bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"><property name="dataSource" ref="dataSource"></property><property name="hibernateProperties"><props><prop key="hibernate.show_sql">true</prop><prop key="format_sql">true</prop><prop key="dialect">org.hibernate.dialect.Oracle10gDialect</prop><!--和线程绑定的Session--><prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</prop></props></property><!--扫描小配置文件--><property name="packagesToScan" value="cn.happy.entity"></property></bean><!--事务管理器--><bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory"></property></bean><!--事务--><tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven></beans>

  

jdbc.properject:

jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@localhost:1521:orcl
jdbc.username=scott
jdbc.password=tiger

  


Web.xml:
<!DOCTYPE web-app PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app><!--上下文--><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><!--过滤器--><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><!--拦截所有方法--><url-pattern>/*</url-pattern></filter-mapping><!--监听器和--><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener></web-app>

  



login.jsp:
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false"pageEncoding="UTF-8"%>
<html>
<body>
<h2>你好,世界</h2>
<div><s:form action="/add" method="POST">请输入用户名:  <s:textfield name="dog.dname"></s:textfield></br>请输入密码:<s:password name="dog.dage"></s:password><s:submit value="添加"></s:submit></s:form></div></body>
</html>

  

  

 



 

 

转载于:https://www.cnblogs.com/zjl0202/p/8508896.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/281120.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

定时插座动一下就断_使用插座定时器在某些时候自动将您的Amazon Echo静音

定时插座动一下就断The Amazon Echo is an always-listening voice-controlled virtual assistant, but if there are times you’d rather not listen (or be listened to) by the Echo, here’s how to automatically mute it at certain times of the day. Amazon Echo是一个…

周末读书:《红楼梦》

【周末读书】| 作者/Edison大家好&#xff0c;我是Edison。古人曾说“开谈不说红楼梦&#xff0c;读尽诗书也枉然”&#xff0c;刚好最近我爸开始在阅读《红楼梦》&#xff0c;我想起当年看了两遍《红楼梦》原著和一遍87版《红楼梦》电视剧的场景。本文是我首发于2018年的一篇读…

onlyoffice启用HTTPS

原文同步自作者博客&#xff1a;https://www.daxueyiwu.com/post/765 HTTPS需要使用SSL证书&#xff0c;可以自己签发也可以用ca机构签发的&#xff0c;加密效果相同。 生成证书&#xff1a; 创建私钥 openssl genrsa -out onlyoffice.key 2048 创建CSR openssl req -new -k…

Oracle-逻辑体系结构

这里指数据文件的逻辑体系结构&#xff0c;包括1.表空间(TABLESPACE) 2.段(SEGMENT) 3.区(EXTENT) 4.块(BLOCK) 数据库(Database)由若干表空间(TABLESPACE)组成&#xff0c;表空间由若干段(SEGMENT)组成&#xff0c;段由若干区(EXTENT)组成&#xff0c;区由若干块(BLOCK)组成…

chromebook刷机_如何从Chromebook上的APK侧面加载Android应用

chromebook刷机Chromebooks can now download and install Android apps from Google Play, and it works pretty well. But not every Android app is available in Google Play. Some apps are available from outside Google Play as APK files, and you can install them o…

修改onlyoffice存储为手动存储关闭浏览器时不进行保存

原文同步自作者博客&#xff1a;https://www.daxueyiwu.com/post/704 相关官方API地址&#xff1a; 文件保存 回调处理程序 配置-编辑-定制-自动保存 配置-编辑-定制-forcesave 需要将: config.editorConfig.customization.forcesave改为true, 并且config.editorConfig.…

如何使用NVIDIA ShadowPlay录制PC游戏

NVIDIA’s ShadowPlay, now known as NVIDIA Share, offers easy gameplay recording, live streaming, and even an FPS counter overlay. It can automatically record gameplay in the background–just on the PlayStation 4 and Xbox One–or only record gameplay when y…

Java流

流分类 字节流字符流输入流InputStreamReader输出流OutputStream WriterInputStream:BufferedInputStream、DataInputStream、ObjectInputStreamOutputStream:BufferedOutputStream、DataOutputStream、ObjectOutputStream、PrintStream 标准流: System.in 、Syst…

Win7安装OnlyOffice(不使用Docker)

原文同步自作者博客&#xff1a;https://www.daxueyiwu.com/post/741 1、安装准备 &#xff08;1&#xff09;安装Elang&#xff1a; 【注意事项】 a)Elang是为了给RabbitMQ使用的&#xff0c;因此在安装Elang之前应确定RabbitMQ的版本及其所需的Elang版本。RabbitMQ的地址…

geek_享受How-To Geek用户样式脚本的好处

geekMost people may not be aware of it but there are two user style scripts that have been created just for use with the How-To Geek website. If you are curious then join us as we look at these two scripts at work. 大多数人可能不知道它&#xff0c;但是已经创…

Memcached 在linux上安装笔记

第一种yum 方式安装 Memcached 支持许多平台&#xff1a;Linux、FreeBSD、Solaris、Mac OS&#xff0c;也可以安装在Windows上。 第一步 Linux系统安装memcached&#xff0c;首先要先安装libevent库 Ubuntu/Debian sudo apt-get install libevent libevent-deve 自动下…

onlyoffice回调函数controller方式实现

原文同步自作者博客&#xff1a;https://www.daxueyiwu.com/post/706 springboot实现的onlyoffice协同编辑网盘项目可以去作者博客。 上代码&#xff1a; //新建报告GetMapping("report/createReport")public String CreatReport(HttpServletRequest request,Stri…

读Bilgin Ibryam 新作 《Dapr 是一种10倍数 平台》

Bilgin Ibryam 最近加入了开发者软件初创公司Diagrid Inc&#xff0c;他是Apache Software Foundation 的 committer 和成员。他也是一个开源的布道师&#xff0c;并且是书籍 Kubernetes设计模式 和 Camel Design Patterns 的作者。早在2020年初 提出的Multi-Runtime Microserv…

如何在iPhone或iPad上使用Safari下载文件

Khamosh PathakKhamosh PathakIn your work or personal life, you’ll sometimes need to download a file on your iPhone or iPad. Using the new feature introduced in iOS 13 and iPadOS 13, you can now do this directly in Safari. No third-party app needed! 在工作…

java版左右手桌面盯盘软件dstock V1.0

V1.0功能比较简陋&#xff0c;先满足自己桌面盯盘需要 V1.0 版本功能介绍&#xff1a; 1. 1s实时刷新盯盘数据 主要市面上的&#xff0c;符合我要求的桌面应用要VIP,穷啊&#xff0c;还是月月付&#xff0c;年年付&#xff0c;还是自己搞吧&#xff01; 2. 配置文件配置股票…

放大倍数超5万倍的Memcached DDoS反射攻击,怎么破?

欢迎大家前往腾讯云社区&#xff0c;获取更多腾讯海量技术实践干货哦~ 作者&#xff1a;腾讯游戏云 背景&#xff1a;Memcached攻击创造DDoS攻击流量纪录 近日&#xff0c;利用Memcached服务器实施反射DDoS攻击的事件呈大幅上升趋势。DDoS攻击流量首次过T&#xff0c;引发业界热…

C# WPF TabControl控件用法详解

概述TabControl我之前有讲过一节&#xff0c;内容详见&#xff1a;C# WPF TabControl用法指南(精品)&#xff0c;上节主要讲解了tabcontrol控件的左右翻页&#xff0c;以及页面筛选&#xff0c;以及数据绑定等内容&#xff0c;这节内容继续接续上节内容进行扩展讲解&#xff0c…

pixel 解锁_如何在Google Pixel 4和Pixel 4 XL上禁用面部解锁

pixel 解锁Justin Duino贾斯汀杜伊诺(Justin Duino)Face Unlock is one of the Google Pixel 4 and Pixel 4 XL’s flagship features. But if the facial recognition is a form of biometric security you’re uncomfortable with, you can delete your face data right off …

【实战】将多个不规则多级表头的工作表合并为一个规范的一维表数据结果表...

最近在项目里&#xff0c;有个临时的小需求&#xff0c;需要将一些行列交叉结构的表格进行汇总合并&#xff0c;转换成规范的一维表数据结构进行后续的分析使用。从一开始想到的使用VBA拼接字符串方式&#xff0c;完成PowerQuery的M语言查询字符串&#xff0c;然后转换成使用插…

happiness[国家集训队2011(吴确)]

【试题来源】 2011中国国家集训队命题答辩【问题描述】 高一一班的座位表是个n*m的矩阵&#xff0c;经过一个学期的相处&#xff0c;每个同学和前后左右相邻的同学互相成为了好朋友。这学期要分文理科了&#xff0c;每个同学对于选择文科与理科有着自己的喜悦值&#xff0c;而一…