`
yjmyd1119
  • 浏览: 11503 次
  • 性别: Icon_minigender_1
  • 来自: 河南
社区版块
存档分类

spring MVC3 集成 freemarker

阅读更多



 1,eclipse 环境下:各个jar包什么的就不上传了。
2,首先web.xml

<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			classpath*:applicationContext.xml
		</param-value>
	</context-param>

	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>


	<servlet>
		<servlet-name>ywlmsj</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>ywlmsj</servlet-name>
		<url-pattern>*.html</url-pattern>

	</servlet-mapping>
  
  
  
  
  
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list> 

 3,*-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

	<mvc:annotation-driven />

	<context:component-scan base-package="com.ywrj.lmsj" />



	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
		p:prefix="/" p:suffix=".jsp" >
		<property name="order" value="2"></property>
    </bean>





	<!-- 配置freeMarker的模板路径 -->
	<bean id="freemarkerConfiguration"
		class="org.springframework.beans.factory.config.PropertiesFactoryBean">
		<property name="location" value="classpath:freemarker.properties" />
	</bean>

	<bean id="freemarkerConfig"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<!--property name="freemarkerSettings" ref="freemarkerConfiguration"/ -->
		<property name="templateLoaderPath">
			<value>/WEB-INF/ftl/</value>
		</property>
		<property name="freemarkerVariables">
			<map>
				<entry key="xml_escape" value-ref="fmXmlEscape" />
			</map>
		</property>
	</bean>
	<bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape" />
	<!-- 配置freeMarker视图解析器 -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
		<property name="viewClass"
			value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
		<property name="contentType" value="text/html; charset=utf-8" />
		<property name="cache" value="true" />
		<property name="prefix" value="" />
		<property name="suffix" value=".ftl" />
		<property name="order" value="1" />

	</bean>
</beans>

 4,applicationContent.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:security=" http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
                     http://www.springframework.org/schema/beans/spring-beans.xsd
                     http://www.springframework.org/schema/tx
                     http://www.springframework.org/schema/tx/spring-tx.xsd
                     http://www.springframework.org/schema/aop
                     http://www.springframework.org/schema/aop/spring-aop.xsd
                     http://www.springframework.org/schema/security 
    				 http://www.springframework.org/schema/security/spring-security-3.0.xsd"
                     >
                     
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<value>classpath*:database.properties</value>
		</property>
	</bean>                   
	
	<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName">
			<value>${ds4.jdbc.driverClassName}</value>
		</property>
		<property name="url">
			<value>${ds4.jdbc.url}</value>
		</property>
		<property name="username">
			<value>${ds4.jdbc.username}</value>
		</property>
		<property name="password">
			<value>${ds4.jdbc.password}</value>
		</property>
	</bean>
	
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		  <constructor-arg ref="dataSource"></constructor-arg>
 	</bean>




	<bean id="txManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<tx:advice id="txAdvice" transaction-manager="txManager">
		<tx:attributes>
			<tx:method name="get*" propagation="NOT_SUPPORTED" read-only="true" />
			<tx:method name="find*" propagation="NOT_SUPPORTED" read-only="true" />
			<tx:method name="list*" propagation="NOT_SUPPORTED" read-only="true" />
			<tx:method name="query*" propagation="NOT_SUPPORTED" read-only="true" />
			<tx:method name="*" propagation="REQUIRED" />
		</tx:attributes>
	</tx:advice>

	<aop:config>
		<aop:pointcut id="allManagerMethod"
			expression="execution(public * com.ywrj.lmsj.service..*.*(..))" />
		<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice" />
	</aop:config> 




</beans>

 

 

5,这个是控制器 controller

package com.ywrj.lmsj.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ywrj.lmsj.domain.Users;
import com.ywrj.lmsj.service.UsersService;
import com.ywrj.lmsj.utils.FreeMarkerUtil;

@Controller
@RequestMapping(value="/users/*")
public class UsersController {
    
	@Resource
	private UsersService userService;
	
	
	@RequestMapping(method=RequestMethod.GET)
	public String user(@ModelAttribute Users user, Model model){
		Users users = userService.findUserById(1);
		model.addAttribute("user",users);
//		Map<String,Object> root=new HashMap<String, Object>();
//		root.put("user", users);
//		String templatesPath="E:/android/workspace/lmsj/WebContent/user";
//		String templateFile="/user.ftl";
//		String htmlFile=templatesPath+"/user.html";
//		FreeMarkerUtil.analysisTemplate(templatesPath,templateFile,htmlFile,root);
		return "/user";
	}
}

 

6,附带项目源文件,jar包太大,就不上传了,有需要了联系我就行。扣扣:254853183

 

惊鸿

 


 

 

  • 大小: 45.2 KB
2
0
分享到:
评论
1 楼 yidao620c 2012-03-14  

相关推荐

    spring mvc, tiles, freemarker集成

    NULL 博文链接:https://haiker.iteye.com/blog/969715

    spring3.0MVC中文教程.pdf

    Spring MVC是Spring的框架的Web组件。 它提供了丰富的功能,为建设强大的Web应用程序。 Spring MVC框架的架构,并在这样的高度可配置的方式,... 喜欢速度与其他视图技术集成,Freemarker的,Excel或PDF现在也有可能。

    maven+springmvc+spring+hibernate+freemarker

    maven管理项目+springmvc+spring+hibernate+freemarker 集成框架。其中注解格式清晰,hibernate进行了代码封装,对开发效率有了提高,对异常进行了封装。freemarker也有优化,参考common包下。对日期工具类有各种...

    基于Spring MVC的web框架 1.1.11

    # demoWeb 一个基于SpringMVC的web框架 ...集成Spring Cache,FastJson Spring Cache增加redis缓存实现 Mybatis使用二级缓存,增加redis实现 增加reactJs 增加Mybatis插件pageHelper,Mapper doc内有相关文档

    springboot集成spring mvc,mybatis

    springboot集成spring mvc,mybatis的一个工程demo。maven工程。前端使用freemarker模板。数据库使用mysql。例子要跑起来了,可以添加下面数据库表结构: DROP TABLE IF EXISTS `sys_user`; CREATE TABLE `sys_...

    Spring4MVC+Hibernate4+Freemarker+Ehcache+EASYUI

    Spring4MVC+Hibernate4+Freemarker+Ehcache+EasyUi整合,里面包含数据库,数据库使用的是Mysql

    spring3.0MVC中文教程

    Spring MVC是Spring的框架的Web组件。 它提供了丰富的功能,为建设强大的Web应用程序。 Spring MVC框架的架构,并在这样的高度可配置的方式,... 喜欢速度与其他视图技术集成,Freemarker的,Excel或PDF现在也有可能。

    spring mvc 3.2 参考文档

    您可以直接与基于呈现技术的模板 (如 JSP、 Velocity和 Freemarker )集成或直接生成 XML、 JSON、 Atom和许多其他类型的内容。模型map被转化为合适的格式,如JSP request attributes或是 Velocity template model。

    spring3.0 MVC 中文教程

    Spring MVC是Spring的框架的Web组件。 它提供了丰富的功能,为建设强大的Web应用程序。 Spring MVC框架的架构,并在这样的高度可配置的方式,... 喜欢速度与其他视图技术集成,Freemarker的,Excel或PDF现在也有可能。

    Spring3 MVC

    Spring MVC是Spring的框架的Web组件。 它提供了丰富的功能,为建设强大的Web应用程序。 Spring MVC框架的架构,并在这样的高度可配置的方式,... 喜欢速度与其他视图技术集成,Freemarker的,Excel或PDF现在也有可能。

    springmvc-mybatis-freemarker:Spring MVC + Mybatis + Freemarker

    GS Spring MVC + Mybatis + Freemarker集成

    spring3.0_MVC之中文教程

    Spring MVC是Spring的框架的Web组件。 它提供了丰富的功能,为建设强大的Web应用程序。 Spring MVC框架的架构,并在这样的高度可配置的方式,每... 喜欢速度与其他视图技术集成,Freemarker的,Excel或PDF现在也有可能

    jersey2+freemarker+spring3

    基于这个jar文件库,可以完成jersey2+freemarker+spring3的集成,实现web应用,避开spring mvc的安全隐患。这里的jersey2的版本是2.25.1. 相关如何使用,可以参考我的博客:...

    基于java的企业级应用开发:Spirng MVC入门.ppt

    11.1 Spring MVC概述 Spring MVC是Spring提供的一个实现了Web MVC设计模式的轻量级Web框架。它与Struts2框架一样,都属于MVC框架,但其使用和性能等方面比Struts2更加优异。 11.1 Spring MVC概述 是Spring框架的一...

    zo-spring-boot:从零到一 —— 将一些有趣的技术方案与 Spring Boot 集成(如 Shiro、Spring Data JPA、Spring MVC、Tiles、Thymeleaf、Bootstrap 等)

    zo-spring-bootFrom zero to one with Spring Boot###roadmap权限:Shiro (Done)UI:SB Admin 2(Based of Bootstrap 3) (TODO)数据库:hsqldb (Done)持久化:Spring Data JPA (Done)MVC:Spring MVC (Done)Template ...

    sample-java-spring-genericdao:使用 Spring MVC 4.1、Hibernate 4.3 + Generic DAO、Spring Security、Freemarker 的项目示例

    目标是展示一个使用 Spring 与 Hibernate 集成的安全 MVC 应用程序,并使用 Generic DAO 框架抽象 DAO 层。 跑前小贴士: 将项目作为现有 Maven 导入(由于父项,您必须两次更新项目) 数据库文件 (DemoDB.rar) ...

    基于SpringMVC的一个web框架

    redis 加锁,redis升级成2.8.2 freemarker工具类 1.1.6 spring websocket 实现在线聊天 maven升级jdk1.8 jetty9.2.4 web升级jdk1.7 tomcat7 1.1.7(maven only) 包名修改 从此不再支持web版本,只支持maven版本 ...

    spring jar 包详解

    可以找到使用Spring ApplicationContext特性时所需的全部类,JDNI所需的全部类,UI方面的用来与模板(Templating)引擎如 Velocity、FreeMarker、JasperReports集成的类,以及校验Validation方面的相关类。...

Global site tag (gtag.js) - Google Analytics