3つの統合フレームワークテンプレートのssh

 

1.web.xml設定

 


<! - -ウェブと春のスタートをしようとリスナーを作成します>
<聞き手> <リスナークラス> org.springframework.web.context.ContextLoaderListener </リスナクラス> </リスナー> <! -設定春> -プロファイルの場所パラメータの<context-param>のの<param-name>のcontextConfigLocation </ PARAM名> applicationContext.xmlを</ PARAM値>:の<param-value>のCLASSPATH </コンテキスト-param>の<! -セッションスコープの拡大注:任意のフィルタは、フィルタストラットの前に呼び出す必要があります   - >   <フィルタ> <フィルタ名> OpenSessionInView </フィルタ名> <フィルタクラス> org.springframework.orm.hibernate5.support.OpenSessionInViewFilter </フィルタクラス> </フィルタ> <!- Struts2のコアフィルター- > <フィルタ> <フィルタ名> Struts2の</フィルタ名>

















<フィルタクラス> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </フィルタクラス>
</フィルタ> <フィルタマッピング> <フィルタ名> openSessionInView </フィルタ名> <URLパターン> / * </のurl-pattern> </のfilter-mapping> <のfilter-mapping> <フィルタ名> Struts2の</フィルタ名> の<url-pattern> / * </のurl-pattern> </フィルタマッピング>








2.db.properties設定


jdbc.jdbcUrl = JDBC:mysqlの:?///データベース名= UTF-8 characterEncoding
jdbc.driverClass =はcom.mysql.jdbc.Driver
jdbc.user =ユーザ名
jdbc.password =パスワード

3.struts.xml設定


<?xml version = "1.0"エンコード= "UTF-8"?>
<DOCTYPEストラットPUBLIC!
" - // Apache Software Foundationの// DTD Strutsの設定2.3 // EN"
「http://struts.apache.org/ DTD /ストラット-2.3.dtd ">

 


<Strutsの>
<! - #struts.objectFactory =春 のコンテナを作成するために、スプリングの作用struts.objectFactory.spring.autoWire =名前バネは、アセンブリの依存アクションのプロパティのために責任がある- > <定数名=「struts.objectFactory」値= "春"> </定数>


 


<パッケージ名= "ユーザー"の名前空間= "/"拡張= "ストラット-デフォルト"> <インターセプター> <! -注册拦截器- > <迎撃名= "privilegeInterceptor"クラス= "CN /時間/ウェブ/インターセプター/ PrivilegeInterceptor "> </インターセプタ> <! -配置拦截器栈- > <インターセプタスタック名=" myStack "> <インターセプター-refの名前=" privilegeInterceptor "> ます。<param name =" excludeMethods ">ログイン、 </ param>の登録</インターセプター-ref>を<インターセプター-refの名前= "defaultStack"> </インターセプター-ref>を</インターセプタースタック> </インターセプタ> <! -指定默认拦截器栈- > <デフォルト・インターセプタ-refの名前= "myStack"> </デフォルト・インターセプター-REF>














 


<! -全局结果集配置- >
<グローバル・結果> <結果名= "toLogin"タイプ= "リダイレクト"> /login.jsp </結果> </グローバル-結果>

 

    <グローバル例外マッピング>  <例外マッピング結果=「エラー」例外=「java.lang.RuntimeException」> </例外マッピング> </グローバル例外マッピング>

 

    <アクション名= "アクション・クラスの名前_ *"クラス= "スプリング注釈名称" METHOD = "{}。1"> </アクション> </パッケージ>



</ストラット>

4.applicationContext.xml構成


<xmlのバージョン= "1.0"エンコード= "UTF-8"?>
<豆のxmlns:XSI = "http://www.w3.org/2001/XMLSchema-instance" のxmlns = "のhttp://www.springframework .ORG /スキーマ/豆" のxmlns:コンテキスト= "http://www.springframework.org/schema/context" のxmlns:AOP = "http://www.springframework.org/schema/aop" のxmlns:TX =" http://www.springframework.org/schema/tx " XSI:のschemaLocation =" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans- 4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd







