美文网首页
SpringBoot模板引擎Thymeleaf前台遍历后台返回数

SpringBoot模板引擎Thymeleaf前台遍历后台返回数

作者: 一叶知秋_zgx | 来源:发表于2018-12-10 17:36 被阅读0次

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";
    }

相关文章

网友评论

      本文标题:SpringBoot模板引擎Thymeleaf前台遍历后台返回数

      本文链接:https://www.haomeiwen.com/subject/ofsdhqtx.html