搭建基于springmvc+freemarker+maven的web项目

1、首先了解如何构建一个maven web项目

搭建基于springmvc+freemarker+maven的web项目_第1张图片

搭建基于springmvc+freemarker+maven的web项目_第2张图片

搭建基于springmvc+freemarker+maven的web项目_第3张图片

右击项目,选择project facets,勾选Dynamic Web Module

搭建基于springmvc+freemarker+maven的web项目_第4张图片

搭建基于springmvc+freemarker+maven的web项目_第5张图片

点击OK,该项目目录结构发生改变,成为能够部署在tomcat上的标准web应用,默认部署目录为WebContent

搭建基于springmvc+freemarker+maven的web项目_第6张图片

实际项目开发中,我们一般会重新构建maven项目结构,接下来就以新建一个基于spring+freemarker+maven的web项目frame为例

搭建基于springmvc+freemarker+maven的web项目_第7张图片

搭建基于springmvc+freemarker+maven的web项目_第8张图片

部署配置如下

搭建基于springmvc+freemarker+maven的web项目_第9张图片

loginCtrl.java

package com.frame.core.ctrl;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class loginCtrl {
	private static Logger log = Logger.getLogger(loginCtrl.class);
	@RequestMapping(value = "/login")
	public ModelAndView login() {
		ModelAndView mav = new ModelAndView("index");
		mav.addObject("username", "笑傲江湖");
		mav.addObject("projectName", "Freemarker框架");
		return mav;//ModelAndView mav = new ModelAndView("redirect:/index.do");index.do里面再返回视图可以重定向解决表单重复提交
	}
}
applicationContext.xml



	

	
	
	
	
	
	
	 
	  
	  
	
		
		
		
		
		
			

				${dialect}
				false
				
			
		
		
			
			
		

	
		
		
		
	

	
	
		
	

	
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
   			
		
	

	
	
		
	
	
			
				${jdbc.url}
			
			
				${jdbc.username}
			
			
				${jdbc.password}
			
			
				true
			
			
				true
			
			
				true
			
			
				20000
			
		
freemarker.properties

tag_syntax=auto_detect
template_update_delay=2
default_encoding=UTF-8
output_encoding=UTF-8
locale=zh_CN
date_format=yyyy-MM-dd
time_format=HH:mm:ss
datetime_format=yyyy-MM-dd HH:mm:ss
jdbc.properties

jdbc.username=root
jdbc.password=123456
jdbc.driverClassName=com.mysql.jdbc.Driver
#jdbc.url=jdbc:mysql://127.0.0.1:3306/inspect
jdbc.url=jdbc:mysql://127.0.0.1:3306/frame
#jdbc.url=jdbc:mysql://192.168.0.35:3308/fn
#jdbc.url=jdbc:mysql://10.169.114.175:3306/inspect
dialect=org.hibernate.dialect.MySQLDialect
spring-mvc.xml



	
		
	
	
	
		
		
			/views/
		
		
			.html
		
	

	
	
		
	

	
	
		

		
			
				/views/
				/ftl/
			
		
		
		
			
				
			
		
		
			
				10
				zh_CN
				yyyy-MM-dd
				yyyy-MM-dd
				#.##
				
				head.ftl
			
		
	

	

	
	
		
		
		
		
		
		
		
		
		
	

	
	
	
		
		
	
footer.fl

<#macro footer>
<#compress>
  

footer

head.flt

 <#import "/spring.ftl" as spring/>
 <#include "/path.ftl"/>
 <#include "/title.ftl"/>
 <#include "/footer.ftl"/>
 <#macro head>
	<#compress>
	
	
	
	
    
	<@projName/>
 	
    

 
<#macro header>
 	<#compress>
 		

project:<@projName/>; path:<@path/>; username:${username!''}

header

path.flt

<#macro path>
<#compress>
${request.contextPath}

 
title.flt

<#macro projName>
<#compress>
${projectName!""}

 
webapp/views/index.html



  
 <@head/>


    <@header/>
    



middle



