我有春季启动应用程序:
@RestController
@EnableAutoConfiguration
@Scope("prototype")
public class BillingController {
@RequestMapping(value = "/testReport4_2", method = RequestMethod.GET)
public ModelAndView helloReport(ModelMap modelMap, ModelAndView modelAndView) {
JRDataSource datasource = new JRBeanCollectionDataSource(payordMng.getPayordGrpAll(), true);
modelMap.put("datasource", datasource);
modelMap.put("format", "pdf");
modelAndView = new ModelAndView("Blank_A4_2", modelMap);
return modelAndView;
}
...
配置:
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/home").setViewName("home");
registry.addViewController("/hello").setViewName("hello");
registry.addViewController("/login").setViewName("login");
}
}
安全性:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
DataSource dataSource;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/test.html", "/home", "/chrglsk", "/chrgall").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
http
.csrf().disable();
}
我的报告Blank_A4_2首先正常工作,并向我显示报告。 我这样访问它:http://myserverIP/testReport4_2
但是,如果我去任何静态页面,例如在我的项目中 http://myserverIP/test.html然后如果我回访我的报告, 它不会显示任何内容,我将在下一个java控制台中看到:
class path resource [Blank_A4_2.html.jasper] cannot be opened because it does not exist
资源文件夹中的报告名称为Blank_A4_2.jasper,为什么spring boot添加 前缀“html”?
答案 0 :(得分:0)
我的问题类似于JasperReportsViewResolver add .html after some time。正如其中所建议的那样,我补充道 produce =“application / pdf; charset = UTF-8” 像这样:
@RequestMapping(value = "/testReport4_2", method = RequestMethod.GET, produces = "application/pdf;charset=UTF-8")
到控制器方法,这个问题解决了。