我是ThymeLeaf的新手,我想知道是否有办法循环<p>html标签以及遍历该<p>标签内的数组.我希望其中的元素smokeTest最终出现在不同的段落中.
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<p th:text="${smokeTests[0].name}"/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助
我是thymeleaf的新手,我正在尝试使用数组和每个循环创建一个简单的表.
我的代码看起来像这样:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Smoke Tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<table border="1" style="width:300px">
<tr>
<td>Test Name</td>
</tr>
<tr th:each="smokeTest : ${smokeTests}">
<td>
th:text="${smokeTest.name}">A Smoke Test'
</td>
</tr>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
基本上我的问题是我不能在<td>s内运行循环<tr>.这段代码有什么办法可行吗?
嘿,我是Spring的新手,我正在尝试在我的Applications.java中运行多个run方法.
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
SpringApplication.run(ScheduledTasks.class);
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行它时,我得到一个例外.
有没有办法在main中调用两个run方法?
-堆栈跟踪
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:135)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:683)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:944)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:933)
at testWebApp.Application.main(Application.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
Run Code Online (Sandbox Code Playgroud) 我是thymeleaf的新手,正在尝试创建一个html表,其中的boolean值决定文本在某些列中的通过还是失败。
SmokeTest.passOrFailArray是布尔数组。现在,smokeTest.name显示在该列中,但是通过或失败的文本完全不显示。
这是我的thymeleaf / html代码
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Smoke Tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<table border="1" style="width:300px">
<tr>
<td>Test Name</td>
<td th:each="testsThatRan : ${testsThatRan}"
th:text="${testsThatRan}">Tests</td>
</tr>
<th:block th:each="smokeTest : ${smokeTests}">
<tr>
<td th:text="${smokeTest.name}">A Smoke Test'</td>
<th:block th:each="smokeTest.passOrFailArray : ${smokeTest.passOrFailArray}">
<td th:if="${smokeTest.passOrFailArray} == true" th:text="Passed"></td>
<td th:if="${smokeTest.passOrFailArray} == false" th:text="failed"></td>
</th:block>
</tr>
</th:block>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我在百里香中用作变量的类
public testers() throws IOException {
localPath = "/Users/dansbacher14/Documents/workspace/OBI_nightly_test/src/OBI_ci_scripts_tests";
remotePath = "ssh://git@stash.ops.aol.com:2022/obi/obi_ci_scripts.git";
localRepo = new FileRepository(localPath + "/.git");
pathToSmoke = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 thymeleaf 创建一个包含一系列复选框的表单。我传递给 thymeleaf 模板的对象源包含一个字符串和一个列表。
package com.controller;
import java.util.List;
public class Source {
private String sourceName;
private List<String> testList;
public String getSourceName()
{
return sourceName;
}
public void setSourceName(String name)
{
this.sourceName = name;
}
public List<String> getTestList()
{
return testList;
}
public void setTestList(List<String> list)
{
this.testList = list;
}
}
Run Code Online (Sandbox Code Playgroud)
我使用此 MVC 控制器将源类型的对象传递到模板中。
package com.controller;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.View;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
import …Run Code Online (Sandbox Code Playgroud)