SSM框架配置文件模板

一、db.properties配置

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/database
jdbc.username=root
jdbc.password=123

二、log4j.properties配置

# Global logging configuration\uff0c\u5efa\u8bae\u5f00\u53d1\u73af\u5883\u4e2d\u8981\u7528debug
log4j.rootLogger=DEBUG, stdout
# 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

三、SqlMapConfig.xml配置




    
    
        
        
    


四、applicationContext.xml配置



    
    
    
    
    
        
        
        
        
        
        
    
    
    
        
        
        
        
        
        
    

    
    
        
        
        
        
    

    
    
        
        
        
        
    

    
    

    
    
    
        
    

    
    
        
            
            
            
            
            
            
            
            
            
            

            
            
            
            
            
            
            

            
        
    

    
    
        
    




关于Spring事务的理解(Controller可以使用@Transactional)

五、springmvc.xml配置



    
    

    
    
    
              

    
    
    
    
    
        
        
            
                
                
            
        
    
    
    


    
    
        
             
        
    

    
    
        
            
        
    
    
        
    

    
    
        
        
        
            
                    
                  
            
            
                    
        
    


在mvc:interceptors标签下声明interceptor主要有两种方式:
(1)直接定义一个Interceptor实现类的bean对象。使用这种方式声明的Interceptor拦截器将会对所有的请求进行拦截。
(2)使用mvc:interceptor标签进行声明。使用这种方式进行声明的Interceptor可以通过mvc:mapping子标签来定义需要进行拦截的请求路径。

public class SecurityInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        HttpSession session = httpServletRequest.getSession(true);
        // 从session 里面获取用户名的信息
        Object obj = session.getAttribute("username");
        // 判断如果没有取到用户信息,就跳转到登陆页面,提示用户进行登陆
        if (obj == null || "".equals(obj.toString())) {
            httpServletResponse.sendRedirect("/login.jsp");
        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}

六、web.xml配置




    
    
    
        contextConfigLocation
        classpath:spring/applicationContext.xml   
    


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


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


    
    
        CharacterEncodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            utf-8
        
        
            forceEncoding
            true
        
    
    
        CharacterEncodingFilter
        /*
    


    
    
        index.jsp
    


    
    
        404
        /error/404.jsp
    
    
    
        500
        /error/500.jsp
    
    
        java.lang.Throwable
        /error/500.jsp
    
    
        org.springframework.web.util.NestedServletException
        /error/500.jsp
    


手把手教你整合最优雅SSM框架:SpringMVC + Spring + MyBatis
SpringMVC中url-pattern /和/*的区别
SpringMVC中web.xml的url-pattern
Servlet的url-pattern匹配规则
Servlet学习一:web.xml中url-pattern匹配规则
表单form action的url写法
/.action
以/开头的是路径匹配 所以不能再用/
.action来匹配 只能用//这样的形式
(.)是后缀匹配

你可能感兴趣的:(SSM框架配置文件模板)