Java spring模型和视图问题-添加;html";前缀
我有spring boot应用程序:Java spring模型和视图问题-添加;html";前缀,java,spring,spring-mvc,jasper-reports,Java,Spring,Spring Mvc,Jasper Reports,我有spring boot应用程序: @RestController @EnableAutoConfiguration @Scope("prototype") public class BillingController { @RequestMapping(value = "/testReport4_2", method = RequestMethod.GET) public ModelAndView helloReport(ModelMap modelMap, ModelAn
@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();
}
我的报告空白_A4_2首先工作正常,它显示了我的报告。
我访问它是为了:
但是如果我转到任何静态页面,例如我的项目中
如果我回去看我的报告,
它不会显示任何内容,接下来我将在java控制台中看到:
class path resource [Blank_A4_2.html.jasper] cannot be opened because it does not exist
资源文件夹中的报告名称为空_A4_2.jasper,为什么spring boot会添加
前缀为“html”?我的问题与此类似。正如上面提到的,我补充说 products=“application/pdf;charset=UTF-8” 像这样:
@RequestMapping(value = "/testReport4_2", method = RequestMethod.GET, produces = "application/pdf;charset=UTF-8")
提出了控制方法,解决了这一问题