SSM + Freemarker 开发框架快速搭建


1.项目骨架建立

一、使用开发工具IDEA,构建Maven项目,然后调整Maven项目结构,使其成为一个标准的web项目:

  • 此处不选择Maven骨架,直接Next:

  • 输入项目的相关信息,直接Finish

  • 项目构建完成后,选择pom.xml 打包方式为 war

    war
    

  • 选择1,建立项目的webapp目录,选择2,在指定目录的WEB-INF下建立web.xml文件:

项目最终构建完成结构层次图:

2.整合SSM + FreeMarker:

一、数据库资源文件配置:

# 数据库配置文件 db.properties
db.username=root
db.password=root
db.url=jdbc:mysql:///meeting?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai

二、Spring配置:

<?xml version="1.0" encoding="UTF-8"?>


    
    
        
    

    
    

    
    
        
        
        
    

    
    
        
        
        
        
            
                classpath:mapper/*Mapper.xml
                classpath:org/taoguoguo/meeting/mapper/*Mapper.xml
            
        
    

    
        
        
    

    
    
    
        
    

    
    
        
            
            
            
            
        
    

    
    
        
        
        
    

    

三、SpringMVC配置:

<?xml version="1.0" encoding="UTF-8"?>


    
    
        
    

    
    

    
    

    
    
        
            
                classpath:freemarker-var.properties
            
        
    

    
    
        
        
        
        
        
        
            
                
            
        
        
        
            
                
                10
                
                zh_CN
                
                yyyy-MM-dd HH:mm:ss 
                
                yyyy-MM-dd
                
                HH:mm:ss
                
                #.####
            
        
    

    
    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    


四、FreeMarker配置:

##freemarker-var.properties 也可以在mvc配置文件中直接写死
root=/
  1. web.xml配置

    <?xml version="1.0" encoding="UTF-8"?>
    
    
        
        
            contextConfigLocation
            classpath:applicationContext.xml
        
        
            org.springframework.web.context.ContextLoaderListener
        
    
        
        
            springmvc
            org.springframework.web.servlet.DispatcherServlet
            
                contextConfigLocation
                classpath:spring-servlet.xml
            
        
        
            springmvc
            /
        
    
        
        
            encodingFilter
            org.springframework.web.filter.CharacterEncodingFilter
            
                encoding
                UTF-8
            
            
                forceRequestEncoding
                true
            
            
                forceResponseEncoding
                true
            
        
        
            encodingFilter
            /*
        
    
    

最后在指定目录下创建html文件,将后缀改为ftl,然后写一个Controller 请求访问即可。