数据排序(多字段数据排序)

这篇博客介绍了如何使用Java枚举类进行动态排序,并在SQL查询中应用。通过设置排序字段和类型,实现对入库单数据的动态排序,如入库日期和到期日期。同时展示了对应的SQL查询语句,根据传入的参数动态生成WHERE子句和ORDER BY子句,实现灵活的数据过滤和排序。
摘要由CSDN通过智能技术生成

java代码

//排序
entity.setSortField(BloodEnum.RkdSortEnum.valueOf(1).getField());
if (ArrayUtil.isNotEmpty(dto.getFields())){
String fields = “”;
for (Integer sort:dto.getFields()){
String field = BloodEnum.RkdSortEnum.valueOf(sort).getField();
if (StrUtil.isNotEmpty(field)){
fields = field + “,”;
}
}
//除去最后的逗号
fields = fields.substring(0,fields.length() -1);
if (dto.getSortType() == 1){
fields = fields + " DESC";
}
entity.setSortField(fields);
}

枚举类

/**
 * 入库单动态排序枚举
 *  1入库日期2到期日期
 */
@Getter
@AllArgsConstructor
public enum RkdSortEnum {
    //排序对应字段名
    one(1,"RKRQ "),
    two(2,"DQRQ");

    public Integer value;
    public String field;

    public static RkdSortEnum valueOf(Integer value){
        for (RkdSortEnum rKdenum : values()){
            if (rKdenum.getValue().equals(value)){
                return rKdenum;
            }
        }
        return null;
    }
}

sql

    <select id="listRkdsBySort" resultType="com.bsoft.lis.lab.core.entity.blood.BloodRkdEntity">
        select
        <include refid="Base_Column_List"/>
        from BLOOD_RKD
        where JGID = #{jgid}
        <if test="ckbj != null and ckbj != ''">
            AND CKBJ = #{ckbj}
        </if>
        <if test="rkfs != null and rkfs != ''">
            AND RKFS = #{rkfs}
        </if>
        <if test="ckrq != null">
            AND CKRQ = #{ckrq}
        </if>
        <if test="ybbh != null">
            AND YBBH = #{ybbh}
        </if>
        <if test="xylx != null and xylx !='' ">
            AND XYLX = #{xylx}
        </if>
        <if test="sfxj != null ">
            AND SFXJ = #{sfxj}
        </if>
        <if test="ztx != null ">
            AND ZTX = #{ztx}
        </if>
        <if test="abo != null and abo !=''">
            AND ABO = #{abo}
        </if>
        <if test="xdh != null and xdh != ''">
            AND XDH = #{xdh}
        </if>
        <if test="xdxh!=null and xdxh !=''">
            And XDXH = #{xdxh}
        </if>
        <if test="hosarea != null and hosarea != ''">
            AND HOSAREA = #{hosarea}
        </if>
        <if test="bfstartDate !=null and bfendDate !=null">
            AND (BFRQ BETWEEN #{bfstartDate} AND #{bfendDate})
        </if>
        <if test="xq != null and xq != ''">
            and TO_NUMBER(DQRQ -  sysdate ) &lt;= #{xq}
        </if>

        order by ${sortField}
    </select>

前端效果

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值