SpringMVC环境的搭建在这里就不多说了,我们这节主要是FreeMarker与SpringMVC整合
首先,在springmvc的配置文件普通视图之前,加入freemarker的视图
fre-servlet.xml
<!-- 一定要放在viewResolver的前面,这样就先去找freemarker的 -->
<bean id="freemarkerConfig"
class="org.springframework.web.servlet
.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/ftl/"/>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet
.view.freemarker.FreeMarkerViewResolver">
<property name="cache" value="true"/>
<property name="prefix" value=""/>
<property name="suffix" value=".ftl"/>
<property name="contentType" value="text/html; charset=UTF-8"/>
</bean>
<bean
class="org.springframework.web.servlet
.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
控制器HelloController
package org. fre.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController {
@RequestMapping("/hello")
public String hello(Model model) {
model.addAttribute("username", "张三");
return "hello";
}
@RequestMapping("/world")
public String helloworld(Model model) {
model.addAttribute("username","李四");
return "world";
}
}
在WEB-INF/jsp目录下有一个world.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
${username }
</body>
</html>
在WEB-INF/ftl目录下有
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>${username}</h1>
</body>
</html>
启动服务,
访问http://localhost:8080/hello时,显示张三
访问http://localhost:8080/world时,显示李四
到此就整合成功了
SpringMVC环境的搭建在这里就不多说了,我们这节主要是FreeMarker与SpringMVC整合
首先,在springmvc的配置文件普通视图之前,加入freemarker的视图
fre-servlet.xml
01 |
<!-- 一定要放在viewResolver的前面,这样就先去找freemarker的 --> |
03 |
<bean id="freemarkerConfig" |
05 |
class="org.springframework.web.servlet |
07 |
.view.freemarker.FreeMarkerConfigurer"> |
09 |
<property name="templateLoaderPath" value="/WEB-INF/ftl/"/> |
13 |
<bean id="viewResolver" |
15 |
class="org.springframework.web.servlet |
17 |
.view.freemarker.FreeMarkerViewResolver"> |
19 |
<property name="cache" value="true"/> |
21 |
<property name="prefix" value=""/> |
23 |
<property name="suffix" value=".ftl"/> |
25 |
<property name="contentType" value="text/html; charset=UTF-8"/> |
31 |
class="org.springframework.web.servlet |
33 |
.view.InternalResourceViewResolver"> |
35 |
<property name="viewClass" |
37 |
value="org.springframework.web.servlet.view.JstlView"/> |
39 |
<property name="prefix" value="/WEB-INF/jsp/" /> |
41 |
<property name="suffix" value=".jsp" /> |
控制器HelloController
01 |
package org. fre.controller; |
05 |
import org.springframework.stereotype.Controller; |
07 |
import org.springframework.ui.Model; |
09 |
import org.springframework.web.bind.annotation.RequestMapping; |
15 |
public class HelloController { |
17 |
@RequestMapping("/hello") |
19 |
public String hello(Model model) { |
21 |
model.addAttribute("username", "张三"); |
27 |
@RequestMapping("/world") |
29 |
public String helloworld(Model model) { |
31 |
model.addAttribute("username","李四"); |
在WEB-INF/jsp目录下有一个world.jsp
01 |
<%@ page language="java" contentType="text/html; charset=UTF-8" |
03 |
pageEncoding="UTF-8"%> |
11 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
13 |
<title>Insert title here</title> |
在WEB-INF/ftl目录下有
05 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
07 |
<title>Insert title here</title> |
启动服务,
访问http://localhost:8080/hello时,显示张三
访问http://localhost:8080/world时,显示李四
到此就整合成功了
- 使用Spring整合Quartz轻松完成定时任务
一.背景 上次我们介绍了如何使用Spring Task进行完成定时任务的编写,这次我们使用Spring整合Quartz的方式来再一次实现定时任务的开发,以下奉上开发步骤及注意事项等. 二.开发环境及必 ...
- 【Java EE 学习 53】【Spring学习第五天】【Spring整合Hibernate】【Spring整合Hibernate、Struts2】【问题:整合hibernate之后事务不能回滚】
一.Spring整合Hibernate 1.如果一个DAO 类继承了HibernateDaoSupport,只需要在spring配置文件中注入SessionFactory就可以了:如果一个DAO类没有 ...
- spring整合hibernate的详细步骤
Spring整合hibernate需要整合些什么? 由IOC容器来生成hibernate的sessionFactory. 让hibernate使用spring的声明式事务 整合步骤: 加入hibern ...
- Spring整合Ehcache管理缓存
前言 Ehcache 是一个成熟的缓存框架,你可以直接使用它来管理你的缓存. Spring 提供了对缓存功能的抽象:即允许绑定不同的缓存解决方案(如Ehcache),但本身不直接提供缓存功能的实现.它 ...
- spring整合hibernate
spring整合hibernate包括三部分:hibernate的配置.hibernate核心对象交给spring管理.事务由AOP控制 好处: 由java代码进行配置,摆脱硬编码,连接数据库等信息更 ...
- MyBatis学习(四)MyBatis和Spring整合
MyBatis和Spring整合 思路 1.让spring管理SqlSessionFactory 2.让spring管理mapper对象和dao. 使用spring和mybatis整合开发mapper ...
- Mybatis与Spring整合,使用了maven管理项目,作为初学者觉得不错,转载下来
转载自:http://www.cnblogs.com/xdp-gacl/p/4271627.html 一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: mvn archetype ...
- Spring整合HBase
Spring整合HBase Spring HBase SHDP § 系统环境 § 配置HBase运行环境 § 配置Hadoop § 配置HBase § 启动Hadoop和HBase § 创建Maven ...
- Spring整合Ehcache管理缓存(转)
目录 前言 概述 安装 Ehcache的使用 HelloWorld范例 Ehcache基本操作 创建CacheManager 添加缓存 删除缓存 实现基本缓存操作 缓存配置 xml方式 API方式 S ...
随机推荐
- 启动Eclipse之后,关闭Maven自动更新
问题描述: 因为架包的修改,所以Maven需要更新,一启动Eclipse之后,自动更新,由于Maven的架包很多download不下来,就一直卡着的样子,很长时间,什么都做不了. 解决办法: Ecli ...
- 基于 DirectX11 的 MMDViewer 04-渲染目标视图和多视口
上篇文章给出了一个简单并且可以运行的渲染框架,接下来将介绍框架中的渲染管线构成. 1.创建渲染管线 在你创建完一个窗口后,接着便要创建渲染管线,使用的函数是 D3D11CreateDeviceAndS ...
- 打开当前目录的其他exe
STARTUPINFO si; PROCESS_INFORMATION pi; memset(&si, , sizeof(si)); si.cb = sizeof(STARTUPINFO); ...
- LightGBM
1.简介 lightGBM包含两个关键点:light即轻量级,GBM 梯度提升机 LightGBM 是一个梯度 boosting 框架,使用基于学习算法的决策树.它可以说是分布式的,高效的,有以下优势 ...
- quartz简介
- kubenetes dns
E0228 07:32:28.912833 1 reflector.go:201] k8s.io/dns/pkg/dns/dns.go:147: Failed to list *v1.En ...
- 使用Django完成CRM管理系统
CRM介绍: CRM即客户关系管理,是指企业用CRM技术来管理与客户之间的关系.在不同场合下,CRM可能是一个管理学术语,可能是一个软件系统.通常所指的CRM,指用计算机自动化分析销售.市场营销.客户 ...
- 在子页面使用layer弹出层时只显示遮罩层,不显示弹出框问题
最近子页面使用layer弹出层时只显示遮罩层,不显示弹出框,这个问题搞了很久,最后才发现,在子页面上使用弹出框时,如果只使用layer.alert()或者layer.open()时,会默认在当前页面弹 ...
- 274. H-Index论文引用量
[抄题]: Given an array of citations (each citation is a non-negative integer) of a researcher, write a ...
- 16-多线程爬取糗事百科(python+Tread)
https://www.cnblogs.com/alamZ/p/7414020.html 课件内容 #_*_ coding: utf-8 _*_ ''' Created on 2018年7月17日 ...