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





  • 相关阅读:
    让UIButton在按下时没有高亮效果
    如何让View一直沿z轴旋转
    App 应用通过网页打开 App Store
    Xcode/iOS: 如何判断代码运行在DEBUG还是RELEASE模式下?
    freemyapps 推荐链接
    [转]Git使用基础篇
    [转]anchorPoint 锚点解析
    Mac下如何看Swf文件
    Xcode 5: 将新项目同步到Svn上
    Shell 启动java程序
  • 原文地址:https://www.cnblogs.com/lavieenrose/p/2417295.html
Copyright © 2011-2022 走看看