Java Stream流使用案例深入详解

2025-04-28 17:50

本文主要是介绍Java Stream流使用案例深入详解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

《JavaStream流使用案例深入详解》:本文主要介绍JavaStream流使用案例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧...

前言

项目一直在用流,但是用的也是一知半解,所以在这里深入学习一下
通常用到流会设计到Java8的几个新知识,下边我回粗略的讲解下这几个知识,再了解认知后学习stream或者用到的时候更得心应手

  • Lambda表达式
  • 方法引用
  • Option
  • stream

1. Lambda

建议先了解函数式接口

1.1 语法

parameter -> expression body;

1.2 没参数只有一条语句或者多条语句

()->System.out.prilt("baicaizhi");
()->{
	System.out.prilt("baicaizhi1");
	System.out.prilt("baicaizhi1");
}

1.3 一个参数只有一条语句或者多条语句

a->System.out.println(a);
a->{
	System.out.println(a);
	System.out.println(a);
}

1.4 多个参数只有一条语句或者多条语句

(a,b)->a+b;
(a,b)->{
	int c = a+b;
	System.out.println(c);
}
  • 可选的参数类型声明 : 无需声明参数的类型。编译器可以从参数的值推断出相同的值。
  • 可选的参数周围的小括号 () : 如果只有一个参数,可以忽略参数周围的小括号。但如果有多个参数,则必须添加小括号。
  • 可选的大括号 {} : 如果 Lambda 表达式只包含一条语句,那么可以省略大括号。但如果有多条语句,则必须添加大括号。
  • 可选的 return 关键字 : 如果 Lambda 表达式只有一条语句,那么编译器会自动 return 该语句最后的结果。但如果显式使用了 return 语句,则必须添加大括号 {} ,哪怕只有一条语句。

2.方法引用

使用:(静态方法或者new的时候用)

Test::new
Test::getName

3.Option

接口名称简要作用描述
Optional empty()构建一个空的Optional 对象
Optional of(T value)构建一个非空的Optional 对象,如果为空则报错!
Optional ofNullable(T value)构建一个Optional 对象,允许为空!
T get()获取一个泛型的对象值,如果值为空,则报错
boolean isPresent()判空,如果不为null 则为 true
boolean isEmpty()判空,如果为null 则为 true
ifPresent(Consumer)传递一个接口函数对,当数据不为空的时候执行这个函数
ifPresentOrElse(Consumer, Runnable)两个参数, 第一个是不为空的时候执行的,第二个是为空的时候执行的。都是接口函数。
Optional filter对对象的一个过滤
Optional map(Function)转换方法
Optional flatMap(Function)转换方法,常用与多层转换一层
Optional or(Supplier)当得到对象为空的时候根据接口函数创建一个新的Optional对象
T orElse(T)当得到对象为空的时候获取一个指定泛型对象
T orElseThrow()不为空 返回对象,为空 则NoSuchElementException
T orElseThrow(Supplier)不为空 返回对象,为空 则指定异常

4.Stream

4.1Stream概述

4.1.1什么是steam

Stream将要处理的元素集合看作一种流,在流的过程中,借助Stream API对流中的元素进行操作,比如:筛选、排序、聚合等。

4.1.2Stream可以由数组和集合创建,对流的操作分为俩类

4.1.2.1中间操作

每次返回一个新的流,可以有多个。

4.1.2.2终端操作

终端操作,每个流只能进行一次终端操作,终端操作结束后流无法再次使用。终端操作会产生一个新的集合或值

4.1.3特性

1.stream不存储数据,而是按照特定的规则对数据进行计算,一般会输出结果。
2.stream不会改变数据源,通常情况下会产生一个新的集合或一个值。
3.stream具有延迟执行特性,只有调用终端操作时,中间操作才会执行。

3.2Stream的创建

3.2.1通过 java.util.Collection.stream() 方法用集合创建流

  	List<String> list = Arrays.asList("a","b","c");        //创建顺序流       
    Stream<String> stream = list.stream();        //创建并发流       
    Stream<String> stringStream = list.parallelStream();

