我用的是springmvc +mybatis+ireport
jasper-views.xml
<context:property-placeholder location="classpath:spring-views.properties" />
<bean id="htmlReport" p:reportDataKey="datasource"
class="org.springframework.web.servlet.view.jasperreports.JasperReportsHtmlView">
<property name="url" value="${dzxxsz}"></property>
<property name="exporterParameters">
<map>
<entry
key="net.sf.jasperreports.engine.JRExporterParameter.CHARACTER_ENCODING">
<value>UTF-8</value>
</entry>
<entry
key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN">
<value>false</value>
</entry>
<entry
key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR">
<value>false</value>
</entry>
</map>
</property>
</bean>
控制层:
@RequestMapping("/getpdfReport")
public ModelAndView doSalesReportPDF(ModelAndView modelAndView,HttpServletRequest request)
{
logger.debug("Received request to download PDF report");
MockDataFactory dataprovider = new MockDataFactory();
JRDataSource categoryData = dataprovider.getCategoriesData();
Map<String,Object> parameterMap = new HashMap<String,Object>();
List<TUser> list=this.userServiceI.getall();
List<JUser> list1=new ArrayList<JUser>();
for (TUser tUser : list) {
JUser j=new JUser();
BeanUtils.copyProperties(tUser, j);
list1.add(j);
}
JREmptyDataSource emptyData = new JREmptyDataSource();
parameterMap.put("datasource", new JRBeanCollectionDataSource(list1));
/*生成HTML文件 */ modelAndView = new ModelAndView("htmlReport", parameterMap); return modelAndView; }
spring-views.properties
Reporturl=/WEB-INF/reports/UserReport.jrxml
dzxxsz=/WEB-INF/reports/dzxxsz.jrxml