[英]spring ModelAndView issue - adding “html” prefix
我有春季启动应用程序:
@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”?
我的问题类似于JasperReportsViewResolver在一段时间后添加.html 。 并按照建议,我像下面这样添加了Produces =“ application / pdf; charset = UTF-8”:
@RequestMapping(value = "/testReport4_2", method = RequestMethod.GET, produces = "application/pdf;charset=UTF-8")
到控制器方法,此问题得以解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.