设为首页 加入收藏

TOP

Spring MVC整合Freemarker基于注解方式
2014-11-24 08:12:39 来源: 作者: 【 】 浏览:1
Tags:Spring MVC 整合 Freemarker 基于 注解 方式

基于网络改进为:最正常版本


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


class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">





class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">



0
UTF-8
0.##########
yyyy-MM-dd HH:mm:ss
true
ignore




6.Controller建立


import javax.servlet.http.HttpServletRequest;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class SpringMvcController {


@RequestMapping(value="/welcome",method={RequestMethod.GET})
public ModelAndView getFirstPage(HttpServletRequest request) {
//welcom就是视图的名称(welcom.ftl)
ModelAndView mv = new ModelAndView("welcom");
mv.addObject("name", "My First Spring Mvc");
return mv;
}
}


在url上敲http://localhost:8080/welcome就会到WEB-INF/view/welcom.ftl页面渲染数据

7.welcom.ftl页面






Insert title here


Hello ${name}


页面出来的效果:


Hello My First Spring Mvc





】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Struts 2.x避免表单的重复提交—.. 下一篇ActiveMQ消息的可靠性机制

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C语言中,“指针”用 (2025-12-26 15:20:18)
·在c语言的指针运算中 (2025-12-26 15:20:15)
·C语言-函数指针与函 (2025-12-26 15:20:12)
·求navicat for mysql (2025-12-26 13:21:33)
·有哪位大哥推荐一下m (2025-12-26 13:21:30)