您当前的位置: 首页 > 

星夜孤帆

暂无认证

  • 3浏览

    0关注

    626博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

SSM框架配置文件整合

星夜孤帆 发布时间:2019-06-10 15:57:43 ,浏览量:3

1 web.xml
  • 1.1前端控制器


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



  springmvc
  *.action

ps: classpath是WEB-INF下的classes文件路径,在工程项目下新建config,内部的文件会自动加载到classes文件下,需要在navigator视图下才能看得到。(这是在.clsspath配置里设置的)

  • 1.2配置编码过滤器
    
    
        CharacterEncodingFilter      
        
            org.springframework.web.filter.CharacterEncodingFilter
        
        
            encoding
            UTF-8
        
    
    
        CharacterEncodingFilter
        /*
    
  • 1.3事物传播行为以及切面配置

    
        
            
            
            
            
            
            
            
            
            
            
        
    
    
    
    
        
    
2.springmvc-config.xml
  • 2.1 配置控制器扫描
    
    
  • 2.2配置视图控制器
    
    
        
        
     
  • 2.3配置自定义类型转换器
     
    
    
    
        
            
                
            
        
    
  • 2.4配置注解驱动


配置了扫描就不需要配置主注解驱动了 原因如下

1>会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean
        DefaultAnnotationHandlerMapping :负责扫描带有@Controller注解的类,给此类设置对应的@RequestMapping
        AnnotationMethodHandlerAdapter :负责扫描Controller类中的方法,给方法设置对应的@RequestMapping
2>
        扫描器会扫描带有@Component@Service@Controller@Component等注解,并实现相应的操作,
        因为这四个注解包含了@Controller,
        所以会将Controller类和方法进行映射,不需要用了
  • 2.5配置静态资源访问映射

       
     
       
      
      default
      *.jpg
      
         
      
    
  • 2.6配置拦截器

拦截器配置


    
       
          
       
        
            
            
            
            
        
        
        
            
            
        

拦截器代码:ps:需要继承HandlerInterceptor接口,并实现三个方法

public class Interceptor1 implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, 
        HttpServletResponse response, Object handler) throws Exception {
        System.out.println("Intercepter1...preHandle");
        return true;
    }
    @Override
    public void postHandle(HttpServletRequest request, 
        HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
        System.out.println("Intercepter1...postHandle");
    }
    @Override
    public void afterCompletion(HttpServletRequest request, 
        HttpServletResponse response, Object handler, 
        Exception ex) throws Exception {
        System.out.println("Intercepter1...afterCompletion");
    }
}

  • 2.7配置文件上传解析器
    
    
          
          
    
3 db.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis
jdbc.username=root
jdbc.password=root
jdbc.maxTotal=30
jdbc.maxIdle=10
jdbc.initialSize=5
4 applicationContext.xml


    
    
    
    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
     
    
        
     
    
    
    
    
         
         
         
  
    
    
    
        
    
     
    

5 mybatis-config.xml



    
    
        
    

6 springmvc-config.xml


    
    
    
    
    
    
    
    
      
    
    
        
        
     
    
    
    
        
            
            
        
     


7 log4j.properties
# Global logging configuration
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration...
log4j.logger.com.itheima.core=DEBUG
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
8 web.xml配置


    
    
        contextConfigLocation
        classpath:applicationContext.xml
    
    
        
             org.springframework.web.context.ContextLoaderListener
        
    
    
    
        encoding
        
             org.springframework.web.filter.CharacterEncodingFilter
        
        
            encoding
            UTF-8
        
    
    
        encoding
        *.action
    
    
    
        springmvc
        
             org.springframework.web.servlet.DispatcherServlet
        
        
            contextConfigLocation
            classpath:springmvc-config.xml
        
        
        1
    
    
        springmvc
        
        /
    

https://www.jianshu.com/p/ad5e2615ba2e

关注
打赏
1636984416
查看更多评论
立即登录/注册

微信扫码登录

0.0428s