【问题标题】:Springboot Thymeleaf Cache pageSpring Boot Thymeleaf 缓存页面
【发布时间】:2017-12-10 08:44:24
【问题描述】:

我实现了一个客户端应用程序。此应用程序使用 Rest web 服务,这些服务返回和 html 页面作为模型中的变量。 我从 Rest Service 成功获取了这些 html 页面,并尝试写入一个空白的 html 页面。 我编写html页面的代码。

public void writeToHtml(ResponseModel response) {

    FileWriter fWriter = null;
    BufferedWriter writer = null;
    try {
        fWriter = new FileWriter(src/main/resources/templates/test.html);
        writer = new BufferedWriter(fWriter);
        writer.write(response.getHtmlPage());
        writer.newLine();
        writer.close();
    } catch (Exception e) {

    }
}

这些函数可以从ResponseModel中获取htmlPage并成功写入test.html 直到一切正常并且我的控制器将其显示在屏幕上。

但是,如果我再次调用相同的 Rest 服务,它可以再次写入“test.html”,但在屏幕上显示第一个创建的 html 页面。 可能它会缓存第一个 html,如果我再次重写。我只取缓存一个。

我的控制器

@RequestMapping(value = "/testPath", method = RequestMethod.POST)
public String payment(RequestModel paymentInfoModel, BindingResult bindingResult, Model model) {
    RestTemplate restTemplate = new RestTemplate();

        ResponseModel response = restTemplate.postForObject(url, request, ResponseModel.class);
        writeToHtml(response);

    return "test";

}

你能帮我解决这些问题吗?

IDEA : Inteliji

【问题讨论】:

    标签: html intellij-idea spring-boot thymeleaf


    【解决方案1】:

    我解决了我的问题有点不同:

    @RequestMapping(value = "/testPath", method = RequestMethod.POST, produces = "text/html")
    @ResponseBody
    public String payment(RequestModel paymentInfoModel, BindingResult bindingResult, Model model) {
    
       RestTemplate restTemplate = new RestTemplate();  
       ResponseModel response = restTemplate.postForObject(url, request, ResponseModel.class);
       writeToHtml(response);
    
       return response.getHtmlPage();
    }
    

    所以我不需要创建 HTML 页面。

    【讨论】: