[springmvc]rendering view

1. DispatcherServlet render Views

  Alternative to having a HttpMessageConverter write the response body

  Designed for generating text/* content from a template

    @RequestMapping(value="html", method=RequestMethod.GET)
public String prepare(Model model) {
model.addAttribute("foo", "bar");
model.addAttribute("fruit", "apple");
return "views/html";
}

2. Model parameter to export data to the view

  Call model.addAttribute(“name”, value) for each item to export

    @RequestMapping(value="/viewName", method=RequestMethod.GET)
public void usingRequestToViewNameTranslator(Model model) {
model.addAttribute("foo", "bar");
model.addAttribute("fruit", "apple");
}

3. Select the view by to render by returning a String

  Do not use @ResponseBody annotation in this case

  Configured ViewResolver maps name to a View instance

    @RequestMapping(value="pathVariables/{foo}/{fruit}", method=RequestMethod.GET)
public String pathVars(@PathVariable String foo, @PathVariable String fruit) {
// No need to add @PathVariables "foo" and "fruit" to the model
// They will be merged in the model before rendering
return "views/html";
}

4. Default ViewResolver forwards to internal servlet resources

  Many other options: JSP, Tiles, Freemarker, Velocity, iText PDF, JExcel, Jasper Reports, and XSLT are all supported out of the box

  Can also write your own View integrations

    @RequestMapping(value="dataBinding/{foo}/{fruit}", method=RequestMethod.GET)
public String dataBinding(@Valid JavaBean javaBean, Model model) {
// JavaBean "foo" and "fruit" properties populated from URI variables
return "views/dataBinding";
}





转载于:https://www.cnblogs.com/lavieenrose/archive/2012/03/26/2417295.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值