基于maven项目的ssh框架搭建

基于maven项目的ssh框架搭建(分层概念)

1.新建maven项目。https://blog.csdn.net/qq_36489998/article/details/80525010

        项目的目录如下:

        基于maven项目的ssh框架搭建_第1张图片

        其中ssh-webapp依赖ssh-service ---->ssh-service依赖ssh-dao ----->ssh-dao依赖ssh-domain

2.在ssh父项目的pom文件中加入jar依赖

基于maven项目的ssh框架搭建_第2张图片



  4.0.0
  club.jiajiajia.ssh
  ssh
  0.0.1-SNAPSHOT
  pom
  
  
  
	
	    com.mchange
	    c3p0
	    0.9.5.2
	
	
  	
      junit
      junit
      4.10
      test
    

       

      

      
        org.apache.struts  
        struts2-core  
        2.3.1  
      

      
        org.apache.struts  
        struts2-spring-plugin  
        2.3.1  
      

       


	
	    org.hibernate
	    hibernate-core
	    4.3.11.Final
	
	
	
	
	    mysql
	    mysql-connector-java
	    5.1.38
	

      
        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.springframework  
        spring-core  
        3.1.1.RELEASE  
      

      
        org.springframework  
        spring-beans  
        3.1.1.RELEASE  
      

      
        org.springframework  
        spring-context  
        3.1.1.RELEASE  
      

      
        org.springframework  
        spring-jdbc  
        3.1.1.RELEASE  
      
    
      
        org.springframework  
        spring-orm  
        3.1.1.RELEASE  
      

      
        org.springframework  
        spring-web  
        3.1.1.RELEASE  
      
  
  
    ssh-domain
    ssh-dao
    ssh-service
    ssh-webapp
  

3.在resources文件夹下新建applicationContext.xml     hibernate.cfg.xml     struts.xml  三个文件

基于maven项目的ssh框架搭建_第3张图片

1》.applicationContext.xml



		
	
    
    
    
    
		
		
		
		
		
		
	
	
    
    	
        
        
    


2.》hibernate.cfg.xml




    
        org.hibernate.dialect.MySQLDialect
        true
        true
        update 
        
        
        
    
3.》struts.xml



    
    	
    		/success.jsp
    	
	
    

4.》修改web.xml



  weblog
  
    index.html
    index.htm
    main.jsp
    default.html
    default.htm
    index.jsp
  
  
  
    struts2
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  
  
    struts2
    *.action
  
  
 
    contextConfigLocation
    classpath:applicationContext.xml
  
  
  
    org.springframework.web.context.ContextLoaderListener
  

3.在webapp文件夹下新建index.jsp    success.jsp

    1>index.jsp

    



Hello World!

    2.>success.jsp

       

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>




Insert title here


	success

4.在ssh-webapp下新建java类

    基于maven项目的ssh框架搭建_第4张图片

    TestAtion.java

package club.jiajiajia.ssh;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller
public class TestAction {
	@Autowired
	private TestServlet testServlet;
	public String test() {
		testServlet.add();
		System.out.println("测试success");
		return "success";
	}
}

5.在ssh-service下新建java类

基于maven项目的ssh框架搭建_第5张图片

TestServlet.java

package club.jiajiajia.ssh;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TestServlet {
	@Autowired
	private TestDao testDao;
	public void add() {
		testDao.testDao();
	}
}	

6.在ssh-dao层下建java类

TestDao.java

package club.jiajiajia.ssh;

import javax.persistence.Access;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class TestDao {
	@Autowired
	private SessionFactory sessionFactory;
	public void testDao() {
		System.out.println(sessionFactory);
	}
}

6.在ssh-domain下新建java类

User.java

基于maven项目的ssh框架搭建_第6张图片

package club.jiajiajia.ssh;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="user")
public class User {
	@Id
	@GeneratedValue
	private Integer id;
	private String name;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public User() {
		super();
		// TODO Auto-generated constructor stub
	}
	public User(Integer id, String name) {
		super();
		this.id = id;
		this.name = name;
	}
	@Override
	public String toString() {
		return "User [id=" + id + ", name=" + name + "]";
	}
	
}

ok启动项目

运行

ok

你可能感兴趣的:(基于maven项目的ssh框架搭建)