powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / JasperReports интеграция в Spring MVC
5 сообщений из 5, страница 1 из 1
JasperReports интеграция в Spring MVC
    #38295651
Kail
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Здравствуйте!
Нужна помощь по интеграции JasperReports(конкретно 5.1) в проект Hibernate+Spring MVC(конкретно Spring 3.1).
...
Рейтинг: 0 / 0
JasperReports интеграция в Spring MVC
    #38295671
vimba
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
А в чем возникли сложности и чем вывод отчетов отличается от вывода любой другой ифнормации?
...
Рейтинг: 0 / 0
JasperReports интеграция в Spring MVC
    #38295683
Kail
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
vimba,
Для начала хотелось бы узнать о XML настройках и как использовать JasperReportsMultiFormatView,
нужен ли JasperReportsViewResolver.
...
Рейтинг: 0 / 0
JasperReports интеграция в Spring MVC
    #38296308
Kail
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Кое-что удалось.

jasper-views.xml:

Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
		http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/util
		http://www.springframework.org/schema/util/spring-util.xsd">

    <bean id="pdfReport"
          class="org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView"
          p:url="resources/reports/report1.jrxml"
          p:reportDataKey="datasource" />


    <bean id="xlsReport"
          class="org.springframework.web.servlet.view.jasperreports.JasperReportsXlsView"
          p:url="resources/reports/report1.jrxml"
          p:reportDataKey="datasource" />


    <bean id="htmlReport"
          class="org.springframework.web.servlet.view.jasperreports.JasperReportsHtmlView"
          p:url="resources/reports/report1.jrxml"
          p:reportDataKey="datasource" />


    <bean id="csvReport"
          class="org.springframework.web.servlet.view.jasperreports.JasperReportsCsvView"
          p:url="resources/reports/report1.jrxml"
          p:reportDataKey="datasource"/>
</beans>



servlet-context.xml:

Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:beans="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

	<annotation-driven />

	<beans:import resource="jasper-views.xml"/>

	<resources mapping="/resources/**" location="/resources/" />
  
  <beans:bean class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
  		<beans:property name="order" value="0"/>
		<beans:property name="basename" value="views" />
	</beans:bean>
	
  	
  <beans:bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
		<beans:property name="definitions" value="/WEB-INF/views/tiles/tiles_templates.xml" />
	</beans:bean>
	
 	<beans:bean class="org.springframework.web.servlet.view.XmlViewResolver">
        <beans:property name="location" value="/WEB-INF/spring/appServlet/jasper-views.xml"/>
        <beans:property name="order" value="1"/>
    </beans:bean>
	
	 <context:component-scan base-package="kz.eec.erp" />
</beans:beans>



Ну и собственно контроллер:

Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
import java.lang.reflect.InvocationTargetException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import kz.eec.erp.service.UseService;
import kz.eec.erp.view.DigDataJasperReportsView;
import kz.eec.erp.view.UserView;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@Scope("session")
@RequestMapping("/reports")
public class JasperController {

	@Autowired
	private UseService useService;

	public void setUseService(UseService useService) {
		this.useService = useService;
	}
	
	@RequestMapping(method = RequestMethod.GET , value = "reportCSV")
    public ModelAndView generateCSVReport(ModelAndView modelAndView) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException{
        Map<String,Object> parameterMap = new HashMap<String,Object>();
        List<UserView> usersList = this.useService.getListUser();
        JRDataSource JRdataSource = new JRBeanCollectionDataSource(usersList);
        parameterMap.put("datasource", JRdataSource);
        modelAndView = new ModelAndView("csvReport", parameterMap);
        return modelAndView;
    }
	
	@RequestMapping(method = RequestMethod.GET , value = "reportHTML")
    public ModelAndView generateHTMLReport(ModelAndView modelAndView) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException{
        Map<String,Object> parameterMap = new HashMap<String,Object>();
        List<UserView> usersList = this.useService.getListUser();
        JRDataSource JRdataSource = new JRBeanCollectionDataSource(usersList);
        parameterMap.put("datasource", JRdataSource);
        modelAndView = new ModelAndView("htmlReport", parameterMap);
        return modelAndView;
    }
	
	@RequestMapping(method = RequestMethod.GET , value = "reportPDF")
    public ModelAndView generatePDFReport(ModelAndView modelAndView) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException{
        Map<String,Object> parameterMap = new HashMap<String,Object>();
        List<UserView> usersList = this.useService.getListUser();
        JRDataSource JRdataSource = new JRBeanCollectionDataSource(usersList);
        parameterMap.put("datasource", JRdataSource);
        modelAndView = new ModelAndView("pdfReport", parameterMap);
        return modelAndView;
    }

	@RequestMapping(method = RequestMethod.GET , value = "reportXLS")
    public ModelAndView generateXLSReport(ModelAndView modelAndView) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException{
        Map<String,Object> parameterMap = new HashMap<String,Object>();
        List<UserView> usersList = this.useService.getListUser();
        JRDataSource JRdataSource = new JRBeanCollectionDataSource(usersList);
        parameterMap.put("datasource", JRdataSource);
        modelAndView = new ModelAndView("xlsReport", parameterMap);
        return modelAndView;
    }	
}



Но хотелось бы более элегантное решение с использованием JasperReportsMultiFormatView.
Откликнитесь профи.
...
Рейтинг: 0 / 0
JasperReports интеграция в Spring MVC
    #38315337
Kail
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
"Хороший форум" за 3 недели 1 ответ и тот не о чём.
...
Рейтинг: 0 / 0
5 сообщений из 5, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / JasperReports интеграция в Spring MVC
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]