List对象去重复

 首先重写equals方法和hascode方法 里面可以自定义判断根据你需要的属性这个对象是否相同

package com.web.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;


@Data
public class TbHuidou implements Serializable {
    private static final long serialVersionUID = 1L;

   
    private Integer hid;

   
    private String acyivity_name;

    private String dzh_no;

    
    private String cf_no;

   
    private String lc_no;

   
    private String product_code;

    
    private String product_type;

    private String function_id;

    private Integer sent;
    
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    //@com.fasterxml.jackson.annotation.JsonIgnore
    private Date create_time;
    
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    // @com.fasterxml.jackson.annotation.JsonIgnore
    private Date update_time;

    private Integer is_delete;

    public TbHuidou() {
    }

    /**
     * 重写eques方法
     * @param o
     * @return
     */

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TbHuidou tbHuidou = (TbHuidou) o;
        return dzh_no.equals(tbHuidou.dzh_no) && lc_no.equals(tbHuidou.lc_no) && product_code.equals(tbHuidou.product_code) &&  function_id.equals(tbHuidou.function_id);
    }

    /**
     * 重写hascode方法
     * @return
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 17;
        result = prime * result + (dzh_no == null ? 0 : dzh_no.hashCode());
        result = prime * result + (lc_no == null ? 0 : lc_no.hashCode());
        result = prime * result + (product_code == null ? 0 : product_code.hashCode());
        result = prime * result + (function_id == null ? 0 : function_id.hashCode());
        return result;
    }

}

set集合去重复

   List<TbHuidou> tbHuidous = tbHuidouMapper.selectHuidouByDate();
   Set<TbHuidou> ts = new HashSet<>();
   ts.addAll(tbHuidous);
   System.err.println(ts);

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值