标签: thymeleaf

Thymeleaf:列表的逗号分隔值?

我是 Thymeleaf 的初学者,我有一个列表,想要通过逗号分隔来列出一行中的元素,例如 London、Paris、Berlin、HonKong(最后一个元素之后不会有逗号)。但是,以下代码会生成新行。那么,我怎样才能让它按照上面的解释工作呢?

<td th:each="city : ${country.cityList}">
    <td th:text="${city.name}? ${city.name} + ',' : ${city.name}"></td>
</td>

Run Code Online (Sandbox Code Playgroud)

我知道它还在最后一个元素的末尾添加了一个额外的逗号,我需要使用索引来检测最后一个索引。我怎样才能做到这一点?

html java spring thymeleaf

1
推荐指数
2
解决办法
2932
查看次数

使用Thymeleaf在Spring MVC中显示模型对象

首先,我定义了一个简单的POJO如下:

public class MyDesc {

    private String desc;

    public MyDesc(String desc) {
        setDesc(desc);
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

}
Run Code Online (Sandbox Code Playgroud)

然后,我通过实例MyDescSpring MVC的 模型对象:

@Bean
public MyDesc myDesc() {
    return new MyDesc("Holla!");
}

@RequestMapping(value="/", method = RequestMethod.GET)
public String home(Model model) {
    model.addAttribute("my-desc", myDesc());
    return "pages/home";
}
Run Code Online (Sandbox Code Playgroud)

现在,我想通过使用Thymeleaf作为模板引擎将内容显示到HTML页面中.

<div th:text="${my-desc.desc}">Desc placeholder</div> 
Run Code Online (Sandbox Code Playgroud)

但是在运行时发生错误:

Property or field 'desc' cannot be found on null 
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

spring spring-mvc thymeleaf

0
推荐指数
1
解决办法
1439
查看次数

Thymeleaf th:field覆盖th:value

我只是想知道该th:field属性覆盖该th:value属性。

在我th:each我想覆盖的价值th:field为我产生。有谁知道如何实现这一目标?

提前致谢。

<ul id="userGroupContainer">
	<li class="clickable unselected" th:each="u, rowStat : ${userNotInGroup}" th:if="${u.id}">
      <input type="text" readonly="readonly" hidden="hidden" disabled="disabled" th:field="* {users[__${rowStat.index}__].id}" th:value="${u.id}" />
      <input type="text" readonly="readonly" hidden="hidden" disabled="disabled" th:field="* {users[__${rowStat.index}__].displayName}" th:value="${u.displayName}" />
      <input type="text" readonly="readonly" hidden="hidden" disabled="disabled" th:field="* {users[__${rowStat.index}__].username}" th:value="${u.username}" />
      <input type="text" readonly="readonly" hidden="hidden" disabled="disabled" th:field="*{users[__${rowStat.index}__].emailAddress}" th:value="${u.emailAddress}" />
								<span th:text="${u.displayName}"></span>
	</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

html java thymeleaf

0
推荐指数
1
解决办法
3393
查看次数

从哈希图/数组列表中打印百里香中的键/值

java / springboot中的代码:

@RequestMapping(value = "results")
public String results(
        Model model, 
        @RequestParam String searchType,
        @RequestParam String searchTerm) {

    model.addAttribute("columns", ListController.columnChoices);
    ArrayList<HashMap<String, String>> jobsbyval = JobData
            .findforValue(searchTerm);
    model.addAttribute("items", jobsbyval);
    return "search";
}
Run Code Online (Sandbox Code Playgroud)

html / thymeleaf中的代码:

<div>
  <table>
    <tbody>
      <tr th:each="item : ${items}">
        <!--each loop begins -->
        <td th:text="${item}"></td> //item.value or item.key dont work!!

      </tr>
      <!--loop ends -->
    </tbody>
  </table>
</div>
Run Code Online (Sandbox Code Playgroud)

这是html输出。

{header 1=something, header 2=Analyst, category 3=somename, location=somewhere, skill=Stats}
Run Code Online (Sandbox Code Playgroud)

表格式的所需HTML输出(键/值)为:

header 1  something  
header 2  Analyst 
category  somename 
location  somewhere 
skill …
Run Code Online (Sandbox Code Playgroud)

arraylist hashmap thymeleaf

0
推荐指数
1
解决办法
5620
查看次数

如果tr与百里香一起为空,如何隐藏父div?

我正在使用百里香框架。如果值显示为空,我想隐藏整个div。并显示它是否不为null。

HTML代码

<div>
<h2> My Table </h2>
    <table border="1">
        <tr bgcolor="powderblue">
            <th>name</th>
            <th>age</th>
            <th>hobby</th>
            <th>interest</th>
            <th>books</th>
            <th>movie</th>
        </tr>
        <tr th:each="table: ${myTable}">

