SSM(SpringMVC/Spring/Mybatis)框架搭建

本文主要介绍SSM框架搭建,采用IDEA和Maven工具。项目启动命令:tomcat7:run。
github源码下载:https://github.com/1287642889/SSM
框架搭建:
1、项目结构:

SSM(SpringMVC/Spring/Mybatis)框架搭建_第1张图片
image.png

2、pom.xml代码:

  

  
    
    
      org.springframework
      spring-context
      5.0.0.RELEASE
    
    
      org.springframework
      spring-core
      5.0.0.RELEASE
    
    
      org.springframework
      spring-beans
      5.0.0.RELEASE
    
    
      org.springframework
      spring-web
      5.0.0.RELEASE
    
    
      org.springframework
      spring-webmvc
      5.0.0.RELEASE
    
    
      org.springframework
      spring-aop
      5.0.0.RELEASE
    
    
      org.springframework
      spring-tx
      5.0.0.RELEASE
    
    
      org.springframework
      spring-jdbc
      5.0.0.RELEASE
    


    
    
      org.mybatis
      mybatis
      3.4.5
    

    
      org.mybatis
      mybatis-spring
      1.3.1
    

    
    
      com.microsoft.sqlserver
      sqljdbc4
      4.0
    

    
    
      com.mchange
      c3p0
      0.9.5.2
    

    
    
      javax.servlet
      jsp-api
      2.0
      provided
    

    
    
      javax.servlet
      jstl
      1.2
    

    
    
      commons-fileupload
      commons-fileupload
      1.3.2
    


    
    
      junit
      junit
      4.12
      test
    
  

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

3、spring-mvc.xml代码:




    
    


    
    
        
        
        
    

    
    
        
        
        
        
        
        
    

4、spring-mybatis.xml代码:




    

        
        
            
        

        
            
            
            
            
        
    
        
            
            
        

        
        
            
            
        

        
        
            
        


5、jdbc.properties代码:

jdbcDriver = com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbcUrl = jdbc:sqlserver://localhost:1433;databaseName = Temp
jdbcUsername = wzf
jdbcPassword = 123456

6、log4j.properties代码:

log4j.rootLogger=INFO,Console,File  
#定义日志输出目的地为控制台
log4j.appender.Console=org.apache.log4j.ConsoleAppender  
log4j.appender.Console.Target=System.out  
#可以灵活地指定日志输出格式,下面一行是指定具体的格式
log4j.appender.Console.layout = org.apache.log4j.PatternLayout  
log4j.appender.Console.layout.ConversionPattern=[%c] - %m%n  

#文件大小到达指定尺寸的时候产生一个新的文件
log4j.appender.File = org.apache.log4j.RollingFileAppender  
#指定输出目录
log4j.appender.File.File = logs/ssm.log  
#定义文件最大大小
log4j.appender.File.MaxFileSize = 10MB  
# 输出所以日志,如果换成DEBUG表示输出DEBUG以上级别日志
log4j.appender.File.Threshold = ALL  
log4j.appender.File.layout = org.apache.log4j.PatternLayout  
log4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n 

7、web.xml代码:




    
    
        contextConfigLocation
        classpath:config/spring-mybatis.xml
    


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


    
    
        org.springframework.web.context.ContextLoaderListener
    
    
    
        org.springframework.web.util.IntrospectorCleanupListener
    



    
    
        SpringMVC
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:config/spring-mvc.xml
        
        1
    
    
        SpringMVC
        /
    


    
        /WEB-INF/jsp/index.jsp
    


8、StudentMapper.xml代码:





    
        
        
    

    

9、StudentController.java代码:

@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @RequestMapping("/getStudentById")
    public ModelAndView getStudentById(int id){
        System.out.println("id = "+id);
        ModelAndView mv = new ModelAndView("studentShow");
        mv.addObject("student",studentService.getStudentById(id));
        return mv;
    }
}

10、index.jsp代码:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


    Title


    点击我


11、功能测试:


SSM(SpringMVC/Spring/Mybatis)框架搭建_第2张图片
image.png

SSM(SpringMVC/Spring/Mybatis)框架搭建_第3张图片
image.png

你可能感兴趣的:(SSM(SpringMVC/Spring/Mybatis)框架搭建)