3.2.2使用java.util.Arrays.stream(T[] array)方法用数组创建流

  //数组创建流        
  int[] array = {1,2,3};        
  IntStream stream1 = Arrays.stream(array);

3.2.3使用Stream的静态方法:of()、iterate()、generate()

 //stream静态方法创建流       
   Stream<Integer> integerStream = Stream.of(1, 2);        
   Stream<Integer> iterate = Stream.iterate(0, x -> x = 3);        
   Stream<Double> limit = Stream.generate(Math::random).limit(3);

3.2.4顺序流转换成并发流

  //顺序流转换成并发流        
  Optional<String> first = list.stream().parallel().filter(x -> x > 6).findFirst();

4.3 使用

使用前先了解Optional

4.3.1 数据准备

class Persohttp://www.chinasem.cnn {
 private String name;  // 姓名
 private int salary; // 薪资
 private int age; // 年龄
 private String sex; //性别
 private String area;  // 地区
 // 构造方法
 public Person(String name, int salary, int age,String sex,String area) {
  this.name = name;
  this.salary = salary;
  this.age = age;
  this.sex = sex;
  this.area = area;
 }
 // 省略了get和set,请自行添加 
}

4.3.2 使用

4.3.2.1 遍历/匹配(foreach/find/match)

Stream也是支持类似集合的遍历和匹配元素的,只是Stream中的元素是以Optional类型存在的。Stream的遍历、匹配非常简单

List<Integer> list = Arrays.asList(1,2,3,4,7,6,5,8);
        // 遍历输出符合条件的元素
        list.stream().filter(x->x>6).forEach(System.out::println);
        // 匹配第一个
        Optional<Integer> first = list.stream().filter(x -> x > 6).findFirst();
        // 匹配任意(适用于并行流)
        Optional<Integer> any = list.parallelStream().filter(x -> x > 6).findAny();
        // 是否包含符合特定条件的元素
        boolean b = list.stream().anyMatch(x -> x < 6);
        System.out.println("匹配第一个值"+first.get());
        System.out.println("匹配任意值"+any.get());
        System.out.println("是否存在大于6的值"+b);

4.3.2.2 筛选(filter)

筛选,是按照一定的规则校验流中的元素,将符合条件的元素提取到新的流中的操作

4.3.2.3 聚合(max/min/count)

List<Person> personList = new ArrayList<Person>();
        personList.add(new Person("Tom", 8900, 11,"male", "New York"));
        personList.add(new Person("Jack", 7000, 12,"male", "Washington"));
        personList.add(new Person("Lily", 7800, 13,"female", "Washington"));
        personList.add(new Person("Anni", 8200, 14,"female", "New York"));
        personList.add(new Person("Owen", 9500, 15,"male", "New York"));
        personList.add(new Person("Alisa", 7900, 16,"female", "New York"));
        List<Integer> list = Arrays.asList(1,2,3,4,7,6,5,8);
        //筛选出Integer集合中大于7的元素,并打印出来
        list.stream().filter(x->x>7).forEach(System.out::println);
        //筛选员工中工资高于8000的人,并形成新的集合。 形成新集合依赖collect(收集)
        List<String> collect = personList.stream().filter(value -> value.getSalary() > 8000).map(Person::getName).collect(Collectors.toList());
        System.out.println("工资高于8000"+collect);

4.3.2.4 映射(map/flatMap)

