zoukankan      html  css  js  c++  java
  • [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";
    }





  • 相关阅读:
    Flex的DateChooser组件中文显示方法
    FLEX XML XMLList XMLListCollection ArrayCollection相互转换
    开机电脑cpu占用100%
    FLEX 动态绑定chart 数据
    FLEX 数组 转化成 xml
    FLEX 通过url 得到网页内容 xml通信
    FLEX 时间计算
    FlEX 如何调试
    unix,linux,windows 哪个更好,更适合做服务器
    FLEX httpService 用法介绍
  • 原文地址:https://www.cnblogs.com/lavieenrose/p/2417295.html
Copyright © 2011-2022 走看看