创建User类(username,password),当get,set方法全是小写的时候(getusername,setusername,getpassword,setpassword)
Controller模拟数据插入Attribute
```java
List users = new ArrayList<User>();
users.add(new User("asd","123"));
users.add(new User("2asd34","234"));
users.add(new User("sda","345"));
users.add(new User("asdasd","456"));
model.addAttribute("users",users);
前端显示失败,查询不到传入的数据
当get,set方法为大写时(getUsername,setUsername,getPassword,setPassword)
却能正常显示传入的数据
有没有人能指点一下
另附相关代码,其中改动只有get,set的首字母大小写
Controller
@GetMapping("/dynamic_table")
public String dynamic(Model model){
// 表格信息遍历
List users = new ArrayList<User>();
users.add(new User("asd","123"));
users.add(new User("2asd34","234"));
users.add(new User("sda","345"));
users.add(new User("asdasd","456"));
model.addAttribute("users",users);
return "table/dynamic_table";
}
User类改动前
public class User {
private String username;
private String password;
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
}
User类改动后
public class User {
private String username;
private String password;
public String getusername() {
return username;
}
public String getpassword() {
return password;
}
public void setusername(String username) {
this.username = username;
}
public void setpassword(String password) {
this.password = password;
}
}
<table class="display table table-bordered" id="hidden-table-info">
<thead>
<tr>
<th>Rendering engine</th>
<th>Browser</th>
<th class="hidden-phone">Platform(s)</th>
</tr>
</thead>
<tbody>
<tr data-th-each="user:${users}">
<td>Internet</td>
<td th:text="${user.username}">username</td>
<td th:text="${user.password}">password</td>
</tr>
</tbody>
</table>