在 MyBatis 中,我们可以使用 order by 语句对查询结果进行排序。以下代码展示了如何查询股票列表并按 public_date 进行排序。

<select id="getSharesList" resultType="com.xja.pojo.Shares">
    select * from shares
    <where>
        <if test="shares_no != null and shares_no !=''">
            and shares_no = #{shares_no}
        </if>
        <if test="shares_name != null and shares_name !=''">
            and shares_name like concat('%',#{shares_name},'%')
        </if>
    </where>
    order by public_date
</select>

在上面的代码中,order by public_date 语句位于 where 标签之后,用于指定查询结果按照 public_date 列进行排序。

通过这种方式,我们可以根据需要对查询结果进行排序,并返回排序后的数据。

MyBatis 查询股票列表并按发布时间排序

原文地址: https://www.cveoy.top/t/topic/pbNd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录