【问题标题】:Thymeleaf could not parse as expression th:select optionThymeleaf 无法解析为表达式 th:select 选项
【发布时间】:2018-04-02 22:32:19
【问题描述】:

我就是想不通我的错误。这是我的 updateprofile.html。

<select class="form-control selectpicker" th:value = "${user.team}" id="team" name="team" roleId="team" required="required">
    <option disabled="disabled">Select your team</option>
    <option th:selected="${user.team} == 'A'}">A</option>
    <option th:selected="${user.team} == 'B'}">B</option>
    <option th:selected="${user.team} == 'C'}">C</option>
    <option th:selected="${user.team} == 'D'}">D</option>  
    <option th:selected="${user.team} == 'TSO'}">TSO</option>   
</select>

错误是

org.thymeleaf.exceptions.TemplateProcessingException:无法解析 作为表达式:"${user.team} == 'A'}" (updateprofile:54)

这是我的控制器类

@RequestMapping(value = "/updateprofile", method = RequestMethod.GET)
public String updateProfile(Principal principal, Model model) {
    User user = userService.findByUsername(principal.getName());
    model.addAttribute("user", user);
    return "updateprofile";
}

提前感谢您的帮助

【问题讨论】:

    标签: spring-boot thymeleaf


    【解决方案1】:

    你的百里香表达式中有一个额外的}

    试试这个

    &lt;option th:selected="${user.team} == 'A'"&gt;A&lt;/option&gt;

    【讨论】:

      猜你喜欢
      • 2016-01-21
      • 2013-04-13
      • 2017-03-28
      • 1970-01-01
      • 2019-01-04
      • 2017-09-22
      • 2021-09-16
      • 2021-01-02
      • 2018-09-29
      相关资源
      最近更新 更多