SSM项目实践

 码云地址:https://gitee.com/xmr123/JAVAEE/tree/feature-SSM

一、项目创建:

1、创建一个Javaweb项目并且配置好tomcat等

(之前做过 此步省略)

 

2、在setting中引入MAVEN

 

 

 

 注意:

MAVEN 的版本不能早于编辑器的版本否则会报错。

 

3、创建项目结构

 

 

 

二、代码编写:

修改pom.xml文件,导入需要的包:



    4.0.0
 
    com.xiao
    SSM
    1.0-SNAPSHOT
    war
 
    
    
        4.2.4.RELEASE
        3.2.8
        1.2.2
        1.6.4
        1.2.17
        2.4.2
        1.0.9
        5.1.32
        1.2
        2.5
        2.0
        1.3.2
        1.3.1
    
 
    
    
        
            
            
                org.springframework
                spring-context
                ${spring.version}
            
            
                org.springframework
                spring-beans
                ${spring.version}
            
            
                org.springframework
                spring-webmvc
                ${spring.version}
            
            
                org.springframework
                spring-jdbc
                ${spring.version}
            
            
                org.springframework
                spring-aspects
                ${spring.version}
            
            
                org.springframework
                spring-jms
                ${spring.version}
            
            
                org.springframework
                spring-context-support
                ${spring.version}
            
 
            
            
                org.mybatis
                mybatis
                ${mybatis.version}
            
            
                org.mybatis
                mybatis-spring
                ${mybatis.spring.version}
            
 
            
            
                org.slf4j
                slf4j-log4j12
                ${slf4j.version}
            
            
                log4j
                log4j
                ${log4j.version}
            
 
            
            
                com.fasterxml.jackson.core
                jackson-databind
                ${jackson.version}
            
 
            
            
                com.alibaba
                druid
                ${druid.version}
            
 
            
            
                mysql
                mysql-connector-java
                ${mysql.version}
            
 
            
            
                org.apache.commons
                commons-io
                ${commons-io.version}
            
 
            
            
                commons-fileupload
                commons-fileupload
                ${commons-fileupload.version}
            
 
            
            
                jstl
                jstl
                ${jstl.version}
            
            
                javax.servlet
                servlet-api
                ${servlet-api.version}
                provided
            
            
                javax.servlet
                jsp-api
                ${jsp-api.version}
                provided
            
        
    
 
    
    
        
        
            org.springframework
            spring-context
        
        
            org.springframework
            spring-beans
        
        
            org.springframework
            spring-webmvc
        
        
            org.springframework
            spring-jdbc
        
        
            org.springframework
            spring-aspects
        
        
            org.springframework
            spring-jms
        
        
            org.springframework
            spring-context-support
        
 
        
        
            org.mybatis
            mybatis
        
        
            org.mybatis
            mybatis-spring
        
 
        
        
            org.slf4j
            slf4j-log4j12
        
 
        
        
            com.fasterxml.jackson.core
            jackson-databind
        
 
        
        
            com.alibaba
            druid
        
 
        
        
            mysql
            mysql-connector-java
        
 
        
        
            org.apache.commons
            commons-io
        
 
        
        
            commons-fileupload
            commons-fileupload
        
 
        
        
            jstl
            jstl
        
        
            javax.servlet
            servlet-api
            provided
        
        
            javax.servlet
            jsp-api
            provided
        
    
 
    
        
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.2
                
                    1.8
                    1.8
                    UTF-8
                
            
        
 
        
        
            
                src/main/java
                
                    **/*.xml
                
                false
            
 
            
                src/main/resources
                
                    **/*.properties
                    **/*.xml
                
                false
            
        
 
    
 

 

(1)连接数据库配置信息文件:db.properties

druid.driver=com.mysql.jdbc.Driver
druid.url=jdbc:mysql://localhost:3306/all_db?characterEncoding=utf-8
druid.username=root
druid.password=Guozhaojie610

(2)Mybatis配置文件:SqlMapConfig.xml

复制代码
复制代码




    
    
        
    

复制代码
复制代码

(3)Spring配置文件:applicationContext.xml

 

复制代码
复制代码



    
    

    
    

    

    
    
    
    
    
    

    
    
        
        
        
        

    

复制代码
复制代码

 

 

最后需要在web.xml文件中进行配置:

复制代码
复制代码



  SSM

  
    index.jsp
  

  
  
    org.springframework.web.context.ContextLoaderListener
  

  
  
    contextConfigLocation
    classpath:applicationContext.xml
  

  
  
    encoding
    org.springframework.web.filter.CharacterEncodingFilter
    
      encoding
      UTF-8
    
  
  
    encoding
    /*
  

  
  
    springmvc
    org.springframework.web.servlet.DispatcherServlet
    
    
      contextConfigLocation
      classpath:springmvc.xml
    
    1
  
  
    springmvc
    /
  

 

 

三、效果展示:

1、新闻首页

 

 

2、登录界面

 

 

 

 

3、后台添加新闻

 

 

4、新闻管理

 

你可能感兴趣的:(SSM项目实践)