Spring5+Hibernate5.1+Struts2.5的环境搭建(IDEA)

一、POM文件




  4.0.0

  com.huilong
  OA
  1.0
  war

  OA Maven Webapp
  
  http://www.example.com

  
    UTF-8
    1.8
    1.8
    
    5.0.7.RELEASE
    5.1.10.Final
    2.5.14.1
  
  
  
    
      
        
      
        org.springframework
        spring-orm
        ${spring.version}
      
      
      
        org.springframework
        spring-context
        ${spring.version}
      
      
      
        org.springframework
        spring-aspects
        ${spring.version}
      
      
      
        org.springframework
        spring-test
        ${spring.version}
      
      
      
        org.springframework
        spring-web
        ${spring.version}
      
      
      
        org.hibernate
        hibernate-core
        ${hibernate.version}
      
      
      
        org.apache.struts
        struts2-core
        ${struts.version}
      
      
        org.apache.struts
        struts2-spring-plugin
        ${struts.version}
      
    
  

  
    
    
      org.slf4j
      slf4j-log4j12
      1.8.0-beta4
    
    
      org.apache.logging.log4j
      log4j-core
      2.9.0
    
    
    
      org.junit.jupiter
      junit-jupiter-api
      5.5.0-M1
      test
    
    
    
    
      org.springframework
      spring-orm
    
    
    
      org.springframework
      spring-context
    
      
      
          org.springframework
          spring-aspects
      
      
      
          org.springframework
          spring-test
      
      
      
          org.springframework
          spring-web
      
    
    
      org.aspectj
      aspectjweaver
      1.9.3
    
    
      org.apache.commons
      commons-pool2
      2.6.1
    
    
      org.springframework
      spring-dao
      2.0.8
    
    
    
      org.hibernate
      hibernate-core
    
    
    
      mysql
      mysql-connector-java
      5.1.47
    
    
    
      com.mchange
      c3p0
      0.9.5
    
    
    
      org.apache.struts
      struts2-core
    
    
    
      org.apache.struts
      struts2-spring-plugin
    
    
    
      org.apache.struts.xwork
      xwork-core
      2.3.36
    
    
    
      javax.servlet
      servlet-api
      2.5
      provided
    
    
    
      javax.servlet
      jsp-api
      2.0
      provided
    
  

  
    OA

    
      
        
          maven-clean-plugin
          3.1.0
        
        
        
          maven-resources-plugin
          3.0.2
        
        
          maven-compiler-plugin
          3.8.0
        
        
          maven-surefire-plugin
          3.0.0-M3
        
        
          maven-war-plugin
          3.2.2
        
        
          maven-install-plugin
          3.0.0-M1
        
        
          maven-deploy-plugin
          3.0.0-M1
        
      
    

    
      
        
        org.apache.tomcat.maven
        tomcat7-maven-plugin
        2.2
      
    
   
  

二、applicationContext.xml文件




       

       

       
           
           
           
           
       
    
       
            
            
       
    
     
         
     
     

三、Hibernate.cfg.xml文件




    
        
        
        
        org.hibernate.dialect.MySQL5Dialect
        
        true
        
        true
        

        
        
        


    

四、jdbc.properties文件

jdbcUrl		= jdbc:mysql://localhost:3306/oa?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
driverClass	= com.mysql.jdbc.Driver
user	= root
password	= root

五、struts.xml文件





    

   
    
    

    
        
            WEB-INF/view/ok.jsp

            
        
    

六、index.jsp页面

    <%@page contentType="text/html;charset=utf-8" language="java" %>
    <%@taglib uri="/struts-tags" prefix="s"%>
    
    
    
     
    首页
    
    
    

Hello World!

ID: name:
中文乱码zhongwenluanma

七、ok.jsp页面

<%--
  Created by IntelliJ IDEA.
  User: wanglei
  Date: 2019/4/21
  Time: 3:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="s" uri="/struts-tags" %>



    显示信息


Message

ID: 姓名:

八、web.xml




  Archetype Created Web Application
 
  
   contextConfigLocation
   classpath:applicationContext.xml
 

    
        log4jConfigLocation
        classpath:log4j2.xml
    

  
    struts
    org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
  
  
    struts
    /*
  
  
  
    org.springframework.web.context.ContextLoaderListener
  

  index.jsp


九、UserAction类

package com.huilong.oa.action;

import com.huilong.oa.entity.UserEntity;
import com.huilong.oa.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller("userAction")
@Scope("prototype")
public class UserAction extends ActionSupport {
    private UserEntity userEntity;
    private int  id;
    private String name;

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getMessage1() {
        return message1;
    }

    public void setMessage1(int message1) {
        this.message1 = message1;
    }

    public String getMessage2() {
        return message2;
    }

    public void setMessage2(String message2) {
        this.message2 = message2;
    }

    private int message1;
    private String message2;
    @Autowired
     private UserService userService;

     public String saveUser(){
     userEntity=new UserEntity(id,name);
     message1=id;
     message2=name;
     userService.save(userEntity);

      return SUCCESS;
    }

    public UserEntity getUserEntity() {
        return userEntity;
    }

    public void setUserEntity(UserEntity userEntity) {
        this.userEntity = userEntity;
    }

}

十、UserDaoImpl类

package com.huilong.oa.dao.impl;

import com.huilong.oa.dao.UserDao;
import com.huilong.oa.entity.UserEntity;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;
@Repository("userDao")
public class UserDaoImpl  implements UserDao {

    private HibernateTemplate hibernateTemplate;
    @Autowired
    public UserDaoImpl(SessionFactory sessionFactory) {
        this.hibernateTemplate = new HibernateTemplate(sessionFactory);
    }
    @Override
    public void save(UserEntity userEntity) {
           hibernateTemplate.save(userEntity);
    }
}

十 一、工程目录结构
Spring5+Hibernate5.1+Struts2.5的环境搭建(IDEA)_第1张图片
总结:本来想写写流程,注意事项什么的,但是因为精神不是很好感觉有点累所以就。。。总之,细心 细心 再细心就对了

你可能感兴趣的:(SSH)