我正在尝试创建复选框绑定,但是当我尝试在复选框内部传递值($ {phone.number})以在后端请求它时,该值始终为布尔值。我添加了一张照片以显示浏览器检查。 我尝试了一切,但我不知道缺少了什么。
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html lang="fr" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:insert="commons/head" />
<script th:src="@{/js/index.js}"></script>
</head>
<body>
<th:block th:insert="commons/top-menu" />
<div class="container">
<div class="clearfix mt-2">
<h3 class="float-left" th:text="#{topmenu.title}" />
</div>
<form id="other" th:action="@{/phone}" th:field="${phones}" method="get">
<div class="form-inline mt-2" style="margin-bottom:50px">
<input class="form-control form-control-sm mr-3 w-75" id="search-value" name="search" type="text" th:value="${search}" th:placeholder="#{index.search}" aria-label="Search">
<button type="submit" name="action" value="select" style="display:inline-block; border:none;background: transparent;">
<img th:src="@{/img/commons/search.png}" style="float:left;margin-right:0.5em" height="25" width="25">
</button>
<button type="submit" name="action" value="include" style="display:inline-block; border:none;background: transparent;">
Add
</button>
<button type="submit" name="action" value="remove" style="display:inline-block; border:none;background: transparent;">
Remove
</button>
</div>
</form>
<form class="form-horizontal"
th:action="@{/phone/save}"
th:object="${resourceDto}"
method="post">
<fieldset>
<span class="pull-right">
<input type="submit" id="submitButton" class="btn btn-success" th:value="Save">
</span>
<table id="activitiesTable" class="table table-hover table-striped table-sm">
<thead>
<tr class="d-flex">
<th scope="col" class="col-1"></th>
<th scope="col" class="col-2"><p th:text="#{number}" /></th>
<th scope="col" class="col-2"><p th:text="#{statusSolicitation}" /></th>
<th scope="col" class="col-2"><p th:text="#{externalList}" /></th>
<th scope="col" class="col-2"><p th:text="#{internalList}" /></th>
<th scope="col" class="col-2"><p th:text="#{withdrawalDate}" /></th>
</tr>
</thead>
<tbody>
<tr class="activitycode d-flex" th:each="phone : ${selectedPhones}" >
<td class="col-1 font-weight-bold">
<div>
<input type="checkbox" th:field="*{phones}" th:value="${phone.number}">
</div>
</td>
<td th:text="${phone.number}" th:style="${phone.phonable? 'color:black':'color:red'}" class="col-2 font-weight-bold"/>
<td th:text="${phone.phonable}? #{statusOk}: #{statusRemoved}" th:style="${phone.phonable? 'color:black':'color:red'}" class="col-2 font-weight-bold"/>
<td th:text="${phone.externalList}? #{yes}: #{no}" class="col-2 font-weight-bold"/>
<td th:text="${phone.internalList}? #{yes}: #{no}" class="col-2 font-weight-bold"/>
<td th:text="${phone.withdrawalDate}" class="col-2 font-weight-bold"/>
</tr>
</tbody>
</table>
</fieldset>
</form>
</div>
</body>
</html>
import java.util.List;
public class ResourceDto {
private List<String> phones;
/**
* @return the phones
*/
public List<String> getPhones() {
return phones;
}
/**
* @param phones the phones to set
*/
public void setPhones(List<String> phones) {
this.phones = phones;
}
}
@PostMapping(value="/phone/save")
public String includePhones(@ModelAttribute("resourceDto") ResourceDto phones) {
System.out.println(phones.getPhones());
return "index";
}