@Controller
@RequestMapping("/book")
@Slf4j
public class TestController {
@RequestMapping("test1")
public String test1(ModelMap map){
TenantSpace space1 = new TenantSpace();
space1.setTenantId("111");
space1.setTenantName("tenant1");
TenantSpace space2 = new TenantSpace();
space2.setTenantId("222");
space2.setTenantName("tenant2");
List spaces = new LinkedList();
spaces.add(space1);
spaces.add(space2);
map.put("name","大鹏");
map.put("tenantSpaces", spaces);
return "test_ty01";
}
@RequestMapping(value="add",method=RequestMethod.POST)
public String test2(@ModelAttribute(value="tenantSpaceGetTenantId") String selectSpace){
log.info("we select {}", selectSpace);
return "index";
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>aaa</title>
</head>
<body>
<!--在div中输出字符串-->
<form action="#" th:action="@{/book/add}" th:object="${string}" method="post">
<!--<li th:each="tenantSpace : ${tenantSpaces}">-->
<!--<input type="checkbox" th:field="*{features}" th:value="${feat}" />-->
<!--<label th:for="${#ids.prev('features')}" th:text="#{${'seedstarter.feature.' + feat}}">Electric Heating</label>-->
<!--</li>-->
<!--<label >-->
<!--<span>Date tenantId</span>-->
<!--</label>-->
<!--<input type="text" th:field="*{tenantId}"/>-->
<!--<label>-->
<!--<span>Date tenantName</span>-->
<!--</label>-->
<!--<input type="text" th:field="*{tenantName}"/>-->
<input type ="radio" name="tenantSpaceGetTenantId"
th:each ="tenantSpace:${tenantSpaces}"
th:value="${tenantSpace.tenantId}"
th:text ="${tenantSpace.tenantName} + ' === ' + ${tenantSpace.tenantId}"
/>
<input type="submit"/>
</form>
</body>
</html>