Explorar el Código

day 24 25 26 代码

fanjialong hace 10 horas
padre
commit
bba438c3c6
Se han modificado 67 ficheros con 2640 adiciones y 0 borrados
  1. 13 0
      java-base-project10/day24/day24.iml
  2. BIN
      java-base-project10/day24/lib/dom4j-2.1.1.jar
  3. BIN
      java-base-project10/day24/lib/hamcrest-core-1.3.jar
  4. BIN
      java-base-project10/day24/lib/junit-4.12.jar
  5. 15 0
      java-base-project10/day24/resources/account-config.xml
  6. 5 0
      java-base-project10/day24/resources/spring.xml
  7. 23 0
      java-base-project10/day24/resources/students-config.xml
  8. 14 0
      java-base-project10/day24/resources/students.properties
  9. 50 0
      java-base-project10/day24/src/com/sf/_01_xml/Account.java
  10. 91 0
      java-base-project10/day24/src/com/sf/_01_xml/Student.java
  11. 207 0
      java-base-project10/day24/src/com/sf/_01_xml/XmlTest.java
  12. 86 0
      java-base-project10/day24/src/com/sf/_02_反射/javabean/Anmail.java
  13. 18 0
      java-base-project10/day24/src/com/sf/_02_反射/javabean/Coffee.java
  14. 15 0
      java-base-project10/day24/src/com/sf/_02_反射/javabean/Coke.java
  15. 50 0
      java-base-project10/day24/src/com/sf/_02_反射/javabean/Drink.java
  16. 16 0
      java-base-project10/day24/src/com/sf/_02_反射/javabean/MilkTea.java
  17. 41 0
      java-base-project10/day24/src/com/sf/_02_反射/javabean/Teacher.java
  18. 68 0
      java-base-project10/day24/src/com/sf/_02_反射/javabean/User.java
  19. 15 0
      java-base-project10/day24/src/com/sf/_02_反射/javabean/Water.java
  20. 232 0
      java-base-project10/day24/src/com/sf/_02_反射/test/ClassTest.java
  21. 27 0
      java-base-project10/day24/src/com/sf/_02_反射/util/PrintJavaBean.java
  22. 17 0
      java-base-project10/day25/day25.iml
  23. BIN
      java-base-project10/day25/lib/createjavabean.jar
  24. BIN
      java-base-project10/day25/lib/dom4j-2.1.1.jar
  25. BIN
      java-base-project10/day25/lib/hamcrest-core-1.3.jar
  26. BIN
      java-base-project10/day25/lib/junit-4.13.jar
  27. BIN
      java-base-project10/day25/lib/lombok-1.18.30.jar
  28. 4 0
      java-base-project10/day25/resources/spring.xml
  29. 57 0
      java-base-project10/day25/src/com/sf/_01_class/javabean/Student.java
  30. 50 0
      java-base-project10/day25/src/com/sf/_01_class/javabean/Teacher.java
  31. 62 0
      java-base-project10/day25/src/com/sf/_01_class/test/ClassTest.java
  32. 86 0
      java-base-project10/day25/src/com/sf/_02_introspection/javabean/Dog.java
  33. 68 0
      java-base-project10/day25/src/com/sf/_02_introspection/javabean/Student.java
  34. 160 0
      java-base-project10/day25/src/com/sf/_02_introspection/test/IntrospectTest.java
  35. 75 0
      java-base-project10/day25/src/com/sf/_02_introspection/util/MapAndJavaBeanConvertUtil.java
  36. 10 0
      java-base-project10/day25/src/com/sf/_03_lombda/Student.java
  37. 11 0
      java-base-project10/day25/src/com/sf/_03_lombda/Test.java
  38. 8 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo1/Dog.java
  39. 8 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo1/Fish.java
  40. 8 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo1/ISwim.java
  41. 48 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo1/LambdaTest.java
  42. 15 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo2/Data.java
  43. 11 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo2/IConditionAble.java
  44. 5 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo2/IFunAble.java
  45. 91 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo2/MyTest.java
  46. 53 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo2/MyTest1.java
  47. 91 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo2/Product.java
  48. 6 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo3/ICallAble.java
  49. 26 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo3/ICallAbleImpl.java
  50. 6 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo3/IRandomable.java
  51. 5 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo3/IShowable.java
  52. 49 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo3/MyTest.java
  53. 5 0
      java-base-project10/day25/src/com/sf/_03_lombda/demo3/StringHandler.java
  54. 12 0
      java-base-project10/day26/day26.iml
  55. BIN
      java-base-project10/day26/lib/hamcrest-core-1.3.jar
  56. BIN
      java-base-project10/day26/lib/junit-4.13.jar
  57. BIN
      java-base-project10/day26/lib/lombok-1.18.30.jar
  58. 13 0
      java-base-project10/day26/src/com/sf/_01_lombok/LombokTest.java
  59. 14 0
      java-base-project10/day26/src/com/sf/_01_lombok/Student.java
  60. 15 0
      java-base-project10/day26/src/com/sf/_02_lombda/Data.java
  61. 10 0
      java-base-project10/day26/src/com/sf/_02_lombda/IConditionAble.java
  62. 144 0
      java-base-project10/day26/src/com/sf/_02_lombda/LambdaTest.java
  63. 16 0
      java-base-project10/day26/src/com/sf/_02_lombda/Product.java
  64. 14 0
      java-base-project10/day26/src/com/sf/_03_jdk8_interface/IFunAble.java
  65. 18 0
      java-base-project10/day26/src/com/sf/_03_jdk8_interface/IFunAbleImpl.java
  66. 344 0
      java-base-project10/day26/src/com/sf/_04_stream/StreamTest.java
  67. 19 0
      java-base-project10/day26/src/com/sf/_04_stream/Student.java

+ 13 - 0
java-base-project10/day24/day24.iml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" name="dom4j-2.1.1 (2)" level="project" />
+  </component>
+</module>

BIN
java-base-project10/day24/lib/dom4j-2.1.1.jar


BIN
java-base-project10/day24/lib/hamcrest-core-1.3.jar


BIN
java-base-project10/day24/lib/junit-4.12.jar


+ 15 - 0
java-base-project10/day24/resources/account-config.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<accounts>
+    <account>
+        <username>zhangsan</username>
+        <password>123</password>
+    </account>
+    <account>
+        <username>lisi</username>
+        <password>123</password>
+    </account>
+    <account>
+        <username>admin</username>
+        <password>123</password>
+    </account>
+</accounts>

+ 5 - 0
java-base-project10/day24/resources/spring.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<beans>
+    <bean class="com.sf._02_反射.javabean.Teacher"></bean>
+    <bean class="com.sf._02_反射.javabean.User"></bean>
+</beans>

+ 23 - 0
java-base-project10/day24/resources/students-config.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<students>
+    <student >
+        <id>1</id>
+        <name>xiaoming</name>
+        <age>18</age>
+        <score>90</score>
+    </student>
+
+    <student >
+        <id>1</id>
+        <name>xiaowang</name>
+        <age>18</age>
+        <score>95</score>
+    </student>
+
+    <student >
+        <id>3</id>
+        <name>xiaoli</name>
+        <age>18</age>
+        <score>99</score>
+    </student>
+</students>

+ 14 - 0
java-base-project10/day24/resources/students.properties

@@ -0,0 +1,14 @@
+student1_id=1
+student1_name=zhangsan
+student1_age=10
+student1_score=80
+
+student2_id=2
+student2_name=lisi
+student2_age=10
+student2_score=85
+
+student3_id=3
+student3_name=wangwu
+student3_age=10
+student3_score=90

+ 50 - 0
java-base-project10/day24/src/com/sf/_01_xml/Account.java

@@ -0,0 +1,50 @@
+package com.sf._01_xml;
+
+public class Account {
+    private String username;
+    private String password;
+
+    public Account() {
+    }
+
+    public Account(String username, String password) {
+        this.username = username;
+        this.password = password;
+    }
+
+    /**
+     * 获取
+     * @return username
+     */
+    public String getUsername() {
+        return username;
+    }
+
+    /**
+     * 设置
+     * @param username
+     */
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    /**
+     * 获取
+     * @return password
+     */
+    public String getPassword() {
+        return password;
+    }
+
+    /**
+     * 设置
+     * @param password
+     */
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String toString() {
+        return "Account{username = " + username + ", password = " + password + "}";
+    }
+}

+ 91 - 0
java-base-project10/day24/src/com/sf/_01_xml/Student.java

@@ -0,0 +1,91 @@
+package com.sf._01_xml;
+
+public class Student implements Comparable<Student>{
+    private Long id;
+    private String name;
+    private Integer age;
+    private double score;
+
+    public Student() {
+    }
+
+    public Student(Long id, String name, Integer age, double score) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+        this.score = score;
+    }
+
+    /**
+     * 获取
+     * @return id
+     */
+    public Long getId() {
+        return id;
+    }
+
+    /**
+     * 设置
+     * @param id
+     */
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public Integer getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return score
+     */
+    public double getScore() {
+        return score;
+    }
+
+    /**
+     * 设置
+     * @param score
+     */
+    public void setScore(double score) {
+        this.score = score;
+    }
+
+    public String toString() {
+        return "Student{id = " + id + ", name = " + name + ", age = " + age + ", score = " + score + "}";
+    }
+
+    @Override
+    public int compareTo(Student o) {
+        return (int) (o.getScore() - this.getScore());
+    }
+}

+ 207 - 0
java-base-project10/day24/src/com/sf/_01_xml/XmlTest.java

