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.pswp.cn/news/281120.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/281120.shtml
英文地址,請注明出處:http://en.pswp.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)組成…

win10下用docker安裝onlyoffice服務

原文同步自作者博客&#xff1a;https://www.daxueyiwu.com/post/699 1. 使用DockerToolbox安裝docker 1.1 DockerToolbox下載地址 DockerToolbox-19.03.1 GitHub上下載實在是太慢了。 我找了好久終于下載下來了&#xff0c;在這里分享一下&#xff01; 網盤下載&#xff1…

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…

速度和性能狂卷,.NET 7來了

.NET 作為一個免費的跨平臺開放源代碼開發人員平臺&#xff0c;這些年在不斷的升級完善。就在最近&#xff0c;史上最快最強的.net平臺.NET 7于2022年11月8日正式發布, .NET 朝著更好的???邁進了?步&#xff01;那么&#xff0c;.NET 7 有什么新東西&#xff1f;.NET 7 建立…

前端JavaScript規范

摘要&#xff1a; JavaScript規范 目錄 類型 對象 數組 字符串 函數 屬性 變量 條件表達式和等號 塊 注釋 空白 逗號 分號 類型轉換 命名約定 存取器 構造器 事件 模塊 jQuery ES5 兼容性 HTML、CSS、JavaScript分離 使用jsHint 前端工具 類型 原始值: 相當于傳值(JavaScript對…

修改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…

.Net 7 的 R2R,Crossgen2是什么?

楔子來下這些概念R22,Crossgen2這兩個東西&#xff0c;跟前面講的AOT和CLR有異曲同工之妙&#xff0c;到底什么呢&#xff1f;本篇來看下。R2RR2R(ReadyToRun),是一種結合了AOT和CLR編譯模式&#xff0c;取其優點&#xff0c;拋其缺點的一種編譯方式。具體的呢&#xff0c;R2R包…

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;但是已經創…

.NET Core統一參數校驗、異常處理、結果返回

我們開發接口時&#xff0c;一般都會涉及到參數校驗、異常處理、封裝結果返回等處理。如果每個后端開發在參數校驗、異常處理等都是各寫各的&#xff0c;沒有統一處理的話&#xff0c;代碼就不優雅&#xff0c;也不容易維護。所以&#xff0c;我們需要統一校驗參數&#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. 配置文件配置股票…