如何在Spring MVC中使用Tiles配置jasper / jrxml报告并查看Resolver

时间:2015-01-11 08:54:37

标签: java spring jasper-reports tiles

我是春季配置的新手,有jasper报告, 我在设置磁贴配置时调用jrxml的正确文件时遇到问题。

@Bean
public InternalResourceViewResolver setupViewResolver() {
    InternalResourceViewResolver resolver = new InternalResourceViewResolver ();
    resolver.setPrefix("/WEB-INF/views/");
    resolver.setSuffix(".jsp");
    resolver.setOrder(2);
    resolver.setViewClass(JstlView.class);
    return resolver;
}

@Bean
public UrlBasedViewResolver urlBasedViewResolver() {
    UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
    viewResolver.setViewClass(TilesView.class);
    viewResolver.setOrder(1);
    return viewResolver;
}

调用该文件时。它将.jsp附加到文件的末尾。

我尝试了这个,但仍然不起作用:

@Autowired
ServletContext servletContext;

@Bean
public XmlViewResolver getXmlViewResolver() {
    XmlViewResolver resolver = new XmlViewResolver();
    Resource resource = new ClassPathResource("classpath:reports/testReport1.jrxml");
    resolver.setLocation(resource);
    resolver.setOrder(0);
    return resolver;
}

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

@Bean
public JasperReportsViewResolver getJasperReportsViewResolver() {
    JasperReportsViewResolver resolver = new JasperReportsViewResolver();
    resolver.setPrefix("resources/jasperreports/");
    resolver.setSuffix(".jasper");
    resolver.setReportDataKey("datasource");
    resolver.setViewNames(new String[] {"Report_*"});
    resolver.setViewClass(JasperReportsMultiFormatView.class);
    resolver.setOrder(0);
    return resolver;
}

其中:

  • “resources / jasperreports /”是您拥有所有报告的文件夹。
  • “。jasper”是编译的jasper报告的扩展名。
  • new String [] {“Report_ *”}是jasper报告的前缀。