映射,可以将一个流的元素按照一定的映射规则映射到另一个流中。分为map和flatMap:

  • map:接收一个函数作为参数,该函数会被应用到每个元素上,并将其映射成一个新的元素。
  • flatMap:接收一个函数作为参数,将流中的每个值都换成另一个流,然后把所有流连接成一个流。
 List<Person> personList = new ArrayList<Person>();
        personList.add(new Person("Tom", 8900, 11,"male", "New York"));
        personList.add(new Person("Jack", 7000, 12,"male", "Washington"));
        personList.add(new Person("Lily", 7800, 13,"female", "Washington"));
        personList.add(new Person("Anni", 8200, 14,"female", "New York"));
        personList.add(new Person("Owen", 9500, 15,"male", "New York"));
        personList.add(new Person("Alisa", 7900, 16,"female", "New York"));
        List<Integer> list = Arrays.asList(1,2,3,4,7,6,5,8);
        List<String> strList = Arrays.asList("ad,nm", "adm,mt", "p,ot", "xb,angd", "weou,jgsd");
        //英文字符串数组的元素全部改为大写。整数数组每个元素+3
        List<Integer> collect = list.stream().map(x -> x + 3).collect(Collectors.toList());
        List<String> collect1 = strList.stream().map(String::toUpperCase).collect(Collectors.toList());
        //将员工的薪资全部增加1000
        //不改变源集合的方式
        List<Person> collect2 = personList.strhAZRream().map(person -> {
            Person person1 = new Person(person.getName(), 0, person.getAge(), person.getSex(), person.getArea());
            person1.setSalary(person.getSalary() + 1000);
            return person1;
        }).collect(Collectors.toList());
        //改变源集合的方式
        List<Person> collect3 = personList.stream().map(person -> {
            person.setSalary(person.getSalary() + 1000);
            return person;
        }).collect(Collectors.toList());
        //将两个字符数组合并成一个新的字符数组
        List<String> collect4 = strList.stream().flatMap(s -> {
            String[] s2 = s.split(",");
            return Arrays.stream(s2);
        }).collect(Collectors.toList());
        System.out.println("每个元素大写:" + collect1);
        System.out.println("每个元素+3:" + collect);
        //注意,执行的时候分开执行,否则看不出来效果
        System.out.println("一次改动前:" + personList.get(0).getName() + "-->" + personList.get(0).getSalary());
        System.out.println("一次改动后:" + collect2.get(0).getName() + "-->" + collect2.get(0).getSalary());
        System.out.println("二次改动前:" + personList.get(0).getName() + "-->" + personList.get(0).getSalary());
        System.out.println("二次改动后:" + collect3.get(0).getName() + "-->" + collect3.get(0).getSalary());
        System.out.println("处理前的集合:" + strList);
        System.out.println("处理后的集合:" + collect4);

4.3.2.5 归约(reduce)

归约,也称缩减,顾名思义,是把一个流缩减成一个值,能实现对集合求和、求乘积和求最值操作

List<Person> personList = new ArrayList<Person>();
        personList.add(new Person("Tom", 8900, 11,"male", "New York"));
        personList.add(new Person("Jack", 7000, 12,"male", "Washington"));
        personList.add(new Person("Lily", 7800, 13,"female", "Washington"));
        personList.add(new Person("Anni", 8200, 14,"female", "New York"));
        personList.add(new Person("Owen", 9500, 15,"male", "New York"));
        personList.add(new Person("Alisa", 7900, 16,"female", "New York"));
        List<Integer> list = Arrays.asList(1,2,3,4,7,6,5,8);
        List<String> strList = Arrays.asList("ad,nm", "adm,mt", "p,ot", "xb,angd", "weou,jgsd");
//        求Integer集合的元素之和、乘积和最大值
        // 求和方式1
        Optional<Integer> reduce = list.stream().reduce((x, y) -> x + y);
        // 求和方式2
        Optional<Integer> reduce1 = list.stream().reduce(Integer::sum);
        // 求和方式3
        Integer reduce2 = list.stream().reduce(0, Integer::sum);
        // 求乘积
        Optional<Integer> reduce3 = list.stream().reduce((x, y) -> x * y);
        // 求最大值方式1
        Optional<Integer> reduce4 = list.stream().reduce((x, y) -> x > y ? x : y);
        // 求最大值写法2
        Integer reduce5 = list.stream().reduce(1, Integer::max);
