【Mybatis】动态SQL之choose、when、otherwise

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Mr_EvanChen/article/details/83996713

Mybatis中没有if-else的写法,取而代之的是choose-when-otherwise。choose在最外面,when相当于if,otherwise则相当于else。

                <choose>
                    <when test="orderby.field != null and orderby.field != ''">
                        ORDER BY ta.${orderby.field} ${orderby.order}
                    </when>
                    <otherwise>
                        ORDER BY ta.create_date DESC
                    </otherwise>
                </choose>

猜你喜欢

转载自blog.csdn.net/Mr_EvanChen/article/details/83996713
今日推荐