How to use thymeleaf conditions - if - elseif - else

后端 未结 6 1279
刺人心
刺人心 2021-02-07 19:44

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:25

    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:

    
    

提交回复
热议问题