Springboot ModelAndView???

直接上代码~

 @Configuration
public class ExportAlarmController {

    @Bean(name = "csvView")
    public CSVView cSVView() {
        return new CSVView();
    }

    @Autowired
    ExportAlarmService exportAlarmService;

    @SuppressWarnings({ "unchecked", "rawtypes" })
    @RequestMapping(value = "/exportAlarm", method = RequestMethod.POST)
    public ModelAndView exportAlarm(HttpServletRequest request, HttpServletResponse response) throws Exception {

        System.out.println("-----------------exportAlarm------------------");

        Map requestValue = request.getParameterMap();

        List list = exportAlarmService.exportAlarm(requestValue);

        Map result = new HashMap();

        result.put("list", list);
        result.put("name", "Alarm");

        return new ModelAndView("csvView", result);
    }

}


执行上面的代码后出现错误~

 org.thymeleaf.exceptions.TemplateInputException: Error resolving template "csvView", template might not exist or might not be accessible by any of the configured Template Resolvers

请问这个要怎么解决呢?

2个回答

new ModelAndView("csvView", result) 这个所指向的页面似乎不存在……

qq_24534807
qq_24534807 有个叫CSVView的类,不是bean了吗?@Bean(name = "csvView") public CSVView cSVView() { return new CSVView(); }为什么还不行呢?
大约 3 年之前 回复

先检查配置:

THYMELEAF (ThymeleafAutoConfiguration)

#spring.thymeleaf.check-template-location=true
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.excluded-view-names= # comma-separated list of view names that should be excluded from resolution
#spring.thymeleaf.view-names= # comma-separated list of view names that can be resolved
#spring.thymeleaf.suffix=.html
#spring.thymeleaf.mode=HTML5
#spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.content-type=text/html # ;charset= is added
#spring.thymeleaf.cache=true # set to false for hot refresh
然后看spring.thymeleaf.prefix配置对应的路径下是否有csvView.html文件

qq_24534807
qq_24534807 请问这个配置是怎么查看的,不太懂~
大约 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问