我们在使用mybatis时,xml文件中接收参数为了防止SQL注入,我们使用#{ }表达式,但是我们在拼接查询条件时,需要根据前台传递的参数决定是升序或降序排序是,此时则一定要使用${ } 表达式。
示例代码
<if test="orderBy != null and orderBy != ''">
order by bo.create_date ${orderBy}
</if>
其中${orderBy}值就是我们前台传递的asc或者desc排序字段。
我们在使用mybatis时,xml文件中接收参数为了防止SQL注入,我们使用#{ }表达式,但是我们在拼接查询条件时,需要根据前台传递的参数决定是升序或降序排序是,此时则一定要使用${ } 表达式。
示例代码
<if test="orderBy != null and orderBy != ''">
order by bo.create_date ${orderBy}
</if>
其中${orderBy}值就是我们前台传递的asc或者desc排序字段。