        <td th:text = "${table.name != null ? table.name : 'NULL'}" />
        <td th:text = "${table.age != null ? table.age : 'NULL'}" />
        <td th:text = "${table.hobby != null ? table.hobby : 'NULL'}" />
        <td th:text = "${table.interest != null ? table.interest: 'NULL'}" />
        <td th:text = "${table.books != null ? table.books : 'NULL'}" />
        <td th:text = "${table.movie != …
Run Code Online (Sandbox Code Playgroud)

html javascript css thymeleaf

0
推荐指数
1
解决办法
3868
查看次数

我如何使用thymeleaf和spring boot循环遍历ArrayList?

我是百里香的新手,我尝试遍历ArrayList,但对我不起作用..请提供一些帮助:这是我的HTML页面:

<body>
    <div class="row">
        <table>
            <tr th:each="data: mois">  
                <td class="text-center" th:text="${data}">data</td>
            </tr>			
        </table>
    </div>
</body>
Run Code Online (Sandbox Code Playgroud)

这是我的控制器

@RequestMapping(value="/editePlanning", method= RequestMethod.GET)
    public String editePlanning(Model model){
        Psi psi = psiRepository.findOne((long) 1);
        List<String> data = new ArrayList<String>();

        for(int i=0;i<psi.getNombreMois();i++){
            int val = psi.getMoisDebut()+i%12;
            data.add(""+ val);
        }

        model.addAttribute("mois",data);
		
        return "editePlanning";
    }
Run Code Online (Sandbox Code Playgroud)

html thymeleaf spring-boot

0
推荐指数
1
解决办法
5570
查看次数

Thymeleaf-如何根据互斥条件应用两种(或更多)样式

我需要表格中的行具有备用背景色。我还需要使行中的文本颜色取决于值。如何使用Thymeleaf做到这一点?这是我的代码:

<tr th:each="item, rowStat : ${items}" 
    th:style="${rowStat.odd} ? 'background: #f0f0f2;' : 'background: #ffffff;'"
    th:style="${item.getValue()} > 5 ? 'color: red;' : 'color: black;'">

                <td.... <!-- cols>

</tr>
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用。Thymeleaf给出一个解析错误:Attribute "th:style" was already specified for element "tr".

更新资料

请注意,这是一封HTML电子邮件,因此我需要使用内联样式。

html css thymeleaf

0
推荐指数
1
解决办法
4052
查看次数

更新资源时Intellij不更新html文件

每当我在html文件上更改某些内容时,我必须重新启动整个项目.我试过了:-

- >编辑配置 - >服务器并更改帧检测以更新资源.

在此输入图像描述

在我的服务器选项卡上,还有关于帧检测的更新资源.但仍然无法更新我的html文件,我必须重新启动服务器以反映我的更改.

在此输入图像描述

Intellij Idea版本是2017年.

java thymeleaf

0
推荐指数
1
解决办法
797
查看次数

Thymeleaf中th:action和th:formaction之间的工作差异

我是Thymeleaf的新手,我有一个Spring-Boot应用程序,该应用程序在视图页面中使用了Thymeleaf组件。

  <form action="#" th:action="@{/saveStudent}" th:object="${user}" method="post">
    <table>
      <tr> 
        <td>Enter Your name</td>
        <td><input type="text"  th:field="*{userName}"/></td>
        <td><input type="submit" value="Submit"/></td>
      </tr>
   </table>
 </form>
Run Code Online (Sandbox Code Playgroud)

上面的代码对我来说很好用

现在,在使用eclipse代码辅助时,我遇到了几个百里香标签/属性th:form,th:formaction

一旦我将上面的代码更改为以下格式:

<th:form  th:formaction="@{/saveStudent}" th:object="${user}" method="post">
  <table>
    <tr> 
      <td>Enter Your name</td>
      <td><input type="text"  th:field="*{userName}"/></td>
      <td><input type="submit" value="Submit"/></td>
    </tr>
  </table>
</th:form>
Run Code Online (Sandbox Code Playgroud)

它停止工作。我的网页没有提交到服务器。因此,我想了解以下内容:

th:form标签的用途是什么?th:action和th:formaction标签之间有什么区别?

spring thymeleaf spring-boot

0
推荐指数
1
解决办法
1965
查看次数

具有禁用输入的弹簧模型绑定

对于一个愚蠢的问题感到抱歉,但我无法完全理解会发生什么,如果这是我怀疑的问题,那么我真的很茫然。我正在使用弹簧靴+百里香叶+物化CSS来显示和验证表单。现在我在很多例子中没有遇到的是这种情况:

一些表单字段是预先填写的,对客户端来说应该被禁用,显示其预先填写的值。这种预填充发生在控制器中,而我处理其他一些请求,并重定向到该视图

我正在使用th:object这样将pojo绑定到表单

<form id="register_form" action="#" th:action="@{/showform}" th:object="${userInfo}" method="post">
 <div class="input-field">
   <label th:text="#{label.surname}" for="surname"></label>
   <input type="text" th:field="*{surname}" id="surname" th:attr="value=${userInfo.surname}" />
 </div>
 <div class="input-field">
   <label th:text="#{label.name}" for="givenname"></label>
   <input type="text" th:field="*{givenname}" id="givenname" th:attr="value=${userInfo.givenname}" disabled="disabled" />
 </div></form>
Run Code Online (Sandbox Code Playgroud)

并将其放入控制器的POST处理程序中,如下所示:

@RequestMapping(value = {"/showform"}, method = RequestMethod.POST)
public ModelAndView submitFormPage(@ModelAttribute("userInfo") @Valid UserInfo userInfo, 
      BindingResult bindingResult, RedirectAttributes redir) 
{      
  ModelAndView mview = new ModelAndView();

  if (bindingResult.hasErrors()) 
  {
     // show form again with error messages
     mview.addObject("userInfo", userInfo);
     mview.setViewName("/showform");
  }
  else 
  {
     // ...
  }

  return mview;
}
Run Code Online (Sandbox Code Playgroud)

出于其他一些原因,存在RedirectAttributes。如您所见,表单上有两个元素,第一个被启用,第二个被禁用。它们的值已正确填入POJO中的预填充值,然后通过ModelMap传递到视图。我也可以在GET处理程序中跟踪它。 …

spring materialize thymeleaf

0
推荐指数
1
解决办法
2444
查看次数