Consumer是消费性接口,通用的方法是用accept()方法;

实体类

    /**
     * 消费型接口,有参数,无返回值类型的接口。
     */
    @Test
    public void consumerTest() {
        User user = User.builder().build();
        UserPageDto userPageDto = new UserPageDto();
        userPageDto.setUserName("张三");
        userPageDto.setRole(2);
        cosumerMethod(user, userPageDto, (x, y) -> BeanUtils.copyProperties(x, y));
        cosumerMethod1(user, (x) -> System.out.println(x));
        cosumerMethod1(user, System.out::println);
    }
    
    private void cosumerMethod1(User user, Consumer<User> cu) {
        cu.accept(user);
    }

    private void cosumerMethod(User user, UserPageDto userPageDto, BiConsumer<UserPageDto,User> bc) {
        bc.accept(userPageDto, user);
    }

其中user和userPageDto可以如下:

@Data
public class UserPageDto {

    private String userName;
    private Integer role;

}

相关文章:

  • 2022-01-07
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2021-11-07
  • 2021-12-11
  • 2022-01-09
猜你喜欢
  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-24
相关资源
相似解决方案