• [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";
    }





  • 相关阅读:
    ubuntu12.04 安装opencv
    VC warning C4786
    su root 后还是不能使用useradd ,useradd 等命令
    C++数组
    C++多维数组
    Centos7 GUI卸载安装gnome
    linux离线安装软件(三)——Centos7以源码编译方式安装两个版本gcc
    yum和源码编译安装nginx
    Linux修改移动硬盘文件类型
    Django部署时STATIC/MEDIA配置
  • 原文地址:https://www.cnblogs.com/lavieenrose/p/2417295.html
Copyright © 2020-2023  润新知