springmvc实现导出数据excel
最近在项目中要实现将数据导出为excel的功能,研究了下目前springmvc框架下excel导出的方式,在spring 4.3中使用AbstractXlsView来实现,AbstractExcelView已被弃用;但这里介绍的是直接用apache poi实现的一种方式。
model如下
package red.itech.blog.dao.model; import java.util.Date; /** * Created by you on 16/10/28. */ public class Blog { private String author; private Date createdAt; private String title; private long count; public Blog(){} public Blog(String author, Date createdAt, String title, long count){ this.author = author; this.count = count; this.createdAt = createdAt; this.title =title; } public void setAuthor(String author) { this.author = author; } public void setCreatedAt(Date createdAt) { this.
Spring+Mybatis+Velocity项目搭建
一、开发工具
JDK 1.8.0_91 Intellij IDEA 15.0.6 Mysql 5.5.44 Maven 3 二、新建工程
新建Maven工程,不选Create from archtype提供的工程模版,为了学习从头开始配置工程,点击next设置工程坐标,然后一路到finish。 <groupId>red.itech</groupId> <artifactId>blogDemo</artifactId> <version>1.0-SNAPSHOT</version> 如果使用git开发,可以新建.gitignore文件,使git忽略idea自动生成的文件(.ignore插件可以帮助生成.gitignore),项目git初始化
# Created by .ignore support plugin (hsz.mobi) .gitignore ### OSX template *.DS_Store # IntelliJ project files .idea *.iml out target gen### Java template *.class # Package Files # *.jar *.war *.ear 三、Spring MVC
编辑pom.xml添加Spring MVC、servlet依赖如下:
<dependencies> <!-- spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.3.3.RELEASE</version> </dependency> <dependency> <groupId>org.