//        求所有员工的工资之和和最高工资
        // 求和方式1
        Optional<Integer> reduce7 = personList.stream().map(Person::getSalary).reduce(Integer::sum);
        // 求和方式2
        Integer reduce6 = personList.stream().reduce(0, (sum, p) -> sum += p.getSalary(),(sum1,sum2)->sum1+sum2);
        // 求和方式3
        Integer reduce8 = personList.stream().reduce(0, (sum, p) -> sum += p.getSalary(), Integer::sum);
        // 求最高工资方式1:
        Integer reduce9 = personList.stream().reduce(0, (max, p) -> max > p.getSalary() ? max : p.getSalary(),Integer::max);
        // 求最高工资方式2:
        Integer reduce10 = personList.stream().reduce(0, (max, p) -> max > p.getSalary() ? max : p.getSalary(), (max1, max2) -> max1 > max2 ? max1 : max2);
        System.out.println("list求和:" + reduce.get() + "," + reduce1.get() + "," + reduce2);
        System.out.println("list求积:" + reduce3.get());
        System.out.println("list求最大值:" + reduce4.get() + "," + reduce5);
        System.out.println("工资之和:" + reduce7.get() + "," + reduce6 + "," + reduce8);
        System.out.println("最高工资:" + reduce9 + "," + reduce10);

4.3.2.6 收集(collect)

解释

  • collect,收集,可以说是内容最繁多、功能最丰富的部分了。从字面上去理解,就是把一个流收集起来,最终可以是收集成一个值也可以收集成一个python新的集合
  • collect主要依赖java.util.stream.Collectors类内置的静态方法

4.3.2.6.1 归集(toList/toSet/toMap)

因为流不存储数据,那么在流中的数据完成处理后,需要将流中的数据重新归集到新的集合里。toList、toSet和toMap比较常用,另外还有toCollection、toConcurrentMap等复杂一些的用法

 List<Person> personList = new ArrayList<Person>();
        personList.add(new Person("Tom", 8900, 11,"male", "New York"));
        personList.add(new Person("Jack", 7000, 12,"male", "Washington"));
        personList.add(new Person("Lily", 7800, 13,"female", "Washington"));
        personList.add(new Person("Anni", 8200, 14,"female", "New York"));
        personList.add(new Person("Owen", 9500, 15,"male", "New York"));
        personList.add(new Person("Alisa", 7900, 16,"female", "New York"));
        List<Integer> list = Arrays.asList(1,2,3,4,7,6,5,8);
        List<String> strList = Arrays.asList("ad,nm", "adm,mt", "p,ot", "xb,angd", "weou,jgsd");
        List<Integer> collect = list.stream().filter(x -> x % 2 == 0).collect(Collectors.toList());
        Set<Integer> collect1 = list.stream().filter(x -> x % 2 == 0).collect(Collectors.toSet());
        Map<String, Person> collect2 = personList.stream().filter(p -> p.getSalary() > 8000).collect(Collectors.toMap(Person::getName, p -> p));
        System.out.println("toList:" + collect);
        System.out.println("toSet:" + collect1);
        System.out.println("toMap:" + collect2);

4.3.2.6.2 统计(count/averaging)

Collectors提供了一系列用于数据统计的静态方法

  • 计数:count
  • 平均值:averagingInt、averagingLong、averagingDouble
  • 最值:maxBy、minBy
  • 求和:summingInt、summin编程gLong、summingDouble
  • 统计以上所有:summarizingInt、summarizingLong、summarizingDouble
List<Person> personList = new ArrayList<Person>();
        personList.add(new Person("Tom", 8900, 11,"male", "New York"));
        personList.add(new Person("Jack", 7000, 12,"male", "Washington"));
        personList.add(new Person("Lily", 7800, 13,"female", "Washington"));
        personList.add(new Person("Anni", 8200, 14,"female", "New York"));
        personList.add(new Person("Owen", 9500, 15,"male", "New York"));
        personList.add(new Person("Alisa", 7900, 16,"female", "New York"));
        List<Integer> list = Arrays.asList(1,2,3,4,7,6,5,8);
        List<String> strList = Arrays.asList("ad,nm", "adm,mt", "p,ot", "xb,angd", "weou,jgsd");
