业务层:
/** * 测试一下 */ @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); } }