How to use thymeleaf conditions - if - elseif - else

后端 未结 6 1199
遇见更好的自我
遇见更好的自我 2021-02-07 20:04

I have a little problem, I must return a different choice of a select into a td using thymeleaf, I try the next sentence:



        
6条回答
  •  一生所求
    2021-02-07 20:24

    If you want to have only one element the option is to make multiple conditions. It is confusing a little bit but if you understanda the logic it is not a big deal.

    Lets say you want to do something like this:

    if(user.role.admin){
     //add only class='text-success'
    }else if(user.role.user){
     //add only class='text-primary'
    }else{
     //add only class='text-warning'
    }
    

    The logic is if1 : 'text-success' ? if2 : 'text-primary' ? 'text-warning' Very simple. But the syntax would be like this:

    
    

提交回复
热议问题