zoukankan      html  css  js  c++  java
  • SpringMVC(二七) 自定义视图

    可以参考博客http://www.cnblogs.com/parryyang/p/5683600.html,举例很清晰。

    对自定义的视图名称匹配不同的解析器进行解析。

    作用:自己定义视图,视图继承view类或者abstractExcelView或者abstractPdfView,将内容以Excel或者PDF格式显示。

    关键的实现过程:

    1. 创建excelView视图,继承AbstractXlsxView。

     参考如下代码,实现功能:从modelAndView中获取model数据,作为excel视图显示。   

     View Code

    2.创建控制器。

      参考如下代码,实现功能:访问相关URL时,直接去访问创建的excelView视图。

      

    复制代码
    package com.tiekui.springmvc.handlers;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Map;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.validation.Errors;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;
    
    import com.sun.org.apache.xpath.internal.operations.Mod;
    import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;
    import com.tiekui.springmvc.pojo.User;
    import com.tiekui.springmvc.views.excelView;
    
    @Controller
    public class ExcelViewTest {
    
        @RequestMapping("excelView")
        public ModelAndView excelViewTest(User user) {
            Map<String, Object> model = new HashMap<>();
            ArrayList<User> userlist = new ArrayList<>();
            userlist.add(user);
            model.put("userList", userlist);
            ModelAndView modelAndView = new ModelAndView(new excelView(),model);
            return modelAndView;
        }
        
    }
    复制代码

    3.访问视图index.jsp

      

    复制代码
        <form action="excelView">
        username : <input type="text" name="username" value="1">
        <br>
        password : <input type="password" name="password" value="1">
        <br>
        email : <input type="text" name="email" value="1">
        <br>
        age : <input type="text" name="age" value="1">
        <br>
        province : <input type="text" name="address.province" value="1">
        <br>
        city : <input type="text" name="address.city" value="1">
        <br>
        <input type="submit" value="PojoTest">
        </form>
    复制代码

    4.SpringMVC配置文件中必须添加以下内容: 

    <bean class="org.springframework.web.servlet.view.BeanNameViewResolver">
        <property name="order" value="0"></property>
    </bean>
  • 相关阅读:
    网格视图
    使用box-shadow 属性用来可以创建纸质样式卡片:
    css 按钮动画
    vue父组件向自定义组件传递参数过程
    vue中如何使用 v-model 实现双向数据绑定?
    vue中是如何实现响应键盘回车事件
    vue中如何实现 样式绑定?
    webpack require.Context功能作用
    Personal tips for success
    my blog frist
  • 原文地址:https://www.cnblogs.com/yuyu666/p/10136131.html
Copyright © 2011-2022 走看看