业务层:
1 2 3 4 5 6 7 8 9 10 11 12 13 | /** * 测试一下 */ @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); } } |
工具类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | 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); } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步