@@ -0,0 +1,207 @@
+package com.sf._01_xml;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.*;
+
+public class XmlTest {
+
+    /**
+     * 解析xml 文件
+     * 操作步骤
+     * 1 使用类加载器加载配置文件
+     * 2 使用SAXRedler  read 方法读取配置文件
+     * 3 使用相关api 获取配置文件信息
+     *
+     * 获取第二个student 的age
+     */
+    @Test
+    public void test() throws DocumentException {
+        //1  使用类加载器加载配置文件
+        InputStream inputStream = Thread.currentThread().
+                getContextClassLoader().
+                getResourceAsStream("students-config.xml");
+
+        //2 创建SAXReader 加载输入流当中信息
+        SAXReader saxReader = new SAXReader();
+        Document document = saxReader.read(inputStream);
+        //3 document ->根元素(students)-> 获取根元素所有的子元素 -> 获取第一个student 元素-> 获取name元素-> 获取元素内容
+        Element rootElement = document.getRootElement();
+        //4 获取students 所有子标签 -> 第一个student
+        Element element = rootElement.elements().get(0);
+        //5 获取studnet 当中name
+        Element nameEle = element.element("name");
+        //6 获取name 标签内容
+        System.out.println("name内容为:"+ nameEle.getText());
+    }
+
+
+    /**
+     * acount-config.xml
+     * acounts
+     *    acount
+     *       username  zhangsan
+     *       password  123
+     *    acount
+     *       username  lisi
+     *       password  123
+     *    acount
+     *       username admin
+     *       password 123
+     * 要求把xml 文件信息加载到集合中
+     * 做登录 定义name 表示用户输入账号  定义一个passwd 用户输入米啊
+     * 遍历集合 看是否对比成功,如果对比成功登录 , 如果失败登录失败
+     */
+    @Test
+    public void test1() throws DocumentException {
+        // 1 先使用类加载加载配置文件信息
+        InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("account-config.xml");
+        // 2 SAXReader 读取信息返回document
+        SAXReader saxReader = new SAXReader();
+        Document document = saxReader.read(inputStream);
+        // 3获取根标签
+        Element rootElement = document.getRootElement();
+        // 4 获取子标签封装
+        List<Account> list = new ArrayList<>();
+        for (Element element : rootElement.elements()) {
+            // 获取username 值 和password 的值封装到Account 对象中
+            String username = element.element("username").getText();
+            String password = element.element("password").getText();
+            Account account = new Account(username,password);
+            // 对象添加到集合中即可
+            list.add(account);
+        }
+        String name = "lisi";
+        String passwd = "123";
+        boolean flag = false;
+        for (Account account : list) {
+            if(name.equals(account.getUsername())&& passwd.equals(account.getPassword())){
+                flag = true;
+            }
+        }
+        if(flag){
+            System.out.println("登录成功");
+        }else{
+            System.out.println("登录失败");
+        }
+    }
+
+
+    /**
+     * 1 创建students.properties 文件
+     *  student1_id=1
+     *  studnet1_name=2
+     *  student1_age=3
+     *  student1_score=90
+     *  3 个信息 和上面雷同
+     *  ......
+     * 2 创建students-config.xml 文件
+     *  <students>
+     *      <student>
+     *          <id>1</id>
+     *          <name>xiaoming</name>
+     *          <age>10</age>
+     *          <score>99</score>
+     *      </student>
+     *      ...
+     *      创建3个学生
+     *  </students>
+     *  3 要求properties 学生信息是1班学生 , xml 学生信息是2班学生信息
+     *  4 要求看两个班学生排名 从大到小
+     *      每个班的平均分  每个班的最高分  每个班的最低分    总榜最高分和最低分
+     */
+    @Test
+    public void test2() throws DocumentException, IOException {
+        // 1 加载properites
+        InputStream xmlInputStream = Thread.currentThread().getContextClassLoader().
+                getResourceAsStream("students-config.xml");
+        // 2 加载xml
+        InputStream propertiesInputStream = Thread.currentThread().getContextClassLoader().
+                getResourceAsStream("students.properties");
+        //3 读取xml SAXReader
+        SAXReader saxReader = new SAXReader();
+        //4 读取properties 类 Properties
+        Properties properties = new Properties();
+        Document document = saxReader.read(xmlInputStream);
+        properties.load(propertiesInputStream);
+        // 创建集合存储xml 学生信息和properties 学生信息
+        List<Student> xmlStudends = new ArrayList<>();
+
+        // 读取xml 信息
+        Element rootElement = document.getRootElement();
+        // 获取跟标签子元素
+        for (Element element : rootElement.elements()) {
+            String id = element.element("id").getText();
+            String name = element.element("name").getText();
+            String age = element.element("age").getText();
+            String score = element.element("score").getText();
+            // 把xml 文件当中数据封装到对象中
+            Student student = new Student();
+            student.setId(Long.valueOf(id));
+            student.setName(name);
+            student.setAge(Integer.valueOf(age));
+            student.setScore(Double.valueOf(score));
+            // 添加到集合中
+            xmlStudends.add(student);
+        }
+        // 遍历封装
+        // 计算xml 里面学生平均分最高分和最低分
+        Double xmlTotalScore  = 0.0 ;
+        for (Student xmlStudend : xmlStudends) {
+            xmlTotalScore += xmlStudend.getScore();
+        }
+        System.out.println("xml 学生平均分为:"+ xmlTotalScore/xmlStudends.size());
+        // 使用工具类进行排序
+        Collections.sort(xmlStudends);
+        double xmlMaxScore = xmlStudends.get(0).getScore();
+
+        System.out.println("xml 班级最高分"+ xmlMaxScore);
+        System.out.println("xml 班级最低分:"+ xmlStudends.get(xmlStudends.size()-1).getScore());
+
+        // 解析properties 文件信息
+        List<Student> propertiesStudents =  new ArrayList<>();
+        Student student1 = new Student();
+        student1.setId(Long.valueOf(properties.getProperty("student1_id")));
+        student1.setName((properties.getProperty("student1_name")));
+        student1.setScore(Double.valueOf(properties.getProperty("student1_score")));
+        student1.setAge(Integer.valueOf(properties.getProperty("student1_age")));
+        propertiesStudents.add(student1);
+
+        Student student2 = new Student();
+        student2.setId(Long.valueOf(properties.getProperty("student2_id")));
+        student2.setName((properties.getProperty("student2_name")));
+        student2.setScore(Double.valueOf(properties.getProperty("student2_score")));
+        student2.setAge(Integer.valueOf(properties.getProperty("student2_age")));
+        propertiesStudents.add(student2);
+
+        Student student3 = new Student();
+        student3.setId(Long.valueOf(properties.getProperty("student3_id")));
+        student3.setName((properties.getProperty("student3_name")));
+        student3.setScore(Double.valueOf(properties.getProperty("student3_score")));
+        student3.setAge(Integer.valueOf(properties.getProperty("student3_age")));
+        propertiesStudents.add(student3);
+
+        // 平均分
+        Double propertiesTotalScore = 0.0;
+        for (Student propertiesStudent : propertiesStudents) {
+            propertiesTotalScore += propertiesStudent.getScore();
+        }
+        System.out.println("properties 班级的平均分:"+ (propertiesTotalScore/propertiesStudents.size()));
+        // 排序
+        Collections.sort(propertiesStudents);
+        double propertiesMaxScore = propertiesStudents.get(0).getScore();
+        System.out.println("properties 班级最高分:"+ propertiesMaxScore);
+        System.out.println("properties 班级最低分:"+ propertiesStudents.get(propertiesStudents.size()-1).getScore());
+
+        // 求两个班级最高分
+        Double allMaxScore = xmlMaxScore > propertiesMaxScore ? xmlMaxScore : propertiesMaxScore;
+        System.out.println("全年级最高分:"+allMaxScore);
+    }
+
+}

+ 86 - 0
java-base-project10/day24/src/com/sf/_02_反射/javabean/Anmail.java

@@ -0,0 +1,86 @@
+package com.sf._02_反射.javabean;
+
+public class Anmail {
+    private Long id;
+    private String name;
+    private int age;
+    private String color;
+
+    public Anmail() {
+    }
+
+    public Anmail(Long id, String name, int age, String color) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+        this.color = color;
+    }
+
+    /**
+     * 获取
+     * @return id
+     */
+    public Long getId() {
+        return id;
+    }
+
+    /**
+     * 设置
+     * @param id
+     */
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public int getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return color
+     */
+    public String getColor() {
+        return color;
+    }
+
+    /**
+     * 设置
+     * @param color
+     */
+    public void setColor(String color) {
+        this.color = color;
+    }
+
+    public String toString() {
+        return "Anmail{id = " + id + ", name = " + name + ", age = " + age + ", color = " + color + "}";
+    }
+}

+ 18 - 0
java-base-project10/day24/src/com/sf/_02_反射/javabean/Coffee.java

@@ -0,0 +1,18 @@
+package com.sf._02_反射.javabean;
+
+public class Coffee extends Drink{
+
+
+
+    public Coffee() {
+    }
+
+    private Coffee(String name, String brand) {
+        super(name, brand);
+    }
+
+    @Override
+    public String toString() {
+        return "name:="+ this.getName() +"-brand:"+this.getBrand();
+    }
+}

+ 15 - 0
java-base-project10/day24/src/com/sf/_02_反射/javabean/Coke.java

@@ -0,0 +1,15 @@
+package com.sf._02_反射.javabean;
+
+public class Coke  extends Drink{
+    public Coke() {
+    }
+
+    private Coke(String name, String brand) {
+        super(name, brand);
+    }
+
+    @Override
+    public String toString() {
+        return "name:="+ this.getName() +"-brand:"+this.getBrand();
+    }
+}

+ 50 - 0
java-base-project10/day24/src/com/sf/_02_反射/javabean/Drink.java

