首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >将上下文绑定到带有胸腺叶的html模板时出错

将上下文绑定到带有胸腺叶的html模板时出错
EN

Stack Overflow用户
提问于 2018-09-12 08:29:31
回答 1查看 780关注 0票数 1

我试图获得一些表单数据到一个html模板,并最终使用iText的PDF。在线上:

代码语言:javascript
复制
String processedHtml = templateEngine.process(templateName, ctx);

我得到了错误:

2018年-09-12 12:13:17.680错误18264 - nio-8080-exec-3 org.thymeleaf.TemplateEngine : THYMELEAF异常处理模板"output.html":模板解析时出错(模板:"class path resource templates/output.html")

原因: org.attoparser.ParseException:无法处理属性“{th: BindStatus,data-th-field}”:找不到与所需窗体绑定操作相关联的字段。这可能是由于缺乏对Spring的适当管理,这通常是通过ThymeleafView或ThymeleafReactiveView完成的( RequestContext:"output.html“- 52行,列36)在org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) ~attoparser-2.0.4.RELEASE.jar:2.0.4.RELEASE在org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~attoparser-2.0.4.RELEASE.jar:2.0.4.RELEASE在org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ~胸腺叶-3.0.9.RELEASE.jar:3.0.9版本... 61个常用帧被省略

output.html第52行是:

代码语言:javascript
复制
   <input type="number" class="form-control inputnid person text-uppercase" 
         data-property="nid" id="nid" placeholder="NID" 
         th:field="*{assessment.nid}"/>

完整的方法是:

代码语言:javascript
复制
public class PdfGeneratorUtil { 

    public static final String BASEURI = "src/main/resources/static"; 
    @Qualifier("templateEngine") 
    @Autowired 
    private TemplateEngine templateEngine; 

    public void createPdf(String templateName, Map map) throws Exception { 
        Assert.notNull(templateName, "The templateName can not be null"); 
        Context ctx = new Context(); 
        if (map != null) { 
            Iterator itMap = map.entrySet().iterator(); 
            while (itMap.hasNext()) { 
                Map.Entry pair = (Map.Entry) itMap.next(); 
                ctx.setVariable(pair.getKey().toString(), pair.getValue()); 
            } 
        } 

        String processedHtml = templateEngine.process(templateName, ctx); 
        PdfWriter writer = new PdfWriter("C:\\tmp\\assessment.pdf"); 
        PdfDocument pdfDoc = new PdfDocument(writer); 
        ConverterProperties converterProperties = new ConverterProperties().setBaseUri(BASEURI); 
        HtmlConverter.convertToPdf(processedHtml, pdfDoc, converterProperties); 
        System.out.println("PDF created successfully"); 
    } 
}
EN

回答 1

Stack Overflow用户

发布于 2018-09-12 09:47:41

找到修复方法了。正如堆栈跟踪在th:字段提示的那样,复选框应为th:选中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52285833

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档