zoukankan      html  css  js  c++  java
  • lamda表达式

    业务层:

        /**
         * 测试一下
         */
        @GetMapping("/test")
        public void test(@RequestBody(required = false) List<Person> roster, int low, int high) {
            roster.forEach(p -> test2(p.getAge(), low, high));
        }
    
        private void test2(int age, int low, int high) {
            if (low <= age && age < high) {
                Person.printPerson(age);
            }
        }
    

      工具类

    package com.onlyphoto.jupiteragent.controller;
    
    import java.time.LocalDate;
    
    
    public class Person {
    
        public enum Sex {
            MALE, FEMALE
        }
        int age;
        String name;
        LocalDate birthday;
        Sex gender;
        String emailAddress;
    
        public void setAge(int age) {
            this.age = age;
        }
    
        public Person(int age, String name, LocalDate birthday, Sex gender, String emailAddress) {
            this.age = age;
            this.name = name;
            this.birthday = birthday;
            this.gender = gender;
            this.emailAddress = emailAddress;
        }
    
        public Person(int age) {
            this.age = age;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public LocalDate getBirthday() {
            return birthday;
        }
    
        public void setBirthday(LocalDate birthday) {
            this.birthday = birthday;
        }
    
        public Sex getGender() {
            return gender;
        }
    
        public void setGender(Sex gender) {
            this.gender = gender;
        }
    
        public String getEmailAddress() {
            return emailAddress;
        }
    
        public void setEmailAddress(String emailAddress) {
            this.emailAddress = emailAddress;
        }
    
        public int getAge() {
            // ...
            return this.age;
        }
    
        public static void printPerson(int age) {
            // ...
    //        this.age = age;
            System.out.println("年龄在合适范围的为: " + age);
        }
    }
    

      

  • 相关阅读:
    Stm32ADC-内部温度传感器的使用
    Stm32 ADC学习
    wpf数据绑定
    06 MyBatis——实体类注意事项
    05 MyBatis——环境搭建及demo
    96 项目导jar包
    04 SSM框架概述
    03 MVC开发模式
    02 Mybaits——包名的命名规范
    26 监听器实现网站在线人数统计
  • 原文地址:https://www.cnblogs.com/MaxElephant/p/14977939.html
Copyright © 2011-2022 走看看