Spring 3 - 以csv格式导出数据
我在数据库中有一些数据,希望能够将其导出到 CSV 文件并提供链接以便用户可以下载它。
Spring 3 是否为此提供了任何机制?
你知道我该怎么做吗?
I have some data in the DB and would like to be able to export it to a CSV file and provide a link so the user can download it.
Is there any mechanism provided by Spring 3 for this?
Do you know how could I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想构建 CSV 或任何文本文件视图应该很容易。以下是建议的步骤:
创建一个扩展
org.springframework.web.servlet.view.AbstractView
的视图类(您可以将其命名为CSVView
)覆盖
renderMergedOutputModel
如下(伪代码):之后,只需返回带有模型的 ModelAndView(带有
modelKey
的对象Whatever
)并在控制器。I guess it should be easy to build a CSV or any text file view. Here are suggested steps:
Create a View class (you can name it as
CSVView
) extendingorg.springframework.web.servlet.view.AbstractView
Override
renderMergedOutputModel
as follows (pseudo code):After that just return ModelAndView with model (object
Whatever
withmodelKey
) and view asCSVView
in the controller.