http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd「>

 

< -读取db.properties文件! - > 
<文脈:プロパティプレースホルダ位置= "クラスパスdb.properties" /> <! -开启扫描类中的注解- > <文脈:コンポーネント・スキャンベースパッケージ= "cn.hr"> </コンテキスト:コンポーネント・スキャン> <! -配置C3P0连接池- > <Bean名= "データソース"クラス= "com.mchange.v2.c3p0.ComboPooledDataSource"> <プロパティ名= "jdbcUrlと"値= "$ {jdbc.jdbcUrl}"> </ property>の<プロパティ名= "driverClass"値= "$ {jdbc.driverClass}"> </ property>の<プロパティ名=「ユーザ"値=" $ {jdbc.user}」> </ property>の<プロパティ名= "パスワード"値= "$ {jdbc.password}"> </プロパティ></豆> <! -コアトランザクションマネージャ- > <Bean名= "のTransactionManager"クラス= "org.springframework.orm.hibernate5.HibernateTransactionManager">













<プロパティ名= "SessionFactoryの" REF = "SessionFactoryの"> </ property>の
</豆> <TX:注釈駆動型トランザクション・マネージャ= "のTransactionManager" /> <Bean名= "SessionFactoryの"クラス= "ORG。 springframework.orm.hibernate5.LocalSessionFactoryBean」> <プロパティ名= "データソース" REF = "データソース"> </ property>の<プロパティ名= "hibernateProperties"> <小道具> <小道具キー= "hibernate.dialect"> org.hibernate .dialect.MySQLDialect </小道具> <! -可选配置- > <小道具キー= "hibernate.show_sql">真</小道具> <小道具キー= "hibernate.format_sql">真</小道具> <小道具キー= "hibernate.hbm2ddl.auto">更新</小道具> </小道具> </プロパティ> <! -自動的に次のドメインエンティティクラスの.hbm.xmlファイルをスキャンします- >















<プロパティ名= "mappingDirectoryLocations"値= "クラスパス:CN /時間/ドメイン"> </ property>の
</豆>

</豆>

基本的な構成と書き込み層5.dao

@Repository(「属性名DAO注入層」)
実装インターフェイスはHibernateDaoSupportが実装名{延びているクラスのパブリッククラス名
//固定フォーマット
@Resource(名=「のSessionFactory」)
公共ボイドsetSF(SessionFactoryのSF){ super.setSessionFactory(SF) ; } }



そして、筆記層は、実質的に配置された6.serviceです

@Service(「サービス属性名注入層」)
//セット次のプロパティが読み取り専用の場合は、読み取り専用ではなく、偽の方法への真のために
@Transactional(= Isolation.REPEATABLE_READ分離、伝播= Propagation.REQUIRED、読み取り専用=真)に
パブリッククラスが実装するインターフェースの実装クラス名name {
@Resource(名= "属性名DAO注入層")
プライベートStartPageDao SPD;
}

そして、筆記層は、実質的に配置された7.actionです

@Scope(「プロトタイプ」)
//が複数の実施例セットアップ
@Controller(「action属性名注入層」)を
パブリッククラスの実装クラス名{ActionSupport延び
@Resource(名=「属性名サービス注入層」)
プライベートStartPageServiceのstartpageserviceと、
// AJAXの送信フロントエンド供給方法設け
パブリック文字列インデックス()例外{スロー// 1層サービスアクセス方式リスト<スタートページ> SP =(一覧<スタートページ>)startpageservice.findStartImage(); // 2データは、フロントエンドに返さ; Gson GSON新しい新しいGson =()文字列= gson.toJson JSON(SP)。ServletActionContext.getResponse()に、setContentType( "ファイルアプリケーション/ JSON;のcharset = UTF-8"); ServletActionContext.getResponse( 。).getWriter()ライト(JSON); 戻りNULL; } }










おすすめ

転載: www.cnblogs.com/hr716/p/12081846.html