What does the question mark mean in GSP/Grails?

前端 未结 4 463
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 14:58

I saw this in my generated GSP pages. What does the ? mean?


4条回答
  •  一生所求
    2021-01-31 15:32

    The ? operator allows null values in Groovy (and thusly, GSP). For example, normally in gsp,

    
    

    If priceDetails is null, this will throw a NullPointerException.

    If we use the ? operator instead ...

     
    

    now the value of ${priceDetails?.amount} is null, instead of throwing a null pointer exception.

提交回复
热议问题