问题
I have spring boot app:
@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;
}
...
Config:
@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");
}
}
Security:
@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();
}
My Report Blank_A4_2 firstly work fine, and it shows me Report. I access it so: http://myserverIP/testReport4_2
But if I go to any static page, in my project, for example http://myserverIP/test.html and then if I visit back my report, it won't show anything and I will see in java console next:
class path resource [Blank_A4_2.html.jasper] cannot be opened because it does not exist
Му report name in resource folder is Blank_A4_2.jasper, why spring boot adds prefix "html" ?
回答1:
My question is similar this one JasperReportsViewResolver add .html after some time. And as suggested in it, I added produces = "application/pdf;charset=UTF-8" like this:
@RequestMapping(value = "/testReport4_2", method = RequestMethod.GET, produces = "application/pdf;charset=UTF-8")
to the controller method and this problem solved.
来源:https://stackoverflow.com/questions/43508899/spring-modelandview-issue-adding-html-prefix