@@ -0,0 +1,50 @@
+package com.sf._02_反射.javabean;
+
+public class Drink {
+    private String name;
+    private String brand;
+
+    public Drink() {
+    }
+
+    public Drink(String name, String brand) {
+        this.name = name;
+        this.brand = brand;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return brand
+     */
+    public String getBrand() {
+        return brand;
+    }
+
+    /**
+     * 设置
+     * @param brand
+     */
+    public void setBrand(String brand) {
+        this.brand = brand;
+    }
+
+    public String toString() {
+        return "Drink{name = " + name + ", brand = " + brand + "}";
+    }
+}

+ 16 - 0
java-base-project10/day24/src/com/sf/_02_反射/javabean/MilkTea.java

@@ -0,0 +1,16 @@
+package com.sf._02_反射.javabean;
+
+public class MilkTea  extends Drink{
+
+    public MilkTea() {
+    }
+
+    private MilkTea(String name, String brand) {
+        super(name, brand);
+    }
+
+    @Override
+    public String toString() {
+        return "name:="+ this.getName() +"-brand:"+this.getBrand();
+    }
+}

+ 41 - 0
java-base-project10/day24/src/com/sf/_02_反射/javabean/Teacher.java

@@ -0,0 +1,41 @@
+package com.sf._02_反射.javabean;
+
+public class Teacher {
+    private Long id;
+    private String name;
+    private Double salary;
+
+    public Teacher() {
+    }
+
+    private Teacher(Long id,String name){
+        this.id = id;
+        this.name= name;
+    }
+    public Teacher(Long id, String name, Double salary) {
+        this.id = id;
+        this.name = name;
+        this.salary = salary;
+    }
+
+    public String toString() {
+        return "Teacher{id = " + id + ", name = " + name + ", salary = " + salary + "}";
+    }
+
+    public void method1(){
+        System.out.println("这是public 修饰方法1");
+    }
+
+    private void method2(){
+        System.out.println("这是private 修饰方法2");
+    }
+
+
+    public void method1(String name){
+        System.out.println("这是public修饰带参数name method1");
+    }
+
+    private void method2(String name){
+        System.out.println("这是private 修饰带参数method 2");
+    }
+}

+ 68 - 0
java-base-project10/day24/src/com/sf/_02_反射/javabean/User.java

@@ -0,0 +1,68 @@
+package com.sf._02_反射.javabean;
+
+public class User {
+    private Long id;
+    private String name;
+    private int age;
+
+    public User() {
+    }
+
+    public User(Long id, String name, int age) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return id
+     */
+    public Long getId() {
+        return id;
+    }
+
+    /**
+     * 设置
+     * @param id
+     */
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public int getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    public String toString() {
+        return "User{id = " + id + ", name = " + name + ", age = " + age + "}";
+    }
+}

+ 15 - 0
java-base-project10/day24/src/com/sf/_02_反射/javabean/Water.java

@@ -0,0 +1,15 @@
+package com.sf._02_反射.javabean;
+
+public class Water extends Drink{
+    public Water() {
+    }
+
+    public Water(String name, String brand) {
+        super(name, brand);
+    }
+
+    @Override
+    public String toString() {
+        return "name:="+ this.getName() +"-brand:"+this.getBrand();
+    }
+}

+ 232 - 0
java-base-project10/day24/src/com/sf/_02_反射/test/ClassTest.java

@@ -0,0 +1,232 @@
+package com.sf._02_反射.test;
+
+import com.sf._01_xml.Student;
+import com.sf._02_反射.javabean.*;
+import com.sf._02_反射.util.PrintJavaBean;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+import org.junit.Test;
+
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.List;
+
+public class ClassTest {
+
+    /**
+     * 测试打印java Bean 信息
+     */
+    @Test
+    public void test(){
+        PrintJavaBean.printJavaBean(new User(1L,"zhangsan",10));
+        PrintJavaBean.printJavaBean(new Teacher(1L,"wangwu",1000.0));
+
+    }
+
+
+    /**
+     * 获取字节码信息
+     * 第一种: Class.forName("完整包名.类名"); 类的全限定名
+     * 第二种: 传入的参数getClass(); 或者字节码信息
+     * 第三种: 直接类名.class
+     * */
+    @Test
+    public void test1() throws ClassNotFoundException {
+        // 第一种获取字节码
+//        Class<?> clz1 = Class.forName("com.sf._02_反射.javabean.User");
+//        System.out.println(clz1);
+
+        // 第二种 getClass  可以获取当前类class 真是类型
+        getClz(new User());
+        getClz(new Teacher());
+        getClz(new Anmail());
+
+        // 第三种 类名.class
+        System.out.println(User.class);
+        System.out.println(Student.class);
+
+        /**
+         * 如何选择:
+         * 如果现在你只知道类全权定名:  就使用第一种方式
+         * 如果现在你没有全限定名:  你有一个参数你不知道他传递是什么类型   使用第二种
+         * 如果现在你已知一个类了, 你想要获取这个类字节码 , 直接.class
+         */
+    }
+
+
+    public static void getClz(Object obj){
+        System.out.println(obj.getClass());
+    }
+
+
+    /**
+     * 通过字节码信息获取构造器
+     *
+     */
+    @Test
+    public void testConstruct() throws NoSuchMethodException {
+       //1 获取字节码信息
+        Class<Teacher> teacherClass = Teacher.class;
+        //2 通过字节码信息获取构造方法
+        // 获取所有的public 修饰构造器
+        Constructor<?>[] constructors = teacherClass.getConstructors();
+        for (Constructor<?> constructor : constructors) {
+            System.out.println(constructor);
+        }
+
+        // 获取所有的构造方法包括非public
+        for (Constructor<?> declaredConstructor : teacherClass.getDeclaredConstructors()) {
+            System.out.println(declaredConstructor);
+        }
+
+        // 现在想要获取两个参数构造器  Long   String
+        /**
+         * 因为teacherClass.getConstructor 只能够获取public 修饰的构造器
+         */
+//        Constructor<Teacher> constructor = teacherClass.getConstructor(Long.class, String.class);
+//        System.out.println(constructor);
+
+        System.out.println(teacherClass.getDeclaredConstructor(Long.class, String.class));
+
+
+    }
+
+
+    @Test
+    public void testNewInstance() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
+        //1 获取字节码信息
+        Class<Teacher> teacherClass = Teacher.class;
+        //2 通过字节码获取构造器
+//        Constructor<Teacher> constructor = teacherClass.getDeclaredConstructor(Long.class, String.class);
+//        // 把private 修饰构造器设置成可访问的
+//        constructor.setAccessible(true);
+//        //3 通过构造器创建对象
+//        Teacher teacher = constructor.newInstance(1L, "zhangsan");
+//        Constructor<Teacher> constructor = teacherClass.getConstructor();
+//        System.out.println(constructor.newInstance());
+
+        // 调用无参构造器简单方式
+        System.out.println(teacherClass.newInstance());
+    }
+
+    /**
+     * 需求: 定义一方法 public static void drink(Drink drink , name, brand);   全参数构造器私有化
+     * Drink 创建3个子类, Coffee  MilkTea  Coke
+     * 如果传递(coffee() 咖啡,星巴克)     打印对象信息  (MikeTea(),奶茶,蜜雪冰城)
+     */
+
+    public static void drink(Drink drink,String name,String brand) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
+        // 通过反射去创建对象
+//        Class<? extends Drink> clz = drink.getClass();
+//        // 通过字节码获取全参数构造器
+//        Constructor<? extends Drink> constructor = clz.getDeclaredConstructor(String.class, String.class);
+//        // 设置成可访问
+//        constructor.setAccessible(true);
+//        System.out.println(constructor.newInstance(name, brand));
+        System.out.println(drink);
+    }
+
+    @Test
+    public void testDrink() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
+
+        drink(new Coffee(),"拿铁","星巴克");
+
+        drink(new MilkTea(),"奶茶","蜜雪冰城");
+
+        drink(new Coke(),"可乐","非常可乐");
+
+        drink(new Water(),"纯净水","娃哈哈");
+    }
+
+    @Test
+    public void testXmlBean() throws DocumentException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+        //1 解析xml 信息获取到class 的值全限定名
+        InputStream inputStream = Thread.currentThread().
+                getContextClassLoader().
+                getResourceAsStream("spring.xml");
+        SAXReader saxReader = new SAXReader();
+        // 读取流信息
+        Document document = saxReader.read(inputStream);
+        // 先获取根元素 beans
+        Element rootElement = document.getRootElement();
+        // 根据beans 获取他的子元素 bean
+        List<Element> elements = rootElement.elements();
+        // 遍历资源  , 通过bean 获取class 属性
+        for (Element element : elements) {
+            // 获取class 属性的值  , attributeValue : 根据标签属性名字获取属性的值
+            String className = element.attributeValue("class");
+            // 通过反射创建对象
+            System.out.println(Class.forName(className).newInstance());
+        }
+    }
+
+    /**
+     * 获取Teacher 当中方法信息
+     */
+    @Test
+    public void testMethod() throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
+        // 1 获取字节码信息
+        Class<Teacher> teacherClass = Teacher.class;
+        // 2 获取构造器信息
+        // 3 通过构造方法去创建对象
+        Teacher teacher = teacherClass.newInstance();
+        // 4 通过字节码获取方法
+        // 获取teacher 当中所有public 修饰方法
+//        for (Method method : teacherClass.getMethods()) {
+//            System.out.println(method);
+//        }
+//
+//        // 获取teacher 当中所有方法包括private 修饰
+//        for (Method declaredMethod : teacherClass.getDeclaredMethods()) {
+//            System.out.println(declaredMethod);
+//        }
+
+        // 获取单个方法
+        Method method1 = teacherClass.getDeclaredMethod("method1");
+        System.out.println(method1);
+
+        // 调用method1 方法
+        method1.invoke(teacher);
+        // 调用带参数 public 公共方法
+        Method method11 = teacherClass.getMethod("method1", String.class);
+        method11.invoke(teacher,"zhangsan");
+
+        //获取私有方法
+        Method method2 = teacherClass.getDeclaredMethod("method2", String.class);
+        method2.setAccessible(true);
+        method2.invoke(teacher,"xx");
+    }
+
+    /**
+     * 如何获取字段信息
+     * 类  方法Method 字段Field 构造器Construct
+     */
+    @Test
+    public void testField() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {
+        //通过 调用Teacher 全参数构造器创建teacher(1L,zhangsan,300.0))
+        Class<Teacher> teacherClass = Teacher.class;
+        //获取有参数构造器
+//        Constructor<Teacher> declaredConstructor = teacherClass.getDeclaredConstructor(Long.class, String.class, Double.class);
+        //创建对象
+//        Teacher teacher = declaredConstructor.newInstance(1L, "zhangsan", 100.0);
+
+//        System.out.println(teacher);
+        //通过反射去获取类当中字段薪资
+//        Field[] fields = teacherClass.getDeclaredFields();
+//        for (Field field : fields) {
+//            System.out.println(field);
+//        }
+        Teacher teacher = teacherClass.newInstance();
+        // 获取单个字段
+        Field idField = teacherClass.getDeclaredField("id");
+        // 设置访问权限
+        idField.setAccessible(true);
+        idField.set(teacher,2L);
+        System.out.println(idField.get(teacher));
+    }
+}

