我是春季配置的新手,有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;
}
答案 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;
}
其中: