前言
今天和大家探讨java8新特性,主要从以下两方面stream、foreach来讲述相关的使用方法,主要涉及了stream流中的filter(过滤),groupingBy (分组),distinct(去重),根据某种属性去重…等
实体类
package com.example.student.entity;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
/**
* @Desc 学生实体类
*/
@Table(name = "student")
@Entity
@Setter
@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Student implements Serializable {
@Id
@GeneratedValue
private Integer id;
private String name;
private Integer age;
private String grade;
private Integer weight;// 排序字段
}
repository层
package com.example.student.repository;
import com.example.student.entity.Student;
import org.springframework.data.repository.CrudRepository;
import java.util.Collection;
/**
* sql语句
*/
public interface StudentRepository extends CrudRepository<Student,Integer> {
Integer deleteAllByIdIn(Collection