+ 27 - 0
java-base-project10/day24/src/com/sf/_02_反射/util/PrintJavaBean.java

@@ -0,0 +1,27 @@
+package com.sf._02_反射.util;
+
+public class PrintJavaBean {
+
+    /**
+     * 打印javaBean 信息
+     * 注意打印javaBean 可能是任意类型
+     *
+     * 我希望传入teacher 打印teacher 信息
+     * 如果传入是student 就打印student 信息
+     *
+     * 问题: 现在只打印两个javaBean 信息就需要判断2次
+     * 如果传入的参数类型可能是100种  或者说可能1000种
+     * 意味着这里需要很多很多次的判断的操作非常的不方便
+     * -------------------------------------------
+     * 最终希望能够得到效果
+     * 参数类型不会限制死 , 他是可以传递任意类型
+     * 每次添加新的类型我们也不需要额外加判断的操作
+     *
+     * 就可以使用反射去解决问题
+     *
+     */
+    public static void printJavaBean(Object obj){
+        // 判断他的类型 如果时候学生
+
+    }
+}

+ 17 - 0
java-base-project10/day25/day25.iml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" name="dom4j-2.1.1 (3)" level="project" />
+    <orderEntry type="library" name="createjavabean" level="project" />
+    <orderEntry type="library" name="lombok-1.18.22" level="project" />
+    <orderEntry type="library" name="junit-4.13" level="project" />
+    <orderEntry type="library" name="lombok-1.18.30" level="project" />
+  </component>
+</module>

BIN
java-base-project10/day25/lib/createjavabean.jar


BIN
java-base-project10/day25/lib/dom4j-2.1.1.jar


BIN
java-base-project10/day25/lib/hamcrest-core-1.3.jar


BIN
java-base-project10/day25/lib/junit-4.13.jar


BIN
java-base-project10/day25/lib/lombok-1.18.30.jar


+ 4 - 0
java-base-project10/day25/resources/spring.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<beans>
+    <bean class="com.sf._01_class.javabean.Teacher"></bean>
+</beans>

+ 57 - 0
java-base-project10/day25/src/com/sf/_01_class/javabean/Student.java

