springBoot 模板引擎 遍历后台传输的值
<div class="">
<label class="">角色</label>
<div class="">
<select th:value="${user.role.roleId}" id="role_sel">
<option value="0">请选择</option>
<option th:each="item:${roles}" th:text="${item.roleName}"
th:value="${item.roleId}" th:selected="(${item.roleName} == ${user.role.roleId})"></option>
</select>
</div>
</div>
<!-- th:selected="(${item.roleName} == ${user.role.roleId})" 这段指定当前行
@Autowired
private RoleRepository roleRepository;
@RequestMapping("/test")
public String test(Model model,@RequestParam("userId") Integer userId){
model.addAttribute("user",userRepository.findOne(userId);
model.addAttribute("roles", roleRepository.findAll());
return "userAdd";
}
网友评论