Spring、SpringMVC、Mybaits搭建ssm框架

本人于2016年毕业,小白一枚,经验不足。各位看官如有问题,请百度。小白我也是一步一步百度而来。小白QQ群571669420,静请打扰;
一、准备工具和环境
(1)PC一台(系统不限,只要能运行Java环境即可)。
(2)eclisp(版本看个人喜好)。
(3)jar包若干(具体哪些jar包,我也不知道,反正本人将spring所有jar包全部导入)。
二、环境搭建
(1)eclisp新建web功能,命名看个人喜好。以下为本人创建工程目录结构,仅供参考;

(2)导入jar包。
(3)在web-inf目录下的lib目录下导入jar包。
(4)同样在web-inf下的web.xml中写入配置文件。配置文件内容如下:


Matton

spring
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
classpath:springmvc.xml

1



encodingFilter
org.springframework.web.filter.CharacterEncodingFilter

encoding
utf-8


forceEncoding
true


encodingFilter
/


org.springframework.web.context.ContextLoaderListener


org.springframework.web.util.IntrospectorCleanupListener


spring
.do


contextConfigLocation
classpath:applicationContext.xml


/jsp/Reception/index.jsp



ExcelServlet
ExcelServlet
com.matton.tools.ExcelServlet


ExcelServlet
/ExcelServlet

(5)在项目工程下添加Spring配置文件,配置文件如下:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
">

    
      
          
      
    
    
      
          
          
          
          
          
          
          
          
          
          
          
          
          
          
      

    
      
          
          
    
    
      
      
          
          
      
    
    

(6)添加SpringMVC配置文件,配置文件如下:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
    

    
    
    
      
  
       
           
              
                   
                     text/plain;charset=UTF-8  
                   
              
           
       
  


    
    
        
        
    
    
      
         
          
     

(7)添加mybaits配置文件,配置文件如下:

PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">

    

    
                        

    



(8)配置数据库连接,配置如下:
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/matton?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
username=root
password=admin
initialSize=0

\u5B9A\u4E49\u6700\u5927\u8FDE\u63A5\u6570

maxActive=20

\u5B9A\u4E49\u6700\u5927\u7A7A\u95F2

maxIdle=20

\u5B9A\u4E49\u6700\u5C0F\u7A7A\u95F2

minIdle=1

\u5B9A\u4E49\u6700\u957F\u7B49\u5F85\u65F6\u95F4

maxWait=60000

(9)配置log4j,配置如下:

log4j.rootLogger=debug, console,file

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%5p [%t] - %m%n
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=E:/logs/log4j.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout

log4j.logger.com.ibatis=debug
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debug
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=debug
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=debug
log4j.logger.java.sql.Connection=debug
log4j.logger.java.sql.Statement=debug
log4j.logger.java.sql.PreparedStatement=debug,stdou

log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-ddHH:mm:ss} [%t] %-5p %c(line-%L) %-4r %x - %m%n
og4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

(10)配置结束。

你可能感兴趣的:(Spring、SpringMVC、Mybaits搭建ssm框架)