It is responsible to manage the flow of the spring mvc application. The @Controller annotation is used to mark the class as the controller in Spring 3. The @RequestMapping annotation is used to map the request url. It is applied on the method. Now Let us understand Spring MVC flow with hello world application Example. First of all, we.
Spring MVC comes with AbstractExcelView class to export data to Excel file via Apache POI library. In this tutorial, it show the use of AbstractExcelView class in Spring MVC application to export data to Excel file for download.
1. Apache POI
Get the Apache POI library to create the excel file.
2. Controller
A controller class, generate dummy data for demonstration, and get the request parameter to determine which view to return. If the request parameter is equal to “EXCEL”, then return an Excel view (AbstractExcelView).
File : RevenueReportController.java
3. AbstractExcelView
Create an Excel view by extends the AbstractExcelView class, and override the buildExcelDocument() method to populate the data to Excel file. The AbstractExcelView is using the Apache POI API to create the Excel file detail.
Spring Mvc Download File
For detail about how to use the Apache POI , please refer to Apache POI documentation
File : ExcelRevenueReportView.java
Alternatively, you can use the AbstractJExcelView, which is using the JExcelAPI to create the same Excel view, see this AbstractJExcelView example.
4. Spring Configuration
Create a XmlViewResolver for the Excel view.
File : spring-excel-views.xml
5. Demo
URL : http://localhost:8080/SpringMVC/revenuereport.htm?output=excel
It generates an Excel file for user to download.
Download Source Code
References
About the Author
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.Comments
Here, we will learn how to handle a form data in spring MVC without using database. Here, we will use @Controler, @RequestMapping and @ModelAttribute annotations.
To display the input form, we are going to use <form:form> tag of spring framework. Let's see a simple example to store form data in a model object and display data of a list.
Required Jar files
To run this example, you need to load:
- Spring Core jar files
- Spring Web jar files
Spring Mvc Javatpoint
Output
Download spring MVC example
We have created this application in MyEclipse IDE which already provides the jar files. If you use eclipse or other IDE's, you need to load the jar file for spring MVC.
Comments are closed.