@@ -0,0 +1,57 @@
+package com.sf._01_class.javabean;
+
+public class Student {
+    private String name;
+    private Integer age;
+
+    public void getStudentByName(){
+        System.out.println("xxx");
+    }
+
+    private void study(String course){
+        System.out.println(this.name+"正在学习"+course  );
+    }
+    private Student() {
+    }
+
+    private Student(String name, Integer age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public Integer getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    public String toString() {
+        return "Student{name = " + name + ", age = " + age + "}";
+    }
+}

+ 50 - 0
java-base-project10/day25/src/com/sf/_01_class/javabean/Teacher.java

@@ -0,0 +1,50 @@
+package com.sf._01_class.javabean;
+
+public class Teacher {
+    private String name;
+    private Integer age;
+
+    public Teacher() {
+    }
+
+    public Teacher(String name, Integer age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public Integer getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    public String toString() {
+        return "Teacher{name = " + name + ", age = " + age + "}";
+    }
+}

+ 62 - 0
java-base-project10/day25/src/com/sf/_01_class/test/ClassTest.java

@@ -0,0 +1,62 @@
+package com.sf._01_class.test;
+
+import com.sf._01_class.javabean.Student;
+import com.sf.util.CreateBean;
+import org.junit.Test;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+public class ClassTest {
+
+
+    @Test
+    public void test(){
+        CreateBean.createBean();
+    }
+
+
+    @Test
+    public void test1() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {
+        // 1 获取student 字节码信息
+        Class<Student> studentClass = Student.class;
+        // 2 通过反射获取调用私有构造器创建student 对象
+        Constructor<Student> declaredConstructor = studentClass.getDeclaredConstructor(String.class, Integer.class);
+        // 创建对象
+        declaredConstructor.setAccessible(true);
+        Student student = declaredConstructor.newInstance("zhangsan", 10);
+        System.out.println(student);
+
+        //3 通过反射获取私有属性name 字段并且修改他的值
+        Field name = studentClass.getDeclaredField("name");
+        name.setAccessible(true);
+        name.set(student,"lisi");
+        System.out.println(name.get(student));
+
+        //4 反射获取私有方法study 并调用
+        Method method = studentClass.getDeclaredMethod("study", String.class);
+        method.setAccessible(true);
+        method.invoke(student,"java");
+
+        //5 通过反射调用所有公共的getter 方法  getName  getAge();
+        // 5.1 先获取所有方法
+        /**
+         * method方法:
+         * 一类studentClass: 方法
+         * 一类Object: 方法
+         *
+         * 现在调用get 方法比较麻烦
+         * 这样去进行调用存在着弊端
+         * 我现在想调用就仅仅有getName()  getAge()
+         */
+        for (Method studentClassMethod : studentClass.getMethods()) {
+            if(studentClassMethod.getDeclaringClass() == studentClass){
+                if(studentClassMethod.getName().startsWith("get")){
+                    System.out.println(studentClassMethod.invoke(student));
+                }
+            }
+        }
+    }
+}

+ 86 - 0
java-base-project10/day25/src/com/sf/_02_introspection/javabean/Dog.java

@@ -0,0 +1,86 @@
+package com.sf._02_introspection.javabean;
+
+/**
+ * lombok 主要帮我们省略get 和set  toString  全参数构造器 无参数构造器
+ * 他内部提供了一些注解,可以帮我们去生成这些get 和set 代码
+ * @Getter  :  提供get 方法
+ * @Setter  :  提供set 方法
+ * @ToString:  提供  toString 方法
+ * @AllArgsConstructor: 提供全参数构造器
+ * @NoArgsConstructor: 提供无参数构造器
+ *
+ */
+//@Getter
+//@Setter
+//@ToString
+//@AllArgsConstructor
+//@NoArgsConstructor
+// 贴了Data 注解所有get set 都有了 但是没有全参数构造器
+
+public class Dog {
+    private String name;
+    private Integer age;
+    private String color;
+
+
+    public Dog() {
+    }
+
+    public Dog(String name, Integer age, String color) {
+        this.name = name;
+        this.age = age;
+        this.color = color;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public Integer getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return color
+     */
+    public String getColor() {
+        return color;
+    }
+
+    /**
+     * 设置
+     * @param color
+     */
+    public void setColor(String color) {
+        this.color = color;
+    }
+
+    public String toString() {
+        return "Dog{name = " + name + ", age = " + age + ", color = " + color + "}";
+    }
+}

+ 68 - 0
java-base-project10/day25/src/com/sf/_02_introspection/javabean/Student.java

@@ -0,0 +1,68 @@
+package com.sf._02_introspection.javabean;
+
+public class Student {
+    private String name;
+    private Integer age;
+    private Double score;
+
+    public Student() {
+    }
+
+    public Student(String name, Integer age, Double score) {
+        this.name = name;
+        this.age = age;
+        this.score = score;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public Integer getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return score
+     */
+    public Double getScore() {
+        return score;
+    }
+
+    /**
+     * 设置
+     * @param score
+     */
+    public void setScore(Double score) {
+        this.score = score;
+    }
+
+    public String toString() {
+        return "Student{name = " + name + ", age = " + age + ", score = " + score + "}";
+    }
+}

+ 160 - 0
java-base-project10/day25/src/com/sf/_02_introspection/test/IntrospectTest.java

@@ -0,0 +1,160 @@
+package com.sf._02_introspection.test;
+
+import com.sf._02_introspection.javabean.Dog;
+import com.sf._02_introspection.javabean.Student;
+import com.sf._02_introspection.util.MapAndJavaBeanConvertUtil;
+import org.junit.Test;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Scanner;
+
+
+public class IntrospectTest {
+    /**
+     * Student(name,age)
+     * 在控制台当中录入 类全限定名 和要操作属性名
+     * 通过反射去给这个属性设置值 调用set方法 , 通过get方法获取值
+     * 比如: com.sf.Teacher   name       setName()   getName()
+     */
+    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IntrospectionException {
+        Scanner scanner = new Scanner(System.in);
+        System.out.println("请录入全限定名");
+        String className = scanner.next();
+        System.out.println("请录入属性名名字");
+        // name    age   email
+        String propertName = scanner.next();
+        System.out.println("请录入属性名value");
+        // name    age   email
+        String value = scanner.next();
+
+
+        // 通过反射获取字节码
+        Class<?> clz = Class.forName(className);
+
+        // 创建对象
+//        Constructor<?> constructor = clz.getConstructor(String.class, Integer.class);
+//        Object obj = constructor.newInstance("zhangsan", 10);
+        Object obj = clz.newInstance();
+
+        // 通过字节码获取方法
+        // getName setName  getAge setAge
+        // setName
+        // propertName.substring(0,1).toUpperCase()  n
+//        Method method = clz.getMethod("set" + propertName.substring(0, 1).toUpperCase() +
+//                propertName.substring(1), String.class);
+//        System.out.println(method);
+        // 调用方法
+//        Method method = clz.getMethod("get" + propertName.substring(0, 1).toUpperCase() +
+//                propertName.substring(1));
+        PropertyDescriptor propertyDescriptor = new PropertyDescriptor(propertName,clz);
+        // 获取属性的类型
+        Class<?> propertyType = propertyDescriptor.getPropertyType();
+
+        Method writeMethod = propertyDescriptor.getWriteMethod();
+        System.out.println(writeMethod);
+        writeMethod.invoke(obj,value);
+        System.out.println(propertyDescriptor.getReadMethod().invoke(obj));
+    }
+
+
+    /**
+     * 内省api :
+     * 内省api 主要就是解决咱们在反射当中去调用get 和set 方法比较麻烦
+     *
+     */
+    @Test
+    public void test2() throws IntrospectionException, InvocationTargetException, IllegalAccessException, InstantiationException {
+        /**
+         * 内省中 PropertyDescriptor  : 属性描述其
+         * 他里面有操作属性get 和set 的方法
+         *
+         * javaBean :  getName  setName   getAge  setAge
+         */
+        Class<Student> studentClass = Student.class;
+        PropertyDescriptor propertyDescriptor = new PropertyDescriptor("name",studentClass);
+        System.out.println(propertyDescriptor.getName());
+        /**
+         * getWriteMethod: 这个就是 set 方法 写的操作
+         */
+        Method setMethod = propertyDescriptor.getWriteMethod();
+        Student student = studentClass.newInstance();
+        /**
+         * 调用方法invoke
+         */
+        setMethod.invoke(student,"zhangsan");
+
+        /**
+         * 通过属性描述其去调用get 方法
+         */
+        Method getMethod = propertyDescriptor.getReadMethod();
+        System.out.println(getMethod.invoke(student));
+
+    }
+
+    /**
+     * 获取当前这个类当中
+     * 所有属性的get 方法
+     * 所有属性set 方法
+     */
+    @Test
+    public void test3() throws IntrospectionException {
+        //1 获取字节码信息
+        Class<Student> studentClass = Student.class;
+        //2 获取javaBean 信息 getBeanInfo
+        /**
+         * beanInfo当中就有我们这个类所有的属性信息
+         */
+        BeanInfo beanInfo = Introspector.getBeanInfo(studentClass, Object.class);
+        /**
+         * beanInfo 有一个方法  getPropertyDescriptors();
+         */
+        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+        for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
+            System.out.println("属性名字:"+ propertyDescriptor.getName());
+            System.out.println("set方法:"+ propertyDescriptor.getWriteMethod());
+            System.out.println("get方法:"+ propertyDescriptor.getReadMethod());
+        }
+    }
+
+
+    /**
+     * 定义一个类MapAndJavaBeanConvertUtil
+     * 对象-map
+     * 这个方法对象可能是任意对象
+     * 比如
+     * Teacher(id=1,name=zhangsan,salary=30.0)   map(id=1,name=zhangsan,salary=30.0)
+     * Student(id=1,name=lisi,score=90)      map(id=1,name=zhangsan,salary=30.0)
+     */
+    @Test
+    public void test4() throws IntrospectionException, InvocationTargetException, InstantiationException, IllegalAccessException {
+        Dog dog = new Dog("旺财", 4, "黑色");
+//        System.out.println(MapAndJavaBeanConvertUtil.mapToObj(dog));
+
+        Student student = new Student("zhangsan",10,90.0);
+//        System.out.println(MapAndJavaBeanConvertUtil.mapToObj(student));
+    }
+
+    @Test
+    public void test5() throws IntrospectionException, InvocationTargetException, InstantiationException, IllegalAccessException {
+        Map<String,Object> map = new HashMap<>();
+        map.put("name","zhangsan");
+        map.put("age",10);
+        map.put("color","黑色");
+        System.out.println(MapAndJavaBeanConvertUtil.mapToObj(map, Dog.class));
+
+        Map<String,Object> map1 = new HashMap<>();
+        map1.put("name","zhangsan");
+        map1.put("age",10);
+        map1.put("score",90.0);
+        System.out.println(MapAndJavaBeanConvertUtil.mapToObj(map1, Student.class));
+
+    }
+
+}

+ 75 - 0
java-base-project10/day25/src/com/sf/_02_introspection/util/MapAndJavaBeanConvertUtil.java

@@ -0,0 +1,75 @@
+package com.sf._02_introspection.util;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+public class MapAndJavaBeanConvertUtil {
+    /**
+     * 对象-> map
+     * obj 可能是student   Teacher   Dog  cat
+     *
+     * 1 拿到对象中所有属性值  放到map中
+     * 2 思考如何获取对象中所有属性值  和属性名
+     * 3 调用对象get方法
+     * 4 通过反射去调用get方法就很不方便要拼接
+     * 5 通过内省获取对象当中所有属性get 方法
+     * 6 获取属性名和属性值以后就 往map 当中存储就可以了
+     *
+     * 把当中属性内容   设置到方法当中
+     */
+    public static Map<String,Object> objToMap(Object obj) throws IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException {
+        // obj(name=xx,age=xx,color=xxx)
+        Map<String,Object> map = new HashMap<>();
+        // 1 获取字节码信息
+        // 传入参数是什么 字节码就是谁
+        Class<?> clz = obj.getClass();
+        // 2 内省当中有一个方法可以获取到java Bean 所有的get 和set 方法
+        BeanInfo beanInfo = Introspector.getBeanInfo(clz,Object.class);
+        // 3 获取所有属性描述其
+        for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) {
+            // map .put(key(属性名),value(属性值))
+            // key: 属性getName()   value: getReadMethod();
+            Method method = propertyDescriptor.getReadMethod();
+            Object value = method.invoke(obj);
+            // 把属性放到map 当中
+            map.put(propertyDescriptor.getName(),value);
+        }
+        return map;
+
+    }
+
+
+    /**
+     * map -> 对象
+     * map: name=xx , age=xx,score=xxx    Student
+     * map: name=xx, age=xx,color=xx     Dog
+     */
+    public static Object mapToObj(Map<String,Object> map,Class clz) throws InstantiationException, IllegalAccessException, IntrospectionException, InvocationTargetException {
+        /**
+         * 核心思路把map 当中属性设置 对象中
+         * map(key(属性名字), value(属性的值))
+         */
+        // 1 通过反射去创建一个对象   Student
+        Object obj = clz.newInstance();
+        // 2 获取属性描述其集合    student.setName  student.setAge  student.setScore
+        BeanInfo beanInfo = Introspector.getBeanInfo(clz, Object.class);
+        // 3 遍历属性描述其集合
+        for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) {
+            // 4 从map 当中取属性的值 , 然后设置到对象中
+            Object value = map.get(propertyDescriptor.getName());
+            Method writeMethod = propertyDescriptor.getWriteMethod();
+            writeMethod.invoke(obj,value);
+        }
+        return obj;
+
+
+
+
+    }
+}

+ 10 - 0
java-base-project10/day25/src/com/sf/_03_lombda/Student.java

@@ -0,0 +1,10 @@
+package com.sf._03_lombda;
+
+import lombok.Data;
+
+@Data
+public class Student {
+    private String name;
+    private int age;
+
+}

+ 11 - 0
java-base-project10/day25/src/com/sf/_03_lombda/Test.java

@@ -0,0 +1,11 @@
+package com.sf._03_lombda;
+
+public class Test {
+
+    @org.junit.Test
+    public void test(){
+        Student student = new Student();
+        student.setName("zhangsan");
+        System.out.println(student.getName());
+    }
+}

+ 8 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo1/Dog.java

@@ -0,0 +1,8 @@
+package com.sf._03_lombda.demo1;
+
+public class Dog  implements ISwim{
+    @Override
+    public void swim() {
+        System.out.println("狗刨");
+    }
+}

+ 8 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo1/Fish.java

@@ -0,0 +1,8 @@
+package com.sf._03_lombda.demo1;
+
+public class Fish implements ISwim{
+    @Override
+    public void swim() {
+        System.out.println("鱼游泳");
+    }
+}

+ 8 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo1/ISwim.java

@@ -0,0 +1,8 @@
+package com.sf._03_lombda.demo1;
+
+public interface ISwim {
+    /**
+     * 游泳
+     */
+    void swim();
+}

+ 48 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo1/LambdaTest.java

@@ -0,0 +1,48 @@
+package com.sf._03_lombda.demo1;
+
+import org.junit.Test;
+
+public class LambdaTest {
+    /**
+     * 最传统方式
+     */
+    @Test
+    public void test(){
+        ISwim swim = new Dog();
+        swim.swim();
+
+        ISwim swim1 = new Fish();
+        swim1.swim();
+    }
+
+    /**
+     * 使用匿名内部类放肆
+     */
+    @Test
+    public void test1(){
+        new ISwim() {
+            @Override
+            public void swim() {
+                System.out.println("狗刨");
+            }
+        }.swim();
+
+        new ISwim() {
+            @Override
+            public void swim() {
+                System.out.println("鱼游泳");
+            }
+        }.swim();
+    }
+
+    /**
+     * 使用lambda 表达式简化
+     */
+    @Test
+    public void test2(){
+        ISwim fishSwim = () -> System.out.println("鱼游泳");
+        fishSwim.swim();
+    }
+
+
+}

+ 15 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo2/Data.java

@@ -0,0 +1,15 @@
+package com.sf._03_lombda.demo2;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Data {
+    public static List<Product> products = new ArrayList<>();
+    static {
+        products.add(new Product(1L, "苹果手机", 8888.88,"手机"));
+        products.add(new Product(2L, "华为手机", 6666.66,"手机"));
+        products.add(new Product(3L, "联想笔记本",7777.77,"电脑"));
+        products.add(new Product(4L, "机械键盘", 999.99,"键盘"));
+        products.add(new Product(5L, "雷蛇鼠标", 222.22,"鼠标"));
+    }
+}

+ 11 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo2/IConditionAble.java

@@ -0,0 +1,11 @@
+package com.sf._03_lombda.demo2;
+
+
+public interface IConditionAble {
+    /**
+     * 判断条件 如果成立返回true 如果不成立就返回false
+     * @return
+     */
+    boolean isCondition(Product product);
+;
+}

+ 5 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo2/IFunAble.java

@@ -0,0 +1,5 @@
+package com.sf._03_lombda.demo2;
+
+public interface IFunAble {
+    void method(String name);
+}

+ 91 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo2/MyTest.java

@@ -0,0 +1,91 @@
+package com.sf._03_lombda.demo2;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class MyTest {
+    /**
+     * 需求1: 筛选出所有名称包含手机的商品
+     * 需求2: 筛选出所有价格大于1000的商品
+     */
+    public static void main(String[] args) {
+//        for (Product product : findProductsByName(Data.products)) {
+//            System.out.println(product);
+//        }
+//        for (Product product : findProductsByPrice(Data.products)) {
+//            System.out.println(product);
+//        }
+        List<Product> list = findProductsByCondition(Data.products, product -> {
+            if(product.getName().contains("手机")){
+                return true;
+            }else{
+                return false;
+            }
+        });
+        System.out.println(list);
+
+//        List<Product> list1 = findProductsByCondition(Data.products, new IConditionAble() {
+//            // 查询价格大于1000的
+//            @Override
+//            public boolean isCondition(Product product) {
+//                return product.getPrice() > 1000;
+//            }
+//        });
+
+
+//        List<Product> list1 = findProductsByCondition(Data.products, p -> {
+//            return p.getPrice()>1000;
+//        });
+
+        List<Product> list1 = findProductsByCondition(Data.products, p -> p.getPrice()>1000);
+        System.out.println(list1);
+
+    }
+
+
+    /**
+     * 需求1: 筛选出所有名称包含手机的商品
+     */
+//    public static List<Product> findProductsByName(List<Product> products){
+//        List<Product> newList = new ArrayList<>();
+//        /**
+//         * 遍历集合
+//         */
+//        for (Product product : products) {
+//            if(product.getName().contains("手机")){
+//                newList.add(product);
+//            }
+//        }
+//        return newList;
+//    }
+//    /**
+//      需求2: 筛选出所有价格大于1000的商品
+//     */
+//    public static List<Product> findProductsByPrice(List<Product> products){
+//        List<Product> newList  = new ArrayList<>();
+//        // 遍历集合 判断是否大于1000
+//        for (Product product : products) {
+//            if(product.getPrice() > 1000){
+//                newList.add(product);
+//            }
+//        }
+//        return newList;
+//    }
+
+    /**
+     * 问题: 我们按照某一个条件查询就需要单独的去创建一个方法进行查询
+     *
+     * 我希望效果就值提供一个方法, 不论你按照什么条件去查询 我都是写一个方法就可以了
+     */
+    public static List<Product> findProductsByCondition(List<Product> products,IConditionAble conditionAble){
+        List<Product> newList = new ArrayList<>();
+        for (Product product : products) {
+            // 判断条件是否成立
+            if(conditionAble.isCondition(product)){
+                newList.add(product);
+            }
+        }
+        return newList;
+    }
+
+}

+ 53 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo2/MyTest1.java

@@ -0,0 +1,53 @@
+package com.sf._03_lombda.demo2;
+
+import org.junit.Test;
+
+public class MyTest1 {
+
+    @Test
+    public void test1(){
+//        m(new IFunAble() {
+//            @Override
+//            public void method() {
+//                System.out.println("111");
+//            }
+//        });
+
+        // 使用lambda 表达式
+        // 函数式接口 接口当中就只有一个方法
+        // lambda 表达式如果只有一个参数() 可以省略
+        // 如果我们方法一个参数都没有() 不可以省略 多个参数()也不能省略
+        // 如果你的代码块代码只有一行{} 也可以
+        // 如果有多行代码必须要写{}
+        m((a)-> {
+            System.out.println(a);
+        });
+    }
+
+
+    public void m(IFunAble able){
+        able.method("123");
+    }
+
+
+    /*
+        1 编写一个接口(IShowable),在该接口中存在一个抽象方法(show),该方法是无参数无返回值
+        2 在测试类(ShowableDemo)中存在一个方法useShowable,方法的的参数是IShowable类型的,
+         在方法内部调用了IShowable的show方法
+    */
+
+    /*
+    1 首先存在一个接口(StringHandler),在该接口中存在一个抽象方法(print),该方法是有参数无返回值
+    2 在测试类PrintableDemo中存在一个方法usePrintable,方法的的参数是IPrintable类型的,
+    在方法内部调用了IPrintable的print方法,打印传入的参数
+     */
+
+    /**
+     * 编写一个接口 IRandomable,接口中存在一个抽象方法getRandom,
+     * 无参数有返回值,传入对应的lambda表达式**
+     */
+
+    /**
+     * 编写一个接口 ICalcable,接口中存在一个抽象方法calc,有参数有返回值,传入对应的lambda表达式
+     */
+}

+ 91 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo2/Product.java

@@ -0,0 +1,91 @@
+package com.sf._03_lombda.demo2;
+
+//@AllArgsConstructor
+//@NoArgsConstructor
+//@Getter
+//@Setter
+//@ToString
+public class Product {
+    private Long    id;         // 序号
+    private String  name;       // 商品名称
+    private Double 	price;      // 价格
+    private String  type;       // 类型
+
+    public Product() {
+    }
+
+    public Product(Long id, String name, Double price, String type) {
+        this.id = id;
+        this.name = name;
+        this.price = price;
+        this.type = type;
+    }
+
+    /**
+     * 获取
+     * @return id
+     */
+    public Long getId() {
+        return id;
+    }
+
+    /**
+     * 设置
+     * @param id
+     */
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return price
+     */
+    public Double getPrice() {
+        return price;
+    }
+
+    /**
+     * 设置
+     * @param price
+     */
+    public void setPrice(Double price) {
+        this.price = price;
+    }
+
+    /**
+     * 获取
+     * @return type
+     */
+    public String getType() {
+        return type;
+    }
+
+    /**
+     * 设置
+     * @param type
+     */
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String toString() {
+        return "Product{id = " + id + ", name = " + name + ", price = " + price + ", type = " + type + "}";
+    }
+}

+ 6 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo3/ICallAble.java

@@ -0,0 +1,6 @@
+package com.sf._03_lombda.demo3;
+
+public interface ICallAble {
+    int calc(int a,int b);
+
+}

+ 26 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo3/ICallAbleImpl.java

@@ -0,0 +1,26 @@
+package com.sf._03_lombda.demo3;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class ICallAbleImpl implements ICallAble {
+//    @Override
+    public String getLen(String str) {
+        return null;
+    }
+
+    @Test
+    public void test1(){
+        List<Integer> list = Arrays.asList(1, 2, 1, 3, -1, 2, 4);
+        System.out.println(list.stream().collect(Collectors.summarizingInt(e -> 2*e)).getMax());
+    }
+
+
+    @Override
+    public int calc(int a, int b) {
+        return 0;
+    }
+}

+ 6 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo3/IRandomable.java

@@ -0,0 +1,6 @@
+package com.sf._03_lombda.demo3;
+
+public interface IRandomable {
+
+    int getRandom();
+}

+ 5 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo3/IShowable.java

@@ -0,0 +1,5 @@
+package com.sf._03_lombda.demo3;
+
+public interface IShowable {
+    void show();
+}

+ 49 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo3/MyTest.java

@@ -0,0 +1,49 @@
+package com.sf._03_lombda.demo3;
+
+import org.junit.Test;
+
+import java.util.Random;
+
+public class MyTest {
+    @Test
+    public void test(){
+        userShowable(()-> System.out.println("展示信息"));
+    }
+
+    public void userShowable(IShowable showable){
+        showable.show();
+    }
+
+    @Test
+    public void test2(){
+        usePrintable(s-> System.out.println(s),"123");
+    }
+
+    public void usePrintable(StringHandler stringHandler,String str){
+        stringHandler.print(str);
+    }
+
+    @Test
+    public void test3(){
+        useRandomAble(()->{
+            return new Random().nextInt(10);
+        });
+    }
+
+    public void useRandomAble(IRandomable randomable ){
+        System.out.println(randomable.getRandom());
+    }
+    @Test
+//    public void test4(){
+//        useCalacAble((a,b)->{
+//            return a+b;
+//        },1,3);
+//    }
+
+    public void test4(){
+
+    }
+    public void useCalacAble(ICallAble callAble,int a , int b){
+        callAble.calc(a,b);
+    }
+}

+ 5 - 0
java-base-project10/day25/src/com/sf/_03_lombda/demo3/StringHandler.java

@@ -0,0 +1,5 @@
+package com.sf._03_lombda.demo3;
+
+public interface StringHandler {
+    void print(String str);
+}

+ 12 - 0
java-base-project10/day26/day26.iml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" name="lib" level="project" />
+  </component>
+</module>

BIN
java-base-project10/day26/lib/hamcrest-core-1.3.jar


BIN
java-base-project10/day26/lib/junit-4.13.jar


BIN
java-base-project10/day26/lib/lombok-1.18.30.jar


+ 13 - 0
java-base-project10/day26/src/com/sf/_01_lombok/LombokTest.java

@@ -0,0 +1,13 @@
+package com.sf._01_lombok;
+
+import org.junit.Test;
+
+public class LombokTest {
+    @Test
+    public void test(){
+        Student student = new Student();
+        student.setName("zhangsan");
+        student.setAge(10);
+        System.out.println(student.getName());
+    }
+}

+ 14 - 0
java-base-project10/day26/src/com/sf/_01_lombok/Student.java

@@ -0,0 +1,14 @@
+package com.sf._01_lombok;
+
+import lombok.*;
+
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+@ToString
+public class Student {
+    private Long id;
+    private String name;
+    private Integer age;
+}

+ 15 - 0
java-base-project10/day26/src/com/sf/_02_lombda/Data.java

@@ -0,0 +1,15 @@
+package com.sf._02_lombda;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Data {
+    public static List<Product> products = new ArrayList<>();
+    static {
+        products.add(new Product(1L, "苹果手机", 8888.88,"手机"));
+        products.add(new Product(2L, "华为手机", 6666.66,"手机"));
+        products.add(new Product(3L, "联想笔记本",7777.77,"电脑"));
+        products.add(new Product(4L, "机械键盘", 999.99,"键盘"));
+        products.add(new Product(5L, "雷蛇鼠标", 222.22,"鼠标"));
+    }
+}

+ 10 - 0
java-base-project10/day26/src/com/sf/_02_lombda/IConditionAble.java

@@ -0,0 +1,10 @@
+package com.sf._02_lombda;
+
+public interface IConditionAble {
+    /**
+     * 判断条件是否成立
+     * @param product
+     * @return
+     */
+    boolean isCondition(Product product);
+}

+ 144 - 0
java-base-project10/day26/src/com/sf/_02_lombda/LambdaTest.java

@@ -0,0 +1,144 @@
+package com.sf._02_lombda;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+public class LambdaTest {
+
+    /**
+     * 需求1: 筛选出所有名称包含手机的商品
+     *
+     * 需求2: 筛选出所有价格大于1000的商品
+     */
+    @Test
+    public void test(){
+//        for (Product product : findProductsByName(Data.products)) {
+//            System.out.println(product);
+//        }
+//        System.out.println("-------------------");
+//        for (Product product : findProductsByPrice(Data.products)) {
+//            System.out.println(product);
+//        }
+//        List<Product> productsByCondtion = findProductsByCondtion(Data.products, new IConditionAble() {
+//            @Override
+//            public boolean isCondition(Product product) {
+//                return product.getPrice() > 1000;
+//            }
+//        });
+//        for (Product product : productsByCondtion) {
+//            System.out.println(product);
+//        }
+        // lambda 表达式去完成
+        List<Product> productsByCondtion = findProductsByCondtion(Data.products, product -> product.getPrice()>1000);
+        for (Product product : productsByCondtion) {
+            System.out.println(product);
+        }
+    }
+
+    public List<Product> findProductsByCondtion(List<Product> products,IConditionAble conditionAble){
+        List<Product> newList = new ArrayList<>();
+        for (Product product : products) {
+            if(conditionAble.isCondition(product)){
+                newList.add(product);
+            }
+        }
+        return newList;
+    }
+
+    /**
+     * 需求1: 筛选出所有名称包含手机的商品
+     */
+    public List<Product> findProductsByName(List<Product> products){
+        List<Product> newList = new ArrayList<>();
+        for (Product product : products) {
+            if(product.getName().contains("手机")){
+                newList.add(product);
+            }
+        }
+        return newList;
+    }
+    /**
+     * 需求2: 筛选出所有价格大于1000的商品
+     */
+    public List<Product> findProductsByPrice(List<Product> products){
+        List<Product> newList = new ArrayList<>();
+        for (Product product : products) {
+            if(product.getPrice()>1000){
+                newList.add(product);
+            }
+        }
+        return newList;
+    }
+
+    /**
+     * 需求1: 编写shop方法输出消费多少元 有两个参数,第一个参数金额int , 第二个参数是一个函数式接口(有参数无返回值)
+     * 分析:输入1000,打印消费为了1000元,
+     * 可以使用自己创建函数式接口 也可以用jdk提供的函数式接口
+     */
+    @Test
+    public  void test1(){
+        shop(2000,m -> System.out.println(m));
+    }
+
+    public void shop(int money, Consumer<Integer> consumer){
+        consumer.accept(money);
+    }
+
+    /**
+     * 需求2:编写 getCode 方法返回指定位数的随机验证码字符串** (长度,函数式接口(有参数有返回值))
+     * 要格式 abc2     UUID
+     */
+    @Test
+    public void test2(){
+        getCode(5,len->{
+            return UUID.randomUUID().toString().substring(0,len);
+        });
+    }
+
+    public void getCode(int codeLen, Function<Integer,String> function){
+        String str = function.apply(codeLen);
+        System.out.println(str);
+    }
+
+    @Test
+    public void test3(){
+        getStringRealLeng("zhangsan",s-> s.length());
+    }
+    /**
+     * 需求3:编写 getStringRealLength 方法返回字符串真实长度
+     * getStringReaLength(String str,函数式接口(有参数, 有返回值));
+     */
+    public void getStringRealLeng(String str,Function<String,Integer> function){
+        System.out.println(function.apply(str));
+    }
+
+    @Test
+    public void test4(){
+        ArrayList<String> strs = new ArrayList<>(Arrays.asList("fanjialong","zhangsan","lisi","xxx","xxxxxx"));
+        List<String> newList = getString(strs, s -> s.length() > 5);
+        for (String s : newList) {
+            System.out.println(s);
+        }
+    }
+    /*
+      List = {"fanjialong","zhangsan","lisi","wangwu","xl"}
+     * 需求4:编写 getString 方法返回长度大于5的字符串的集合
+     * getString(集合,函数接口(有参数, 返回值是boolean))
+     */
+    public List<String> getString(List<String> list, Predicate<String> predicate){
+        List<String> newList = new ArrayList<>();
+        for (String s : list) {
+            if(predicate.test(s)){
+                newList.add(s);
+            }
+        }
+        return newList;
+    }
+}

+ 16 - 0
java-base-project10/day26/src/com/sf/_02_lombda/Product.java

@@ -0,0 +1,16 @@
+package com.sf._02_lombda;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class Product {
+    private Long    id;         // 序号
+    private String  name;       // 商品名称
+    private Double 	price;      // 价格
+    private String  type;       // 类型
+    //...getter/setter
+}

+ 14 - 0
java-base-project10/day26/src/com/sf/_03_jdk8_interface/IFunAble.java

@@ -0,0 +1,14 @@
+package com.sf._03_jdk8_interface;
+
+public interface IFunAble {
+    void eat();
+
+    void sleep();
+
+    default void runCar(){};
+
+
+//    static void method1(){
+//
+//    }
+}

+ 18 - 0
java-base-project10/day26/src/com/sf/_03_jdk8_interface/IFunAbleImpl.java

@@ -0,0 +1,18 @@
+package com.sf._03_jdk8_interface;
+
+public class IFunAbleImpl implements IFunAble {
+    @Override
+    public void eat() {
+
+    }
+
+    @Override
+    public void sleep() {
+
+    }
+
+    @Override
+    public void runCar() {
+
+    }
+}

+ 344 - 0
java-base-project10/day26/src/com/sf/_04_stream/StreamTest.java

@@ -0,0 +1,344 @@
+package com.sf._04_stream;
+
+import org.junit.Test;
+
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class StreamTest {
+
+    /**
+     * 如何创建stream 刘
+     * 集合.stream();
+     * Arrays.stream(数组);
+     * Stream.of(元素,元素);
+     */
+    @Test
+    public void test(){
+        // 1 通过集合获取stream 刘
+        List<Integer> list = new ArrayList<>(Arrays.asList(1,3,4,5,6,7,8));
+        Stream<Integer> stream = list.stream();
+        System.out.println(stream);
+        // 2 数组获取steram流
+        Integer[] arr = {2,3,4,5,6,7,8};
+        Stream<Integer> stream1 = Arrays.stream(arr);
+        System.out.println(stream1);
+        // 3 通过Stream.of 获取流信息
+        System.out.println(Stream.of(1, 2, 3, 4, 5, 67));
+    }
+
+
+    /**
+     * 中间操作
+     * filter(函数式接口 有参数有返回 boolean)
+     * 过滤大于3的元素
+     */
+    @Test
+    public void test2(){
+        List<Integer> list = new ArrayList<>(Arrays.asList(1,2,3,4,5));
+//        for (Integer integer : list) {
+//            if(integer>3){
+//                System.out.println(integer);
+//            }
+//        }
+        // 获取stream 刘
+        // list.stream()  开始
+        // filter:  中间处理
+        // forEach: 结束操作
+        list.stream().filter(e-> e>3).forEach(e-> System.out.println(e));
+    }
+
+
+    /**
+     * 现在有一个集合 zhangsan  zhangsi  lisi   wangwu  zhaoliu
+     * 找到行zhang的元素 并且打印
+     */
+    @Test
+    public void test3(){
+        List<String> list = new ArrayList<>(Arrays.asList("zhangsan","lisi","zhangsi","wangwu","zhaoliu"));
+        list.stream().filter(e-> e.contains("zhang")).forEach(e-> System.out.println(e));
+    }
+
+    /**
+     * distinct: 去除重复数据
+     */
+    @Test
+    public void test4(){
+        ArrayList<Integer> arrayList = new ArrayList<>(Arrays.asList(1,1,2,3,4,5,5,6,7));
+        // 去除arrayList 当中重复数据
+        // 去除大于4 的重复的数据
+        arrayList.stream().
+                filter(e-> e > 3).
+                distinct().
+                forEach(e-> System.out.println(e));
+    }
+
+    /**
+     * limit : 保留多少个数据
+     * skip: 跳过多少条数据
+     *
+     *
+     */
+    @Test
+    public void test5(){
+        ArrayList<Integer> arrayList = new ArrayList<>(Arrays.asList(1,1,2,3,4,5,5,6,7));
+        // 保留前4 个数据
+//        arrayList.stream().limit(4).forEach(e-> System.out.println(e));
+        arrayList.stream().
+                skip(3).   // 跳过3条数据
+                limit(3). // 保留3个数据
+                forEach(e-> System.out.println(e));
+
+    }
+
+
+    /**
+     * 1,1,9,3,4,5,5,6,9,13,15,12,12,18,21
+     * 去重
+     * 找出3的倍数的数字
+     * 每页显示3条数据, 展示第2页的信息
+     * 3 6 9  12  15  18  21
+     */
+    @Test
+    public void test6(){
+        ArrayList<Integer> arrayList = new ArrayList<>(Arrays.asList(1,1,9,3,4,5,5,6,9,13,15,12,12,18,21));
+        arrayList.stream().
+                distinct().
+                filter(e-> e%3 == 0).
+                skip(3).
+                limit(3).
+                forEach(e-> System.out.println(e));
+    }
+
+
+    /**
+     * map: 主要作用是对于集合当中元素进行额外的处理
+     * 需要 集合元素 1  2  3  4   我们希望集合当中元素进行平方操作
+     */
+    @Test
+    public void test7(){
+        ArrayList<Integer> arrayList = new ArrayList<>(Arrays.asList(1,2,3,4));
+        arrayList.stream().
+                map(e-> e*e).  // 对于之前元素进行平方处理
+                forEach(e-> System.out.println(e));
+    }
+
+    /**
+     * 集合当中元素 , i  love  you  china
+     * I LOVE YOU CHAINA
+     */
+    @Test
+    public void test8(){
+        ArrayList<String> arrayList = new ArrayList<>(Arrays.asList("i","love","you","china"));
+        arrayList.stream().
+                map(e-> e.toUpperCase()).  // 对于之前元素进行平方处理
+                forEach(e-> System.out.println(e));
+    }
+
+    /**
+     * 定义一个Student id  name   age  score
+     * 往list 集合当中添加6 个学生, 无需 ,  先试用工具类按照score 进行降序排序
+     * 使用stream 查询年龄大于18 的学生,保留3个 , 将他们分数+10分
+     */
+    @Test
+    public void test9(){
+        List<Student> students = new ArrayList<>();
+        students.add(new Student(1L,"zhangsan",19,90.0));
+        students.add(new Student(2L,"zhangsan1",17,91.0));
+        students.add(new Student(3L,"zhangsan2",16,90.0));
+        students.add(new Student(4L,"zhangsan3",19,93.0));
+        students.add(new Student(5L,"zhangsan4",20,95.0));
+        students.add(new Student(6L,"zhangsan5",21,80.0));
+        students.add(new Student(7L,"zhangsan6",13,99.0));
+        // 调用工具类进行分数排序
+        Collections.sort(students);
+        students.stream().
+                filter(s-> s.getAge() > 18).
+                map(s-> {
+                    s.setScore(s.getScore()+10);
+                    return s;
+                }).
+                limit(3).   //保留3个
+                forEach(e-> System.out.println(e));
+    }
+
+
+    @Test
+    public void test10(){
+        List<Integer> list1 = Arrays.asList(1, 2);
+        List<Integer> list2 = Arrays.asList(3, 4, 5);
+
+        // 想要把两个集合当中数据放到一起然后进行处理
+        Stream.of(list1, list2).
+                flatMap(list-> list.stream()).
+                forEach(e-> System.out.println(e));
+    }
+
+    /**
+     * ArrayList<Student>   list1   3 个学生    list2 3个徐盛
+     * 需要把两个班级归类一起查看年龄>18 信息
+     */
+    @Test
+    public void test11(){
+        ArrayList<Student> list1 = new ArrayList<>();
+        list1.add(new Student(1L,"zhangsan",19,80.0));
+        list1.add(new Student(2L,"zhangsan2",17,81.0));
+        list1.add(new Student(3L,"zhangsan3",16,82.0));
+
+        ArrayList<Student> list2 = new ArrayList<>();
+        list2.add(new Student(1L,"zhangsan5",19,80.0));
+        list2.add(new Student(2L,"zhangsan6",17,81.0));
+        list2.add(new Student(3L,"zhangsan7",16,82.0));
+
+        Stream.of(list1,list2).
+                flatMap(list -> list.stream()).
+                filter(s -> s.getAge()>18).
+                forEach(e-> System.out.println(e));
+    }
+
+    @Test
+    public void test12(){
+        List<Integer> list1 = Arrays.asList(1,3,2,6,5);
+        list1.stream().sorted().forEach(e-> System.out.println(e));
+    }
+
+
+    /**
+     * 想要从大到小进行降序排序
+     */
+    @Test
+    public void test13(){
+        List<Integer> list1 = Arrays.asList(1,3,2,6,5);
+//        list1.stream().sorted(new Comparator<Integer>() {
+//            @Override
+//            public int compare(Integer o1, Integer o2) {
+//                return o2 - o1;
+//            }
+//        }).forEach(e-> System.out.println(e));
+        list1.stream().sorted(((o1, o2) -> o2-o1)).forEach(e-> System.out.println(e));
+    }
+
+
+    /**
+     * list<Student> 按照学生成绩进行降序排序 , 取前三名
+     */
+    @Test
+    public void test14(){
+        List<Student> students = new ArrayList<>();
+        students.add(new Student(1L,"zhangsan",19,90.0));
+        students.add(new Student(2L,"zhangsan1",17,91.0));
+        students.add(new Student(3L,"zhangsan2",16,90.0));
+        students.add(new Student(4L,"zhangsan3",19,93.0));
+        students.add(new Student(5L,"zhangsan4",20,95.0));
+        students.add(new Student(6L,"zhangsan5",21,80.0));
+        students.add(new Student(7L,"zhangsan6",13,99.0));
+
+        students.stream().
+                sorted((o1, o2) -> (int) (o2.getScore()-o1.getScore())).  // 按照分数降序排序
+                limit(3). //保留前3名
+                forEach(e-> System.out.println(e));
+    }
+
+    /**
+     * 需求1:  获取给定一个集合数据的总数
+     *
+     * 需求2: 获取给定一个集合中的最大值
+     *
+     * 需求3: 获取给定一个集合中的最小值
+     */
+    @Test
+    public void test15(){
+        List<Integer> list1 = Arrays.asList(1,3,2,6,5);
+        System.out.println(list1.stream().filter(e-> e> 3).count());
+
+        // 获取集合当中最大值 和最小值
+        System.out.println(list1.stream().min((o1, o2) -> o1- o2).get());
+        System.out.println(list1.stream().max((o1, o2) -> o1- o2).get());
+    }
+
+    /**
+     * List 集合 查询分数大于90分学生有多少个人
+     * 查询班级分数最高同学
+     * 查询班级分数最低同学
+     */
+    @Test
+    public void test16(){
+        List<Student> students = new ArrayList<>();
+        students.add(new Student(1L,"zhangsan",19,90.0));
+        students.add(new Student(2L,"zhangsan1",17,91.0));
+        students.add(new Student(3L,"zhangsan2",16,90.0));
+        students.add(new Student(4L,"zhangsan3",19,85.0));
+        students.add(new Student(5L,"zhangsan4",20,95.0));
+        students.add(new Student(6L,"zhangsan5",21,80.0));
+
+        System.out.println(students.stream().filter(s -> s.getScore() > 90).count());
+        System.out.println(students.stream().max((o1, o2) -> (int) (o1.getScore() - o2.getScore())).get());
+        System.out.println(students.stream().min((o1, o2) -> (int) (o1.getScore() - o2.getScore())).get());
+    }
+
+    /**
+     * collect(Collectors.toSet(),Collection.toList(),toMap())
+     */
+    @Test
+    public void test17(){
+        List<Integer> list = Arrays.asList(1,2,3,4,4,5,6);
+        //list->set
+        Set<Integer> set = list.stream().collect(Collectors.toSet());
+        System.out.println(set);
+        //set->list
+        List<Integer> list1 = set.stream().collect(Collectors.toList());
+        System.out.println(list1);
+        //list->map
+
+        List<Integer> list2 = Arrays.asList(1,2,3,4);
+        Map<Integer, Integer> map = list2.stream().distinct().collect(Collectors.toMap(e -> e, e -> e * e));
+        System.out.println(map);
+
+    }
+
+    /**
+     * List<Student>
+     * 按照分数排序
+     * 查询名字中包含zhang
+     * 需要让他年龄+5
+     * 保留3
+     * 最终要把转成map  (key=studentId, value =student)
+     */
+    @Test
+    public void test18(){
+        List<Student> students = new ArrayList<>();
+        students.add(new Student(1L,"zhangsan",19,90.0));
+        students.add(new Student(2L,"zhangsan1",17,91.0));
+        students.add(new Student(3L,"zhangsan2",16,90.0));
+        students.add(new Student(4L,"zhangsan3",19,85.0));
+        students.add(new Student(5L,"zhangsan4",20,95.0));
+        students.add(new Student(6L,"zhangsan5",21,80.0));
+
+        Map<Long, Student> map = students.stream().
+                sorted((o1, o2) -> (int) (o2.getScore() - o1.getScore())).  // 按照分数降序排序
+                        filter(s -> s.getName().contains("zhang")).  // 名字当中是否包含zhang
+                        map(s -> {      // 讲年龄+5
+                    s.setAge(s.getAge() + 5);
+                    return s;
+                }).
+                limit(3).  // 取前3个
+                collect(Collectors.toMap(e -> e.getId(), e -> e));// 转成map
+        System.out.println(map);
+    }
+
+    /**
+     * .collect(Collectors.summingInt(e -> e));
+     * 求平均  求和
+     *
+     */
+    @Test
+    public void test19(){
+        List<Integer> list = Arrays.asList(1,2,3,4,4,5,6);
+        IntSummaryStatistics collect = list.stream().collect(Collectors.summarizingInt(e -> 2*e));
+        System.out.println("总和为"+collect.getSum());
+        System.out.println("平均值:"+collect.getAverage());
+        System.out.println("最大值:"+collect.getMax());
+        System.out.println("最小值为:"+collect.getMin());
+    }
+}

+ 19 - 0
java-base-project10/day26/src/com/sf/_04_stream/Student.java

@@ -0,0 +1,19 @@
+package com.sf._04_stream;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class Student implements Comparable<Student> {
+    private Long id;
+    private String name;
+    private Integer age ;
+    private Double score;
+
+    @Override
+    public int compareTo(Student o) {
+        return (int) (o.getScore() - this.getScore());
+    }
+}