Chunk은 무료 Java 오픈 소스 템플릿 엔진입니다. Chunk는 Freemarker 나 Velocity와 비슷하지만 더 직관적 인 구문을 사용합니다.
덩어리의 중첩 가능한 "루프"와 태그는 매우 쉽게 이런 종류의 일을 할 "경우"(SRC/테마/my_template.chtml에서 예를 들어 클래스 경로에 위치)
my_template.chtml
<html>
<head>
</head>
<body>
<table>
<tbody>
<thead>
Blah Blah table Header--Constant Part
</thead>
<tr>
some text-constant part
</tr>
{!---Main Customization Part--}
{% loop in $list as $row %}
<tr>
{% loop in $row as $cell %}
{% if ($cell.color == "blue") %}
<td class="{$class_a}">{$cell.text}</td>
{% else %}
<td class="{$class_b}">{$cell.text}</td>
{% endif %}
{% endloop %}
</tr>
{% endloop %}
</tbody>
</table>
</body>
</html>
을 내가 루프 친화적 인 데이터를 생성하는 인라인 테이블 (청크의 편의 형식)를 사용하지만, 어떤 객체 t의 배열이나 목록을 사용할 수 있습니다
import com.x5.template.Theme;
import com.x5.template.Chunk;
...
Theme theme = new Theme();
Chunk html = theme.makeChunk("my_template");
html.set("class_a", "blue_cell");
html.set("class_b", "plain_cell");
String row1 = "[[color,text],[blue,moe],[red,curly],[orange,larry]]";
String row2 = "[[color,text],[red,hat],[black,dog],[blue,bottle]]";
String[] list = new String[]{row1,row2};
html.set("list", list);
out = getOutputWriter();
html.render(out); // or System.out.print(html.toString())
out.flush();
out.close();
:이 템플릿 작업을위한
샘플 자바 hat은 com.x5.util.DataCapsule을 구현하고 Chunk는 템플릿을 렌더링하기 전에 객체에서 데이터를 바로 복사합니다.
최종 출력 : 당신은 작업을 관리 또한 필요
<html>
<head>
</head>
<body>
<table>
<tbody>
<thead>
Blah Blah table Header--Constant Part
</thead>
<tr>
some text-constant part
</tr>
<tr>
<td class="blue_cell">moe</td>
<td class="plain_cell">curly</td>
<td class="plain_cell">larry</td>
</tr>
<tr>
<td class="plain_cell">hat</td>
<td class="plain_cell">dog</td>
<td class="blue_cell">bottle</td>
</tr>
</tbody>
</table>
</body>
</html>
"가가와"를 확인하셨습니까? http://code.google.com/p/gagawa/ –
간단한 템플릿 엔진을 사용할 수 있습니다. 이 항목을 확인하십시오 : http://stackoverflow.com/questions/3793880/lightweight-template-engine-in-java – mdakin
* "출력이 부족합니다."* 출력이 잘못되었습니다. [확인 서비스] (http://validator.w3.org/)를 사용하여 확인하십시오. –