spring ModelAndView问题 - 添加“html”字首 [英] spring ModelAndView issue - adding "html" prefix
问题描述
我有春季启动应用程序:
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;
}
...
配置:
@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
My Report Blank_A4_2 firstly work fine, and it shows me Report. I access it so: http://myserverIP/testReport4_2
但如果我去任何静态页面,在我的项目中,例如
http:// myserverIP / test.html 然后如果我访问我的报告,
它将不显示任何内容,我将在下一个java控制台中看到:
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
资源文件夹中的报告名称为Blank_A4_2.jasper,为什么spring boot添加
前缀html?
Му report name in resource folder is Blank_A4_2.jasper, why spring boot adds prefix "html" ?
推荐答案
我的问题类似于 JasperReportsViewResolver在一段时间后添加.html 。正如其中所建议的,我添加了
产生=application / pdf; charset = UTF-8
,如下所示:
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.
这篇关于spring ModelAndView问题 - 添加“html”字首的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!