SSH基础框架搭建(maven管理架包)

基础的SSH框架,只有一个测试的index.jsp页面。
运行环境:Eclipse4.8.0 + Tomcat7.0 + jdk1.8(1.8以下版本没有测试)
注:架包通过maven管理

首先来看一下整个项目的结构:
SSH基础框架搭建(maven管理架包)_第1张图片
控制层:com.fyc.action
Service层:com.fyc.servicecom.fyc.serviceImpl
Dao层:com.fyc.daocom.fyc.daoImpl
实体类:com.fyc.entity
工具类:com.fyc.util
资源文件:src/main/resources
架包管理:pom.xml

其中remarks.txt是个人记录笔记文件,无需理会。
数据库建成之后,只需更改jdbc.properties文件中的属性即可。
其中Dao层采用通用Dao层的形式,因此整个项目只需要一个Dao类即可。

话不多说,直接上代码:
web.xml:



   
  
    index.jsp
  

    
    
        struts2
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    
    
        struts2
        /*
    

    
    
        org.springframework.web.context.ContextLoaderListener
    

    
    
        contextConfigLocation
        classpath:applicationContext.xml
    

applicationContext.xml:

    


    
    

    
    

    
    
        
        
        
        
        
    

    
    
        
        
        
        
            
                
                true
                
                update
                org.hibernate.dialect.MySQL5InnoDBDialect
            
        

        
        
    

    
    
        
        
    
    

    
    
        
            
            
            
            
            
        
    

    
    
        
        
        
        
    


struts.xml:




    
    

    
    
    

    
    
        
        
            default.jsp
        
    

    
    

    
       
        
        

        
        
            
                state
            
        

        
        
            
                state
            
        

        
        
            
                state
            
        
    

dao层通用接口:

package com.fyc.dao;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.hibernate.Session;

public interface CommonDao {
    /**
     * 存储对象
     * @date    2018-6-19 下午5:06:07
     * @author  live
     * @param t
     */
    public void save(T t);

    /**
     * 删除对象
     * @date    2018-6-28 上午11:42:53
     * @author  live
     * @param t
     */
    public void delete(T t);

    /**
     * 查询对象(根据类和主键id查询)
     * @date    2018-6-28 上午11:48:22
     * @author  live
     * @param t
     */
    public void query(T t, Integer id);

    /**
     * 更新对象(根据对象的主键进行更新)
     * @date    2018-6-28 上午11:51:53
     * @author  live
     * @param t
     */
    public void update(T t);

    /**
     * 执行SQL语句
     * @date    2018-6-28 上午11:54:07
     * @author  live
     * @return
     */
    public int executeBySql(String sql);

    /**
     * 执行hql语句
     * @date    2018-6-28 上午11:59:46
     * @author  live
     * @param hql
     * @return
     */
    public List executeByHql(String hql);


    /*********************************************************************************************分割线*********************************************************************************************/

    /**
     * 存储或更新(根据主键判定)
     * @date    2018-6-28 下午2:13:17
     * @author  live
     */
    public void saveOrUpdate(T t);

}

导入架包-pom.xml:

    
  4.0.0
  mmic
  mmic
  0.0.1-SNAPSHOT
  war
  
  
  
    UTF-8
  
  
  
    
        
            false
        
        central
        Maven Repository Switchboard
        http://repo2.maven.org/maven2
    
  
  
    
      javax.servlet
      jstl
      1.2
      provided
    
    
      javax.servlet.jsp
      jsp-api
      2.1
      provided
    
    
      org.glassfish
      javax.annotation
      3.0.1
    
    
      org.glassfish
      javax.ejb
      3.0.1
    
    
      org.jboss.weld
      weld-osgi-bundle
      1.0.1-SP3
    
    
      org.glassfish
      javax.servlet
      3.0.1
    

        
            junit
            junit
            4.10
            test
        
        
        
        
            org.apache.struts
            struts2-core
            2.3.24
        

        
            org.apache.struts
            struts2-spring-plugin
            2.3.24.1
        

        
        
            org.apache.struts
            struts2-json-plugin
            2.3.16.1
        

        
        
            org.hibernate
            hibernate-core
            4.2.2.Final
        

        
        
            org.springframework
            spring-core
            4.2.4.RELEASE
        
        
        
            org.springframework
            spring-beans
            4.2.4.RELEASE
        

        
        
            org.springframework
            spring-orm
            4.2.4.RELEASE
        

        
        
            org.springframework
            spring-web
            4.2.4.RELEASE
        

        
        
            org.springframework
            spring-context
            4.2.4.RELEASE
        
        
        
            mysql
            mysql-connector-java
            5.1.26
        
        
        
            c3p0
            c3p0
            0.9.1.2
        


        
            commons-dbcp
            commons-dbcp
            1.4
        

        
        
            log4j
            log4j
            1.2.16
        
        
            org.slf4j
            slf4j-api
            1.6.1
        
        
            org.slf4j
            slf4j-nop
            1.6.4
        

        
        
            javassist
            javassist
            3.11.0.GA
        

        
        
            org.aspectj
            aspectjweaver
            1.9.1
        

  
  
    
      
        maven-war-plugin
      
      
        maven-compiler-plugin
        
          1.6
          1.6
        
      
    
  

其他类暂不赘述,完整资源包下载传送:https://download.csdn.net/download/qq_38084142/10600235

框架也是自己在网上搜罗的资源拼合而成,如有bug,敬请指教!!!

你可能感兴趣的:(SSH基础框架搭建(maven管理架包))