<@footer/>
web.xml



  Freemarker框架
  
    contextConfigLocation
    classpath:applicationContext.xml
  
  
     org.springframework.web.context.ContextLoaderListener  
  
  
    60
  
  
    CharacterEncodingFilter
    org.springframework.web.filter.CharacterEncodingFilter
    
      encoding
      utf8
    
  
  
    CharacterEncodingFilter
    /*
  
  
    dispatcher
    org.springframework.web.servlet.DispatcherServlet
    
      contextConfigLocation
      
      			classpath:spring-mvc.xml 
      		
    
    1
  
  
    dispatcher
    *.do
  
  
    OpenSessionInViewFilter
    
			org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
    
      sessionFactoryBeanName
      coreSessionFactory
    
    
      singleSession
      true
    
    
      flushMode
      AUTO
    
  
  
    OpenSessionInViewFilter
    /*
  
  
    /index.jsp
  
webapp/index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="UTF-8"%>



<%response.sendRedirect(request.getContextPath()+"/login.do"); %>

pom.xml


	4.0.0
	com.frame
	frame
	war
	0.0.2-SNAPSHOT
	Freemarker框架
	http://maven.apache.org

	
		
			junit
			junit
			${junit-version}
		
		
		  
		    com.fasterxml.jackson.core  
		    jackson-databind  
		    ${jackson2.version}  
		 
		
		
			org.springframework
			spring-context
			${spring-version}
		
		
		
			org.springframework
			spring-tx
			${spring-version}
		

		
			org.springframework
			spring-orm
			${spring-version}
		

		
			org.springframework
			spring-web
			${spring-version}
		

		
			org.springframework
			spring-webmvc
			${spring-version}
		
		
			org.springframework
			spring-context-support
			${spring-version}
		
		
	        org.springframework.data
	        spring-data-jpa
	        1.8.0.RELEASE
	     

		
			org.springframework
			spring-test
			${spring-version}

		

		
			org.aspectj
			aspectjweaver
			${aspectjweaver-version}
		

		
			cglib
			cglib-nodep
			${cglib-version}
		

		
			commons-dbcp
			commons-dbcp
			${commons-dbcp-version}
		
		
			 org.apache.commons
 			 commons-lang3
			${commons-lang-version}
		
	
			commons-fileupload
			commons-fileupload
			${commons-fileupload-version}
		
		
		
			org.hibernate
			hibernate-core
			${hibernate-version}
		
		
		
			mysql
			mysql-connector-java
			${mysql-connector-version}
		
		
		
			log4j
			log4j
			${log4j-version}
		
		  
		    org.mortbay.jetty  
		    servlet-api-2.5  
		    6.1.14
		    provided  
		 
		
			  org.freemarker
			  freemarker
			  ${freemarker-version}
			
		
		     org.apache.tomcat
			  tomcat-servlet-api
			  7.0.47
		    provided
		
			
			opensymphony
			oscache
			${oscache-version}
		
		
		 
		    json
			org.json-2.0.jar
			2.0
		    system
		    ${project.basedir}/src/main/webapp/WEB-INF/lib/org.json-2.0.jar
		
		
		
			org.quartz-scheduler
			quartz
			2.2.1
		
 
	    
	      com.thoughtworks.xstream
	      xstream
	      1.4.7
	    
	    
		    
		      org.codehaus.btm
		      btm
			2.1.4
		    
		    
		    
		       org.jboss.spec.javax.el
			  jboss-el-api_2.2_spec
			  1.0.4.Final
			  provided
		    
		    
		    
				org.springframework.security
				spring-security-web
					  ${spring.security.version}
			
			
				org.springframework.security
				spring-security-config
					  ${spring.security.version}
			
			
				jaxen
				jaxen
				1.1.6
			
			
				net.sf.json-lib
				json-lib
				2.2.3
				jdk15
			
	
	
		frame
      src/main/java
      src/test/java
      
          
             src/main/resources
           
          
             src/jbpm/resources
           
          
             src/main/config
           
       
      
          
             src/test/resources
           
       
		
			
				maven-compiler-plugin
				3.0
				
					1.7
					1.7
				
			
			
				maven-war-plugin
				2.6
				
					src/main/webapp
					false
				
			
			
			
				org.apache.tomcat.maven
				tomcat7-maven-plugin
				2.2
				
					8080
					/frame
					http://localhost:8080/manager/html
					tomcat
					admin
					admin
					tomcat7
                
				
					
						mysql
						mysql-connector-java
						${mysql-connector-version}
					
					
						org.codehaus.btm
						btm
						${btm.version}
					
					
						org.codehaus.btm
						btm-tomcat55-lifecycle
						${btm.version}
					
					
						slf4j-api
						org.slf4j
						1.7.2
					
					
						javax.transaction
						jta
						1.1
					
					
						com.h2database
						h2
						1.3.168
					
				
			
			
				org.apache.maven.plugins
				maven-surefire-plugin
				2.17
				
					
						
							**/*Test.java
						
					
					
					 	
							**/*AllTest.java
					 	
					 	
							**/AControllerTest.java 
					 	
					
					
						firefox
						testng.xml
					
				
			
			
		        org.codehaus.mojo
		        build-helper-maven-plugin
		        1.4
		        
		          
		            add-source
		            generate-sources
		            
		              add-source
		            
		            
		              
		                src/main/java
		              
		            
		          
		        
		      
	
	
			
				
				
					org.eclipse.m2e
					lifecycle-mapping
					1.0.0
					
						
							
								
									
										
											org.codehaus.mojo
										
										
											build-helper-maven-plugin
										
										
											[1.4,)
										
										
											add-source
										
									
									
										
									
								
							
						
					
				
			
		
	

	
		UTF-8
		UTF-8
		2014
		4.0.9.RELEASE
		3.2.0.RELEASE
		4.2.17.Final
		4.2.0.Beta2
		2.3.8
		1.4
		3.3.2
		2.2.2
		1.7.1
		1.2
		3.0-alpha-1
		2.2.1-b03
		13.0.1
		1.7.2
		1.2.17
		4.11
		5.1.22
		6.1.1
		2.3.20
		6.0
		0.9.0
		2.2.3
		1.3.1 
		2.3 
	    6.0.0.Final
	    6.0.0.Final
	    1.0.0.Final
	    1.0.9
	    1.3.161
	    2.1.4
	    4.8.1
		 UTF-8
	

运行效果

搭建基于springmvc+freemarker+maven的web项目_第10张图片














你可能感兴趣的:(框架相关,freemarker,maven)