StringTemplate list of attributes defined for a given template

前端 未结 2 788
误落风尘
误落风尘 2020-12-18 07:19

I am getting started with StringTemplate 4 and I am trying to create a template from a simple string stored in a database. I use something like this:

STGroup         


        
2条回答
  •  半阙折子戏
    2020-12-18 07:50

    The documentation for CompiledST states tokens is only for debug. Not sure what that means.

    ST template = new ST("Hello , how are you? Using expression in condition works, and repeating  is not a problem.");
    Set expressions = new HashSet();
    TokenStream tokens = template.impl.tokens;
    for (int i = 0; i < tokens.range(); i++) {
        Token token = tokens.get(i);
        if (token.getType() == STLexer.ID) {
            expressions.add(token.getText());
        }
    }
    

    Gives you the Strings username and condition.

提交回复
热议问题