//        统计员工人数、平均工资、工资总额、最高工资
        // 求总数
        Long collect = personList.stream().collect(Collectors.counting());
        // 求平均工资
        Double collect1 = personList.stream().collect(Collectors.averagingDouble(Person::getSalary));
        // 求最高工资
        Optional<Integer> collect2 = personList.stream().map(Person::getSalary).collect(Collectors.maxBy(Integer::compare));
        // 求工资之和
        Integer collect3 = personList.stream().collect(Collectors.summingInt(Person::getSalary));
        // 一次性统计所有信息
        DoubleSummaryStatistics collect4 = personList.stream().collect(Collectors.summarizingDouble(Person::getSalary));
        System.out.println("员工总数:" + collect);
        System.out.println("员工平均工资:" + collect1);
        System.out.println("员工工资总和:" + collect2.get());
        System.out.println("员工工资所有统计:" + collect3);

4.3.2.6.3 分组(partitioningBy/groupingBy)

解释

  • 分区:将stream按条件分为两个Map,比如员工按薪资是否高于8000分为两部分。
  • 分组:将集合分为多个Map,比如员工按性别分组。有单级分组和多级分组。
List<Person> personList = new ArrayList<Person>();
        personList.add(new Person("Tom", 8900, 11,"male", "New York"));
        personList.add(new Person("Jack", 7000, 12,"male", "Washington"));
        personList.add(new Person("Lily", 7800, 13,"female", "Washington"));
        personList.add(new Person("Anni", 8200, 14,"female", "New York"));
        personList.add(new Person("Owen", 9500, 15,"male", "New York"));
        personList.add(new Person("Alisa", 7900, 16,"female", "New York"));
        List<Integer> list = Arrays.asList(1,2,3,4,7,6,5,8);
        List<String> strList = Arrays.asList("ad,nm", "adm,mt", "p,ot", "xb,angd", "weou,jgsd");
        //将员工按薪资是否高于8000分为两部分;将员工按性别和地区分组
        // 将员工按薪资是否高于8000分组
        Map<Boolean, List<Person>> collect = personList.stream().collect(Collectors.partitioningBy(person -> person.getSalary() > 8000));
        // 将员工按性别分组
        Map<String, List<Person>> collect1 = personList.stream().collect(Collectors.groupingBy(Person::getSex));
        // 将员工先按性别分组,再按地区分组
        Map<String, Map<String, List<Person>>> collect2 = personList.stream().collect(Collectors.groupingBy(Person::getSex, Collectors.groupingBy(PersChina编程on::getArea)));
        System.out.println("员工按薪资是否大于8000分组情况:" + collect);
        System.out.println("员工按性别分组情况:" + collect1);
        System.out.println("员工按性别、地区:" + collect2);

4.3.2.6.4 接合(joining)

joining可以将stream中的元素用特定的连接符(没有的话,则直接连接)连接成一个字符串。

  List<Person> personList = new ArrayList<Person>();
        personList.add(new Person("Tom", 8900, 11,"male", "New York"));
        personList.add(new Person("Jack", 7000, 12,"male", "Washington"));
        personList.add(new Person("Lily", 7800, 13,"female", "Washington"));
        personList.add(new Person("Anni", 8200, 14,"female", "New York"));
        personList.add(new Person("Owen", 9500, 15,"male", "New York"));
        personList.add(new Person("Alisa", 7900, 16,"female", "New York"));
        List<Integer> list = Arrays.asList(1,2,3,4,7,6,5,8);
        List<String> strList = Arrays.asList("ad,nm", "adm,mt", "p,ot", "xb,angd", "weou,jgsd");
        //字符串拼接
        String collect = strList.stream().collect(Collectors.joining("-"));
        //所有员工的名字
        String collect1 = personList.stream().map(Person::getName).collect(Collectors.joining(","));
        System.out.println("所有员工的姓名:" + collect1);
        System.out.println("拼接后的字符串:" + collect);

4.3.2.6.5 归约(reducing)

