为什么我的浏览器下载文件而不是呈现 SpringBoot 和 Sitemesh 输出?

Why is my browser downloading file instead of rendering SpringBoot & Sitemesh output?

我正在尝试将 SpringBoot 与 Freemarker 和 Sitemesh 一起使用。

当我转到 URL 时,应用程序正在处理请求,加载数据并生成 HTML 输出,但由于某种原因,浏览器已决定要下载文件(包含正确的内容)而不是将其呈现为页面。

这在一段时间前是有效的,问题是我不确定我所做的哪个更改破坏了它!

Sitemesh 过滤器:

@WebFilter
public class SitemeshFilter extends ConfigurableSiteMeshFilter {

private static final Logger LOG = Logger.getLogger(SitemeshFilter.class);

    @Override
    protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
        LOG.debug("SiteMeshFilter creation");
        builder.addDecoratorPath("/*", "/templates/main.ftl")
            .addExcludedPath("/h2console/*");
    }
}

申请:

@ServletComponentScan
@SpringBootApplication
@EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class})
public class ClubManagementApplication {

    private static Logger LOG = Logger.getLogger(ClubManagementApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(ClubManagementApplication.class, args);
    }
}

控制器片段:

@Controller
public class ClubController {

    @Autowired
    ClubService clubService;

    @RequestMapping(value = {"Club/{id}","club/{id}"})
    public ModelAndView viewClub(@PathVariable("id") int clubId) {
        ModelAndView mv = new ModelAndView("club");
        ....
        return mv;
    }
}

编辑: 从控制器中的 HttpServletRequest object... 接受 : text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q= 0.8

在响应中 headers: Content-Type : application/octet-stream;字符集=UTF-8

我猜是内容类型的问题....只是要找出为什么它被设置成那样。

为了防止其他人遇到这个问题,我将我的模板文件从 ftl 更改为 html 扩展名,突然它就醒了。

@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder)   {
    LOG.debug("SiteMeshFilter creation");
    //builder.addDecoratorPath("/*", "/templates/main.ftl");
    builder.addDecoratorPath("/*", "/templates/main.html");
}