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

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

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

关键的实现过程:

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

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

 

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>

SpringMVC(二七) 自定义视图的更多相关文章

  1. SpringMvc配置自定义视图

    1.在dispatcherServlet-servlet.xml配置自定义视图 <!-- 配置视图 BeanNameViewResolver 解析器: 使用视图的名字来解析视图 --> & ...

  2. SpringMVC:自定义视图及其执行过程

    一:自定义视图 1.自定义一个实现View接口的类,添加@Component注解,将其放入SpringIOC容器 package com.zzj.view; import java.io.PrintW ...

  3. SpringMVC系列(九)自定义视图、重定向、转发

    一.自定义视图 1. 自定义一个视图HelloView.java,使用@Component注解交给Spring IOC容器处理 package com.study.springmvc.views; i ...

  4. SpringMVC自定义视图Excel视图和PDF视图

    SpringMVC自定义视图 Excel视图和PDF视图 SpringMVC杂记(十一) 使用Excel视图 Spring MVC 视图解析器(ViewResolver ) java实现导出excel ...

  5. SpringMVC自定义视图 Excel视图和PDF视图

    一.自定义视图-Excel视图 1.Maven依赖 引入POI <dependency> <groupId>org.apache.poi</groupId> < ...

  6. 自定义视图(SpringMVC)

    一.首先理解视图的解析过程 1)请求处理方法执行完成后,最终返回一个 ModelAndView 对象. ModelAndView 对象,它包含了逻辑名(访问URL)和模型对象(javaBean数据)的 ...

  7. springmvc自定义视图

    自定义视图 可以整合jfreechart.excel @RequestMapping("/testView") public String testView(){ System.o ...

  8. springMVC学习 七 视图解析器

    在springMVC中,如果不配置视图解析器,会走默认的视图解析器,但是有时候配置视图解析器,还有一定的作用 <bean id="viewResolver" class=&q ...

  9. 基于BeanNameViewResolver解析器,自定义视图

    概述 基于spring-mvc自定义视图,以BeanNameViewResolver作为解析器,以满足特殊需求. 本文以输出多个pdf文件的压缩文件,供前台下载的需求为例:但是不提供服务层实现. 实现 ...

随机推荐

  1. mongo数据库的各种查询语句示例

    左边是mongodb查询语句,右边是sql语句.对照着用,挺方便. db.users.find() select * from users db.users.find({"age" ...

  2. linux文件与目录管理笔记

    ### Linux文件与目录管理 ---------- 绝对路径: / 相对路径:不以/开头的 当前目录 . 上一个工作目录 - 用户主目录 ~ root账户的主目录是/root 其他用户是/home ...

  3. Nginx的进程模型及高可用方案(OpenResty)

    1. Nginx 进程模型简介 Nginx默认采用多进程工作方式,Nginx启动后,会运行一个master进程和多个worker进程.其中master充当整个进程组与用户的交互接口,同时对进程进行监护 ...

  4. linux 源码安装PHP

    解压: 解压完: configure: configure成功: make: make完成: 安装完成!!! 测试: 需要./bin/php来运行php 想要任何目录输入PHP就能使用php 方法一: ...

  5. laravel 统计数据

    //根据format字符串格式化date值.下列修饰符可以被用在format字符串中:  //%M 月名字(January……December)  //%W 星期名字(Sunday……Saturday ...

  6. wireless Penetration Testing & Honeypot and Mis-Association attacks

    重新记一遍 ,在捕获握手数据包的时候不容易获取,所以使用ARP请求.使用自己的无线网卡的地址发送请求,会容易使得无线开启端掉线,迫使重新连接. 1.使用命令   aireplay-ng -3 -b a ...

  7. Pychram 在model中修改class属性值后更新到Navicat Premium中

    一.pycharm数据更新的问题bug问题 1.在更改user_email字端属性后出现数据库信息无法更新到数据库,出现的bug原因是数据库修改了属性之后没有做migrate 和 makemigrat ...

  8. border画梯形

    <!doctype html><html lang="en"> <head>  <meta charset="UTF-8&quo ...

  9. Python GUI界面编程

    常用GUI框架 wxPython 安装wxPython pip install -U wxPython C:\Users> pip install -U wxPython Collecting ...

  10. Java 产生一个大于等于200,小于300的随机数,且是10的整数倍

    public class Random200_300 { public static void main(String[] args) { int r1 = 0; while (true) { r1 ...