Collectors类提供的reducing方法,相比于stream本身的reduce方法,增加了对自定义归约的支持

 List<Person> personList = new ArrayList<Person>();
        personList.add(new Person("Tom", 8900, 11,"male", "New York"));
        personList.add(new Person("Jack", 7000, 12,"male", "Washington"));
        personList.add(new Person("Lily", 7800, 13,"female", "Washington"));
        personList.add(new Person("Anni", 8200, 14,"female", "New York"));
        personList.add(new Person("Owen", 9500, 15,"male", "New York"));
        personList.add(new Person("Alisa", 7900, 16,"female", "New York"));
        List<Integer> list = Arrays.asList(1,2,3,4,7,6,5,8);
        List<String> strList = Arrays.asList("ad,nm", "adm,mt", "p,ot", "xb,angd", "weou,jgsd");
        // 每个员工减去起征点后的薪资之和(这个例子并不严谨,但一时没想到好的例子)
        Integer collect = personList.stream().collect(Collectors.reducing(0, Person::getSalary, (i, j) -> i + j - 5000));
        System.out.println("员工扣税薪资总和:" + collect);
        // stream的reduce
        Optional<Integer> reduce = personList.stream().map(Person::getSalary).reduce(Integer::sum);
        System.out.println("员工扣税薪资总和:" + reduce.get());

4.3.2.7 排序(sorted)

解释

  • sorted():自然排序,流中元素需实现Comparable接口
  • sorted(Comparator com):Comparator排序器自定义排序
List<Person> personList = new ArrayList<Person>();
        personList.add(new Person("Tom", 8900, 11,"male", "New York"));
        personList.add(new Person("Jack", 7000, 12,"male", "Washington"));
        personList.add(new Person("Lily", 7800, 13,"female", "Washington"));
        personList.add(new Person("Anni", 8200, 14,"female", "New York"));
        personList.add(new Person("Owen", 9500, 15,"male", "New York"));
        personList.add(new Person("Alisa", 7900, 16,"female", "New York"));
        List<Integer> list = Arrays.asList(1,2,3,4,7,6,5,8);
        List<String> strList = Arrays.asList("ad,nm", "adm,mt", "p,ot", "xb,angd", "weou,jgsd");
        // 按工资增序排序
        List<String> newList = personList.stream().sorted(Comparator.comparing(Person::getSalary)).map(Person::getName)
                .collect(Collectors.toList());
        // 按工资倒序排序
        List<String> newList2 = personList.stream().sorted(Comparator.comparing(Person::getSalary).reversed())
                .map(Person::getName).collect(Collectors.toList());
        // 先按工资再按年龄自然排序(从小到大)
        List<String> newList3 = personList.stream().sorted(Comparator.comparing(Person::getSalary).reversed())
                .map(Person::getName).collect(Collectors.toList());
        // 先按工资再按年龄自定义排序(从大到小)
        List<String> newList4 = personList.stream().sorted((p1, p2) -> {
            if (p1.getSalary() == p2.getSalary()) {
                return p2.getAge() - p1.getAge();
            } else {
                return p2.getSalary() - p1.getSalary();
            }
        }).map(Person::getName).collect(Collectors.toList());
        System.out.println("按工资自然排序:" + newList);
        System.out.println("按工资降序排序:" + newList2);
        System.out.println("先按工资再按年龄自然排序:" + newList3);
        System.out.println("先按工资再按年龄自定义降序排序:" + newList4);

4.3.2.8 提取/组合(distinct,skip,limit)

流也可以进行合并、去重、限制、跳过等操作。

String[] arr1 = { "a", "b", "c", "d" };
        String[] arr2 = { "d", "e", "f", "g" };
        Stream<String> stream1 = Stream.of(arr1);
        Stream<String> stream2 = Stream.of(arr2);
        // concat:合并两个流 distinct:去重
        List<String> newList = Stream.concat(stream1, stream2).distinct().collect(Collectors.toList());
        // limit:限制从流中获得前n个数据
        List<Integer> collect = Stream.iterate(1, x -> x + 2).limit(10).collect(Collectors.toList());
        // skip:跳过前n个数据
        List<Integer> collect2 = Stream.iterate(1, x -> x + 2).skip(1).limit(5).collect(Collectors.toList());
        System.out.println("流合并:" + newList);
        System.out.println("limit:" + collect);
        System.out.println("skip:" + collect2);

