SSHフレーム統合-憧れコース


SSHフレーム統合-憧れコース
学習時間:2018年12月3日
慕課リンク:SSHに基づいて社員管理システムの枠組み整合編を実現する.
内容:Struts 2+Hiberg+Springフレームを統合し、Struts 2統合SpringとSpring統合Hiberg 2ステップに分けて行います.
ソース:Github:SSH_ベース
一、開発環境の構築
1.jarパッケージ導入
2.関連配置ファイルの導入
  • web.xml-->Struts 2フィルタ構成
    
          
              struts
              org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
          
          
              struts
              /*
         
  • struts 2.xml-->src
    >struts-2.3.36-all.zip\struts-2.3.36\apps\struts2-blank-2.3.36.war\WEB-INF\classes\struts2.xml
    
  • web.xml-->Springコアモニター
    > ContextLoaderListener--> ContextLoader --> 105:contextConfigLocation
    
      
               org.springframework.web.context.ContextLoaderListener
      
      
              contextConfigLocation
              classpath:applicationContext.xml
      
  • appication Contect.xml
  • 3.パッケージ構造とエンティティの作成
    
    -    :
        - com.ssh.action
        - com.ssh.dao-
        - com.ssh.domain -    product
        - com.ssh.service
    二、Struts 2統合Spring
    1.ページの作成
  • struts 2タグレイアウトページを使用して
  • 2.アクション、サービス、Daoなどを書く
  • comp.ssh.action
    Production//商品管理のアクション
    public class ProductAction extends ActionSupport implements ModelDriven{
        //^extends ActionSupport implements ModelDriven (       )
        //        
        private Product product = new Product();
        @Override
        public Product getModel() {
            // TODO Auto-generated method stub
            return product;
        }
        /*  Service  struts2-spring-plugin-2.3.36.jar > struts-plugin.xml > struts.objectFactory
                >struts.objectFactory.spring.autoWire = name     */    
        /*Struts  Spring                  */
        private ProductService productService;
    
        public void setProductService(ProductService productService) {
            this.productService = productService;
        }
    }
  • comp.ssh.dao
    ProductDao//商品管理のDAO
  • comp.ssh.domain
    実体プロジェクト
  • comp.ssh.service
    ProductService//商品管理の業務層
    //      Dao  
    private ProductDao productDao;
    
    public void setProductDao(ProductDao productDao) {
        this.productDao = productDao;
    }    
  • 3.アクション、サービス、Daoのクラスを配置する
  • applicationContactext.xmlは、業務層のクラス*
    
    
        
    
    
    
    
    
  • を配置します.
  • Struts 2とSpring統合の2つの方法
  • (1)アクションクラスは、Struts 2自身で作成される.
  • struts 2.xml——>
  • Service DAOの2つのタグ(前のステップ*)
  • を、appication Contactext.xmlに配置する.
  • (2)actioクラスをSpringに渡して
    
      
            
            
    
    
        
        
    
  • を作成します.
  • アクションで実行される方法
  • 三、Spring統合ハイバーナ
    1.データベースの作成
  • create database myssh
  • 2.マッピングファイルとSpringの構成を作成する
  • /ssh/src/com/epoff/ssh/doman/Product.hbm.xml
    --> /org/hibernate/hibernate-mapping-3.0.dtd
    
    
    
            
                
                    
                 
                
                
            
        
  • appication Contect.xml
    
     
    
    
        
        
        
        
    
    
    
        
        
        
        
            
                org.hibernate.dialect.MySQLDialect
                true
                true
                update    
            
        
        
        
            
                com/epoint/ssh/domain/Product.hbm.xml
            
        
    
  • 3.DAOコードの作成
  • 注入Session Factory:
  • Dao上extens Hbernate DaoSupport
  • は、appication ComptextのDao
  • を構成する.
    
        
            
  • は、Daoでテンプレートの保存完了を呼び出す
    this.getHibernateTemplate().save(product)     
    
  • .
    4.事務管理を追加する
    
    
        
    
    
        
    5.問題
  • エラー1:Causedby:java.lang.ClassNotFoundException:com.mchange.v2.c3p0.ComboPooledDataSource解決:
    1.C 3 p-0.9.2.1.jarとmchange-commons-java-0.3.4.jarを導入する(導入すれば解決するものもあれば、エラーを報告するものもあります.第二のステップを読みます.)
    2.に対して の中のクラスは直接コピーして貼り付けられません.「ヒント」でノックします.直接コピーしたり、ヒントを押してノックしないと同じエラーが続きます.
  • エラー2:Loading class 'com.mysql.jdbc.Driver'. This is deprecated. 解決:
    comsql.jdbc.Driverをcomp.mysql.cj.jdbc.Driverに変更しました.
  • エラー3:MYSQL:WARN: Establishing SSL connection without server's identity verification is not recommended. 解決:
    jdbc:mysql://localhost:3306/test?useSSL=false
  • エラー4:java.sql.SQLException: Access denied for user 'root '@'localhost' (using password: YES) 解決:
    参考:java.sql.SQLException