Java8中List的removeif()函数的使用示例

代码:

import java.util.List;
import java.util.function.Predicate;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.anbank.eva.po.RptEbankMerchantDetail;
import com.anbank.eva.service.RptEbankMerchantDetailService;

@RestController
@RequestMapping("/RPT_EBANK_MERCHANT_DETAIL")
public class RptEbankMerchantDetailController {

    @Autowired
    private RptEbankMerchantDetailService rptEbankMerchantDetailService;
    
    @RequestMapping("/all")
    public List<RptEbankMerchantDetail> getAllRptEbankMerchantDetails() {
        List<RptEbankMerchantDetail> list = this.rptEbankMerchantDetailService.getAllRptEbankMerchantDetails();
        return list;
    }
    
    @RequestMapping("/result")
    public List<RptEbankMerchantDetail> getRptEbankMerchantDetails(@RequestParam(value="orgId", required=false)  String orgId,
                                                                        @RequestParam(value="startDate", required=false) String startDate,
                                                                        @RequestParam(value="endDate", required=false) String endDate,
                                                                        @RequestParam(value="merId", required=false) String merId
                                            ) {
        List<RptEbankMerchantDetail> list = this.rptEbankMerchantDetailService.getAllRptEbankMerchantDetails();
        Predicate<RptEbankMerchantDetail> predicate = (ele) -> {
            if (orgId != null && orgId.equals(ele.getORG_CODE()) == false)
                return true;
            if (startDate != null && startDate.compareTo(ele.getCREATE_DT()) > 0)
                return true;
            if (endDate != null && endDate.compareTo(ele.getCREATE_DT()) < 0)
                return true;
            if (merId != null && merId.equals(ele.getMER_ID()) == false)
                return true;
            return false;
        };
        list.removeIf(predicate);
        return list;
    }
}

猜你喜欢

转载自www.cnblogs.com/zifeiy/p/9249092.html