到此这篇关于Java Stream流使用案例深入详解的文章就介绍到这了,更多相关Java Stream流内容请搜索编程China编程(www.chinasem.cn)以前的文章或继续浏览下面的相关文章希望大家以后多多支持China编程(www.chinasem.cn)!

这篇关于Java Stream流使用案例深入详解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1154413

相关文章

如何在 Spring Boot 中实现 FreeMarker 模板

《如何在SpringBoot中实现FreeMarker模板》FreeMarker是一种功能强大、轻量级的模板引擎,用于在Java应用中生成动态文本输出(如HTML、XML、邮件内容等),本文... 目录什么是 FreeMarker 模板?在 Spring Boot 中实现 FreeMarker 模板1. 环

使用Python和Pyecharts创建交互式地图

《使用Python和Pyecharts创建交互式地图》在数据可视化领域,创建交互式地图是一种强大的方式,可以使受众能够以引人入胜且信息丰富的方式探索地理数据,下面我们看看如何使用Python和Pyec... 目录简介Pyecharts 简介创建上海地图代码说明运行结果总结简介在数据可视化领域,创建交互式地

SpringMVC 通过ajax 前后端数据交互的实现方法

《SpringMVC通过ajax前后端数据交互的实现方法》:本文主要介绍SpringMVC通过ajax前后端数据交互的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价... 在前端的开发过程中,经常在html页面通过AJAX进行前后端数据的交互,SpringMVC的controll

Java中的工具类命名方法

《Java中的工具类命名方法》:本文主要介绍Java中的工具类究竟如何命名,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录Java中的工具类究竟如何命名?先来几个例子几种命名方式的比较到底如何命名 ?总结Java中的工具类究竟如何命名?先来几个例子JD

Spring Security自定义身份认证的实现方法

《SpringSecurity自定义身份认证的实现方法》:本文主要介绍SpringSecurity自定义身份认证的实现方法,下面对SpringSecurity的这三种自定义身份认证进行详细讲解,... 目录1.内存身份认证(1)创建配置类(2)验证内存身份认证2.JDBC身份认证(1)数据准备 (2)配置依

SpringBoot整合OpenFeign的完整指南

《SpringBoot整合OpenFeign的完整指南》OpenFeign是由Netflix开发的一个声明式Web服务客户端,它使得编写HTTP客户端变得更加简单,本文为大家介绍了SpringBoot... 目录什么是OpenFeign环境准备创建 Spring Boot 项目添加依赖启用 OpenFeig

Java Spring 中 @PostConstruct 注解使用原理及常见场景

《JavaSpring中@PostConstruct注解使用原理及常见场景》在JavaSpring中,@PostConstruct注解是一个非常实用的功能,它允许开发者在Spring容器完全初... 目录一、@PostConstruct 注解概述二、@PostConstruct 注解的基本使用2.1 基本代

C#使用StackExchange.Redis实现分布式锁的两种方式介绍

《C#使用StackExchange.Redis实现分布式锁的两种方式介绍》分布式锁在集群的架构中发挥着重要的作用,:本文主要介绍C#使用StackExchange.Redis实现分布式锁的... 目录自定义分布式锁获取锁释放锁自动续期StackExchange.Redis分布式锁获取锁释放锁自动续期分布式

springboot使用Scheduling实现动态增删启停定时任务教程

《springboot使用Scheduling实现动态增删启停定时任务教程》:本文主要介绍springboot使用Scheduling实现动态增删启停定时任务教程,具有很好的参考价值,希望对大家有... 目录1、配置定时任务需要的线程池2、创建ScheduledFuture的包装类3、注册定时任务,增加、删

SpringBoot整合mybatisPlus实现批量插入并获取ID详解

《SpringBoot整合mybatisPlus实现批量插入并获取ID详解》这篇文章主要为大家详细介绍了SpringBoot如何整合mybatisPlus实现批量插入并获取ID,文中的示例代码讲解详细... 目录【1】saveBATch(一万条数据总耗时:2478ms)【2】集合方式foreach(一万条数