Dam*_*ien 2 java spring templates thymeleaf spring-boot
我正在使用 Spring Boot 2.1.5.RELEASE 并希望使用 Thymeleaf 生成 JSON 模板文件。
这是我当前拥有的文件之一的示例:
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"labels": {
"run": "[( ${imageNameLabel} )]"
},
"name": "[( ${imageNameLabel} )]"
},
"spec": {
"replicas": [( ${replicas} )],
"selector": {
"matchLabels": {
"run": "[( ${imageNameLabel} )]"
}
},
"template": {
"metadata": {
"labels": {
"run": "[( ${imageNameLabel} )]"
}
},
"spec": {
"containers": [
{
"image": "[( ${imageName} )]:[( ${imageVersion} )]",
"name": "[( ${imageNameLabel} )]",
"env": [( ${credentials} )],
"volumeMounts": [
{
"mountPath": "/etc/foo",
"name": "[( ${imageNameLabel} )]",
"readOnly": true
}
]
}
],
"volumes": [
{
"name": "[( ${imageNameLabel} )]",
"secret": {
"secretName": "[( ${imageNameLabel} )]"
}
}
]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想将条件逻辑放入该文件中。Thymeleaf 是否可以做到这一点,或者我应该考虑其他模板技术吗?
请参阅文本模板模式的文档。一个例子可能看起来像:
[# th:if="${condition}" th:text="${item}" /]
Run Code Online (Sandbox Code Playgroud)
或者
[# th:if="${condition}"][(${imageNameLabel})][/]
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6584 次 |
最近记录: |