小编Ket*_*iya的帖子

如何在循环中以及完成循环后在Thymeleaf变量中添加值以显示最终值

我是产品设计帐单,我想使用表格在百里香模板中显示所有产品,最后,我想循环显示百里香中所有产品的价格总和。如何定义全局变量并执行此操作?

<table th:with="totalPrice=0">
    <tr th:each="count,iterator: ${product.paidService}">
        <td th:text="${iterator.index+1}"></td>
        <td th:text="${count.name}"></td>
        <td>Paid</td>
        <td th:text="${count.price}"></td>
        <p th:with="totalPrice=${totalPrice + count.price}"> </p>
    </tr>
    <span th:text="${totalPrice}"></span>
</table>
Run Code Online (Sandbox Code Playgroud)

我正在接受0输出,但我希望所有产品的价格总和作为输出。

如何使变量全局化并解决我的问题?

html spring thymeleaf spring-boot spring-boot-actuator

3
推荐指数
1
解决办法
3840
查看次数

如何设置PDF页面尺寸A4,当我们使用ITextRenderer生成从thymeleaf HTML模板PDF?

如何设置PDF页面尺寸A4,当我们使用ITextRenderer生成从thymeleaf HTML模板PDF?

我已经生成的PDF,但页面大小是不正确的,如何在JAVA设置页面大小A4 ITextRenderer库

    ClassLoaderTemplateResolver templateResolver = new 
    ClassLoaderTemplateResolver();
    templateResolver.setSuffix(".html");
    templateResolver.setTemplateMode("HTML5");

    TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);

    Context context = new Context();
    context.setVariable("name", "Thomas");

    String html = templateEngine.process("templates/Quote", context);

    OutputStream outputStream = new FileOutputStream("message.pdf");
    ITextRenderer renderer = new ITextRenderer();
    renderer.setDocumentFromString(html);
    renderer.layout();
    renderer.createPDF(outputStream,true);
    outputStream.close();
Run Code Online (Sandbox Code Playgroud)

java itext thymeleaf itext7

1
推荐指数
1
解决办法
2762
查看次数