Quellcode durchsuchen

20 21 22 23 24 天代码

fanjialong vor 9 Monaten
Ursprung
Commit
72ccc409cd
43 geänderte Dateien mit 2556 neuen und 0 gelöschten Zeilen
  1. 29 0
      src/main/java/com/sf/day20/_01_code/Test.java
  2. 335 0
      src/main/java/com/sf/day20/_02_io/Test.java
  3. 50 0
      src/main/java/com/sf/day20/_02_io/dt/Student.java
  4. 41 0
      src/main/java/com/sf/day20/_02_io/dt/User.java
  5. 148 0
      src/main/java/com/sf/day21/_01_buffer_io/Test.java
  6. 31 0
      src/main/java/com/sf/day21/_02_jar/Test.java
  7. 12 0
      src/main/java/com/sf/day21/_03_junit/UserServiceImpl.java
  8. 12 0
      src/main/java/com/sf/day21/_03_junit/UserServiceImpl1.java
  9. 42 0
      src/main/java/com/sf/day21/_04_properties/MyTest.java
  10. 88 0
      src/main/java/com/sf/day22/_01_properties/ProeprotiesTest.java
  11. 18 0
      src/main/java/com/sf/day22/_01_properties/data/Data.java
  12. 19 0
      src/main/java/com/sf/day22/_01_properties/dt/Result.java
  13. 40 0
      src/main/java/com/sf/day22/_01_properties/dt/User.java
  14. 11 0
      src/main/java/com/sf/day22/_01_properties/ex/LoginException.java
  15. 8 0
      src/main/java/com/sf/day22/_01_properties/service/ILoginService.java
  16. 52 0
      src/main/java/com/sf/day22/_01_properties/service/impl/LoginServiceImpl.java
  17. 81 0
      src/main/java/com/sf/day22/_02_xml/XMLTest.java
  18. 49 0
      src/main/java/com/sf/day22/_03_class/dt/Cat.java
  19. 56 0
      src/main/java/com/sf/day22/_03_class/dt/Student.java
  20. 30 0
      src/main/java/com/sf/day22/_03_class/dt/User.java
  21. 185 0
      src/main/java/com/sf/day22/_03_class/test/ClassTest.java
  22. 24 0
      src/main/java/com/sf/day22/_03_class/util/PrintJavaBeanUtil.java
  23. 169 0
      src/main/java/com/sf/day23/_01_javaBean/LombokTest.java
  24. 24 0
      src/main/java/com/sf/day23/_01_javaBean/Person.java
  25. 15 0
      src/main/java/com/sf/day23/_01_javaBean/Student.java
  26. 243 0
      src/main/java/com/sf/day23/_02_lombda/LombdaTest.java
  27. 15 0
      src/main/java/com/sf/day23/_02_lombda/dt/Data.java
  28. 15 0
      src/main/java/com/sf/day23/_02_lombda/dt/Product.java
  29. 8 0
      src/main/java/com/sf/day23/_02_lombda/service/IFunctionAble.java
  30. 9 0
      src/main/java/com/sf/day23/_02_lombda/service/IMyPredicate.java
  31. 5 0
      src/main/java/com/sf/day23/_02_lombda/service/IPrintable.java
  32. 5 0
      src/main/java/com/sf/day23/_02_lombda/service/IRandomable.java
  33. 6 0
      src/main/java/com/sf/day23/_02_lombda/service/IShowAble.java
  34. 122 0
      src/main/java/com/sf/day24/_01_lombda/LambdaTest.java
  35. 165 0
      src/main/java/com/sf/day24/_02_method_ref/MethodRefrenceTest.java
  36. 7 0
      src/main/java/com/sf/day24/_02_method_ref/dt/Product.java
  37. 12 0
      src/main/java/com/sf/day24/_02_method_ref/servcie/FuntionService.java
  38. 7 0
      src/main/java/com/sf/day24/_02_method_ref/servcie/IRunService.java
  39. 15 0
      src/main/java/com/sf/day24/_02_method_ref/servcie/impl/Person1Impl.java
  40. 11 0
      src/main/java/com/sf/day24/_02_method_ref/servcie/impl/Person2Impl.java
  41. 317 0
      src/main/java/com/sf/day24/_03_stream/StreamTest.java
  42. 12 0
      src/main/java/com/sf/day24/_03_stream/dt/Product.java
  43. 13 0
      src/main/java/com/sf/day24/_03_stream/dt/User.java

+ 29 - 0
src/main/java/com/sf/day20/_01_code/Test.java

@@ -0,0 +1,29 @@
+package com.sf.day20._01_code;
+
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+
+public class Test {
+
+    public static void main(String[] args) throws UnsupportedEncodingException {
+        method1();
+    }
+
+    /**
+     * 字符串的编码和解码
+     * 编码: str-> byte[]   str.getBytes(编码规则);
+     * 解码: byte[] -> str  new String(字节数组,编码规则);
+     */
+    private static void method1() throws UnsupportedEncodingException {
+        //编码
+        String str = "love中";
+        byte[] bytes = str.getBytes("UTF-8");
+        // 问题bytes 当中有多个元素?
+        // java 当中long的类不需要导入就可以只用
+        System.out.println(Arrays.toString(bytes));
+
+        //解码
+        System.out.println(new String(bytes,"UTF-8"));
+    }
+}

+ 335 - 0
src/main/java/com/sf/day20/_02_io/Test.java

@@ -0,0 +1,335 @@
+package com.sf.day20._02_io;
+
+import com.sf.day20._02_io.dt.Student;
+import com.sf.day20._02_io.dt.User;
+
+import java.io.*;
+import java.lang.reflect.Field;
+import java.util.*;
+
+public class Test {
+    public static void main(String[] args) throws IOException {
+//        method1();
+//        method2();
+//        method3();
+
+//        method4();
+//        method5();
+
+//        method6();
+//        method8();
+        method9();
+    }
+
+    private static void method9() throws IOException {
+        /**
+         * 现在在d盘有一个文件 , 文件内容为 abcdedfaedfg
+         * 要求读取文件内容统计每个字符出现次数
+         * 最终把内容输出到d 盘下面c.txt 当中
+         * a - 2次
+         * b - 3次
+         * .....
+         */
+        //1 创建两个File 分别只想a.txt 和b.txt
+        File file = new File("D:\\a.txt");
+        File file1 = new File("D:\\c.txt");
+        //2 创建字符输入流和字符输出流
+        FileReader fileReader = new FileReader(file);
+        FileWriter fileWriter = new FileWriter(file1);
+        //3 创建字符数组char[] buffer
+        //[a,c,e,d,c ,0,0,0,0,0,0]
+        char[] buffer = new char[1024];
+        //4 fileReader.read(buffer)
+        fileReader.read(buffer);
+        //5 创建Map<Char,Integer> map
+        Map<Character,Integer> map = new HashMap<>();
+        //6 遍历字符数组
+        for (char c : buffer) {
+            if(c == 0){
+                continue;
+            }
+            //7 判断在map 当中是否存在,如果不存在就设置数量为1
+            if(!map.containsKey(c)){
+                map.put(c,1);
+            }else{
+                //8 如果存在就上之前数量+1
+                map.put(c,map.get(c) + 1);
+            }
+        }
+        System.out.println(map);
+
+        //9 遍历map ,拿到每一个key-value
+
+        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
+            //10 把文件当中去输出内容
+            Character key = entry.getKey();    // a b c d
+            Integer value = entry.getValue();  // 次数
+            // a - 2   b -1  c -1
+            // 调用输出流进行输出
+            fileWriter.write(key + " - " + value);
+            fileWriter.write(System.lineSeparator());
+        }
+        // 关闭资源
+        fileReader.close();
+        fileWriter.close();
+
+    }
+
+    private static void method8() throws IOException {
+        File file = new File("D:\\a.txt");
+        // 创建管道
+        FileReader fileReader = new FileReader(file);
+
+        char[] buffer = new char[2];
+        int len = 0;
+        while ((len = fileReader.read(buffer))!=-1){
+            System.out.println(Arrays.toString(buffer));
+        }
+        // 关闭资源
+        fileReader.close();
+    }
+
+    private static void method7() throws IOException {
+        //1  确定目的地
+        File file = new File("D:\\a.txt");
+        //2 创建管道
+        FileWriter fileWriter = new FileWriter(file);
+        //3 把数据写出去
+        fileWriter.write("你好中国啊 aaaaaaaa");
+        //4 关闭资源
+        fileWriter.close();
+    }
+
+
+
+    /**
+     * 需求2 : 现在d 盘中有一个b.txt 的文件内容为 i love coding
+     *         要求吧b.txt 内容拷贝到 c.txt中内容 你的名字 + i love coding
+     */
+    private static void method6() throws IOException {
+        // 创建File  b.txt
+        File file = new File("D:\\B.txt");
+        // 创建File  c.txt
+        File file1 = new File("D:\\C.txt");
+        // 创建输入流FileInputStream ->file
+        FileInputStream fileInputStream = new FileInputStream(file);
+        // 创建输出流FileOutputStream-> file
+        FileOutputStream fileOutputStream = new FileOutputStream(file1);
+        // 定义byte数组
+        byte[] buffer= new byte[1024];
+        // len = 0
+        int len = 0;
+        // while 读数据
+        while ((len = fileInputStream.read(buffer))!=-1){
+            // 在循环内部写数据
+            String str = new String(buffer,0,len,"UTF-8");
+            // 往c.txt 写
+            fileOutputStream.write(("fanjialong "+str).getBytes());
+        }
+
+        // 关闭资源
+        fileInputStream.close();
+        fileOutputStream.close();
+    }
+
+    /**
+     *  现在在d盘的a.txt 文件中有一个内容name=zhangsan
+     *  要把内容存到map 当中key = name  value 值等于zhangsan
+     */
+    private static void method5() throws IOException {
+        File file = new File("D:\\a.txt");
+        // 创建一个输入流
+        FileInputStream fileInputStream = new FileInputStream(file);
+        // 读取数据
+        byte[] buffer = new byte[1024];
+        int len = 0;
+
+        len = fileInputStream.read(buffer);
+        // name=zhangsan
+        String str = new String(buffer,0,len,"UTF-8");
+        // 把数据存储到map 当中key name value zhangsan
+        String[] arr = str.split("=");
+        Map<String,Object> map=  new HashMap<>();
+        map.put(arr[0],arr[1]);
+        System.out.println(map);
+        // 关闭资源
+        fileInputStream.close();
+    }
+
+    /**
+     * 学习输入流: 如何使用输入流读取磁盘的数据
+     */
+    private static void method4() throws IOException {
+        /**
+         * - 1 确定源和目的地
+         * - 2 创建管道(创建文件字节输入流对象)
+         * - 3 把数据读进来
+         * - 4 释放资源
+         */
+         //1 创建File
+        File file = new File("D:\\a.txt");
+        // 2 创建输入管道,FileInputStream
+        FileInputStream fileInputStream = new FileInputStream(file);
+        // 3 调用file.read()方法读取, 一个字节一个字节的读取
+        //abc中
+        // file.read() 方法一个字节一个字节读取太麻烦了
+        //abc中a   1022 97 1023 98  1024  -27   中
+        byte[] b = new byte[1024];
+        int len = 0;
+        //[97 98 99]   abc
+        //[ -27 -127 -189]  中
+        //[97 -127 -189]  a 乱码
+        // while循环什么时候结束,文件读取完结束
+        // 什么时候文件读取完 , read() 返回值是-1
+        // 如果read() 方法不传递byte数组默认就是读取一个字节
+        // 如果read()  方法传递byte 数组那读取的就是有效长度
+        while ((len=fileInputStream.read(b)) !=-1){
+            // 不等于-1 表示文件还有内容
+            // String(字节数组,从字节数组那一个位置开始0,有效长度,编码)
+            // 因为我们发现最后一次读取我们要看有效长度
+            String str = new String(b,0,len,"UTF-8");
+            System.out.println(str);
+        }
+        // 4 关闭资源
+        fileInputStream.close();
+    }
+
+
+
+
+
+
+    //需求:用户可以在控制台当中输入 id  ,name  ,age ,score
+    // 要求最终把内容输出到文件c.txt当中
+    /**
+     *    id    name     age  score     第一部分
+     *    1     zhangsan 18    70
+     *    2     lisi     19    60
+     *    3     wangwu   17    50       第二部分
+     *    总人数:3人      第三部分
+     *    总分数:180      第四部分
+     *    平均分:60       第五部分
+     *
+     */
+
+    private static void method3() throws IOException {
+        // 1 创建Scaner 对象
+        Scanner scanner = new Scanner(System.in);
+        // 2 获取id name age score
+        List<Student> students = new ArrayList<>();
+        for (int i = 0; i < 3; i++) {
+            // 3 吧信息封装到一个对象当中User
+            System.out.println("请输入id");
+            long id = scanner.nextLong();
+            System.out.println("请输入name:");
+            String name = scanner.next();
+            System.out.println("请输入age");
+            int age = scanner.nextInt();
+            System.out.println("请输入分数");
+            int score = scanner.nextInt();
+            Student student = new Student(id,name,age,score);
+            // 4 User 对象放到一个集合当中 List<User> list  User1 User2 User3
+            students.add(student);
+        }
+        // 5 创建File file 指定磁盘文件
+        File file = new File("D:\\a.txt");
+        // 6 FileOutputStream outputStream
+        FileOutputStream fileOutputStream = new FileOutputStream(file,true);
+        // 7 outPutStream.wirte("id  name  age  score".getBytes("UTF-8"));
+        fileOutputStream.write("id  name  age  score".getBytes("UTF-8"));
+        // 8 write(换行)
+        fileOutputStream.write(System.lineSeparator().getBytes("UTF-8"));
+        Integer countScore = 0;
+        // 9 便利集合,拿到集合每一个元素
+        for (Student student : students) {
+//            1     zhangsan 18    70
+            String str = student.getId() + "  " + student.getName() +"  " + student.getAge()+"  " + student.getScore();
+            fileOutputStream.write(str.getBytes("UTF-8"));
+            // 10 write(user.getId +" " + user.getName() +" " + user.getAge(" ")+ user.getScore().getBytes("UTF-8"))
+            fileOutputStream.write(System.lineSeparator().getBytes("UTF-8"));
+            // 计算总分数
+            countScore +=student.getScore();
+        }
+        // 11 计算出来总人数list.size , 然后调用outuptSteram 去写出
+        fileOutputStream.write(("总人数:"+students.size()).getBytes("UTF-8"));
+        fileOutputStream.write(System.lineSeparator().getBytes("UTF-8"));
+        // 12 计算出来总分数, 然后调用outPutsteam 去写出
+        fileOutputStream.write(("总分数:"+countScore).getBytes());
+        fileOutputStream.write(System.lineSeparator().getBytes("UTF-8"));
+        // 13 计算平均分, 然后写出   countPrice/students.size();
+        fileOutputStream.write(("平均数"+ countScore/students.size()).getBytes("UTF-8"));
+
+    }
+    //需求:现在又一个List<User(id name integal)> 集合
+    /**
+     * 集合当中有3 个元素 User(1L,zhangsan,10) User2 (2L, lisi ,10) User3(3L,wangwu ,20)
+     * 要求把名字输出到一个文件 b.txt     zhangsan-lisi-wangwu
+     * 把积分综合添加到一个c.txt 文件中   40
+     */
+    private static void method2() throws IOException {
+        List<User> list = new ArrayList<>();
+        list.add(new User(1L,"zhangsan",10));
+        list.add(new User(2L,"lisi",10));
+        list.add(new User(3L,"wangwu",20));
+
+        File file = new File("D:\\b.txt");
+        File file1 = new File("D:\\c.txt");
+        // 拼接字符串
+        StringBuilder stringBuilder = new StringBuilder();
+        // 便利jihe
+        Integer sum = 0;
+        for (int i = 0; i < list.size(); i++) {
+            User user = list.get(i);
+            if(i == list.size()-1){
+                stringBuilder.append(user.getName());
+            }else{
+                stringBuilder.append(user.getName()).append("-");
+            }
+            sum += user.getIntegral();
+        }
+        // 往文件当中输出内容
+        FileOutputStream fileOutputStream = new FileOutputStream(file);
+        FileOutputStream fileOutputStream1 = new FileOutputStream(file1);
+        // 往b.txt 输出 zhangsan-lisi-wangwu
+        fileOutputStream.write(stringBuilder.toString().getBytes("UTF-8"));
+        // 往c.txt 输出40
+        fileOutputStream1.write(sum.toString().getBytes("UTF-8"));
+
+        // 关闭资源
+        fileOutputStream.close();
+        fileOutputStream1.close();
+
+
+
+    }
+
+    private static void method1() throws IOException {
+        /**
+         * - 1 确定源和目的地
+         *
+         * - 2 创建管道(创建字节输出流对象)
+         *
+         * - 3 把数据写出去
+         *
+         * - 4 释放资源
+         */
+        //1 创建目的地 其实就是创建File
+        File file = new File("D:\\abc\\f.txt");
+        //2 创建管道 , 其实就是创建输出流
+        // 在实际开发当中我们在写入内容时候不想覆盖而是在之前的内容的基础上进行增加
+        // fileOutputSteram(appned: 是否追加)
+        FileOutputStream fileOutputStream = new FileOutputStream(file,true);
+        //3 往文件当中去写内容
+//        fileOutputStream.write(105);
+//        fileOutputStream.write(108);
+
+        fileOutputStream.write(System.lineSeparator().getBytes());
+        String str = "中国";
+        fileOutputStream.write(str.getBytes("UTF-8"));
+        //4 关系资源
+        fileOutputStream.close();
+     }
+
+
+
+}

+ 50 - 0
src/main/java/com/sf/day20/_02_io/dt/Student.java

@@ -0,0 +1,50 @@
+package com.sf.day20._02_io.dt;
+
+public class Student {
+    private Long id;
+    private String name;
+    private Integer age;
+    private Integer score;
+
+    public Student() {
+    }
+
+    public Student(Long id, String name, Integer age, Integer score) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+        this.score = score;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Integer getAge() {
+        return age;
+    }
+
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    public Integer getScore() {
+        return score;
+    }
+
+    public void setScore(Integer score) {
+        this.score = score;
+    }
+}

+ 41 - 0
src/main/java/com/sf/day20/_02_io/dt/User.java

@@ -0,0 +1,41 @@
+package com.sf.day20._02_io.dt;
+
+public class User {
+    private Long id;
+    private String name;
+    private Integer integral;
+
+
+    public User() {
+    }
+
+    public User(Long id, String name, Integer integral) {
+        this.id = id;
+        this.name = name;
+        this.integral = integral;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Integer getIntegral() {
+        return integral;
+    }
+
+    public void setIntegral(Integer integral) {
+        this.integral = integral;
+    }
+}

+ 148 - 0
src/main/java/com/sf/day21/_01_buffer_io/Test.java

@@ -0,0 +1,148 @@
+package com.sf.day21._01_buffer_io;
+
+import java.io.*;
+
+public class Test {
+    public static void main(String[] args) throws IOException {
+//        method2();
+//        method3();
+//        method4();
+        method5();
+    }
+
+
+    /**
+     * 需求2 :
+     * 现在有一个文件的内容为
+     * 我是清风拂过岭,
+     * 爱河潺潺润桃花。
+     * 中国大地春常在,
+     * 国泰民安享岁华。
+     *
+     * 最终把这首诗每一行的第一字 拼接我爱中国  把他输出到一个文件中
+     *
+     */
+    private static void method5() throws IOException {
+        // 缓冲字符输入流
+        BufferedReader bufferedReader = new BufferedReader(new FileReader(new File("d:\\a.txt")));
+        // 缓冲字符输出流
+        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(new File("d:\\d.txt")));
+
+        String str = null;
+        StringBuilder sb = new StringBuilder();
+        while ((str = bufferedReader.readLine())!=null){
+            char[] chars = str.toCharArray();
+            sb.append(chars[0]);
+        }
+        bufferedWriter.write(sb.toString());
+        //关闭资源方法
+        bufferedReader.close();
+        bufferedWriter.close();
+
+    }
+
+    /**
+     * 现在在d盘中有一个a.txt 日志文件
+     * 要求把error 错误信息输出到另外一个文件当中
+     */
+    private static void method4() throws IOException {
+        // 缓冲字符输入流
+        BufferedReader bufferedReader = new BufferedReader(new FileReader(new File("d:\\a.txt")));
+        // 缓冲字符输出流
+        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(new File("d:\\error.txt")));
+
+        String str = null;
+        while ((str = bufferedReader.readLine())!=null){
+            //判断内容是否包含error
+            if(str.contains("error")){
+                //吧这行内容写到文件中
+                bufferedWriter.write(str);
+                bufferedWriter.newLine();
+            }
+        }
+        // 关闭资源
+        bufferedReader.close();
+        bufferedWriter.close();
+
+    }
+
+
+
+
+    private static void method3() throws IOException {
+        // 字符缓冲流   字符缓冲输入流 和字符缓冲输出Luis
+        // 使用字符输入缓冲流
+//        File file = new File("d:\\a.txt");
+//        FileReader fileReader = new FileReader(file);
+        BufferedReader bufferedReader = new BufferedReader(new FileReader(new File("d:\\a.txt")));
+        // 把a.txt 内容写到 b.txt 当中
+        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(new File("d:\\b.txt")));
+
+        String st = null;
+        while ((st=bufferedReader.readLine())!=null){
+            bufferedWriter.write(st);
+            bufferedWriter.newLine();
+        }
+        bufferedReader.close();
+        bufferedWriter.close();
+    }
+
+    private static void method2() throws IOException {
+        // 把d盘下的视频 拷贝到d盘的a.avi当中
+        // 要求使用字节流进行操作,一次性读取一个 ,要求统计一共耗时多久
+        // 在开始的时候记录一下时间, 在结束的时候记录一下时间观察一共耗时多久
+        long start = System.currentTimeMillis();
+        //TODO: io操作
+        // 1 创键File d盘视频   File 指向a.avi
+        File file = new File("D:\\a.mp4");
+        File file1 = new File("D:\\b.mp4");
+        // 2 创建字节输入流和字节输出流
+        FileInputStream fileInputStream = new FileInputStream(file);
+
+        // 创建字节输入缓冲流
+        BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
+        FileOutputStream fileOutputStream = new FileOutputStream(file1);
+        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
+        // 3 定义byte数组[1]
+        byte[] buffer = new byte[1];
+        int len = 0;
+        // 4 while 读取
+        while ((bufferedInputStream.read(buffer))!=-1){
+            // 5 在就往另外一文件当中写内容
+            bufferedOutputStream.write(buffer);
+        }
+        // 6 关闭资源
+        long end = System.currentTimeMillis();
+        System.out.println("耗时时间:" +(end-start)/1000 + " 秒");
+        // 使用缓存流 必须要调用close 方法,只要调用close 方法他才能把缓存区内容 写或者读 到文件中
+        bufferedInputStream.close();
+        bufferedOutputStream.close();
+    }
+
+    public static void method1() throws IOException {
+        // 把d盘下的视频 拷贝到d盘的a.avi当中
+        // 要求使用字节流进行操作,一次性读取一个 ,要求统计一共耗时多久
+        // 在开始的时候记录一下时间, 在结束的时候记录一下时间观察一共耗时多久
+        long start = System.currentTimeMillis();
+        //TODO: io操作
+        // 1 创键File d盘视频   File 指向a.avi
+        File file = new File("D:\\a.mp4");
+        File file1 = new File("D:\\b.mp4");
+        // 2 创建字节输入流和字节输出流
+        FileInputStream fileInputStream = new FileInputStream(file);
+        FileOutputStream fileOutputStream = new FileOutputStream(file1);
+        // 3 定义byte数组[1]
+        byte[] buffer = new byte[1];
+        int len = 0;
+        // 4 while 读取
+        while ((fileInputStream.read(buffer))!=-1){
+            // 5 在就往另外一文件当中写内容
+            fileOutputStream.write(buffer);
+        }
+        // 6 关闭资源
+        long end = System.currentTimeMillis();
+        System.out.println("耗时时间:" +(end-start)/1000 + " 秒");
+    }
+
+
+}

+ 31 - 0
src/main/java/com/sf/day21/_02_jar/Test.java

@@ -0,0 +1,31 @@
+package com.sf.day21._02_jar;
+
+import com.koobieteach.LoginController;
+import com.koobieteach.UserMapper;
+import com.koobietech.ApplicationContext;
+import com.koobietech.util.CalcUtil;
+
+public class Test {
+    public static void main(String[] args) {
+//        method1();
+        method2();
+    }
+
+    /**
+     * 需求:
+     *  要求定义spring.jar 里面提供ApplicationContext类中createBean方法打印 spring创建对象
+     *  要求定义mybatis.jar  里面定义UserMapper 里面 get() 放 打印mybatis 操作数据库数据
+     *  要求定义springmvc.jar 里面定义UserController 里面定义login() 里面打印springmvc 操作表现层
+     *
+     *  最终在vip35这个项目中引入3个jar 包然后分别打印
+     */
+    private static void method2() {
+        ApplicationContext.createBean();
+        UserMapper.get();
+        LoginController.get();
+    }
+
+    private static void method1() {
+        System.out.println(CalcUtil.add(1, 2));
+    }
+}

+ 12 - 0
src/main/java/com/sf/day21/_03_junit/UserServiceImpl.java

@@ -0,0 +1,12 @@
+package com.sf.day21._03_junit;
+
+public class UserServiceImpl {
+
+    public void addUser(){
+        System.out.println("添加用户");
+    }
+
+    public void deleteUesr(){
+        System.out.println("删除用户");
+    }
+}

+ 12 - 0
src/main/java/com/sf/day21/_03_junit/UserServiceImpl1.java

@@ -0,0 +1,12 @@
+package com.sf.day21._03_junit;
+
+public class UserServiceImpl1 {
+
+    public void addUser(){
+        System.out.println("添加用户");
+    }
+
+    public void deleteUesr(){
+        System.out.println("删除用户");
+    }
+}

+ 42 - 0
src/main/java/com/sf/day21/_04_properties/MyTest.java

@@ -0,0 +1,42 @@
+package com.sf.day21._04_properties;
+
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Properties;
+
+public class MyTest
+{
+
+
+    /**
+     * 需求: 现在有一个User类 User类当中有两字段username 一个password
+     * 要求吧配置文件db.properties 当中username值  和password 的值123 设置对象的字段中
+     *
+     */
+    @Test
+    public void test() throws IOException {
+        // 这个需求就设计到读取配置文件内容
+        /**
+         * Properties 常用类
+         * 提供无参数构造器
+         * properties.load(inputStream 输入流);
+         * properties.getProperty(key) 获取配置文件当中内容 比如getProperty(username) root
+         */
+        //加载properties 文件
+        // 以后在实际开发当中不会采用new FileInputStream 方式呢?
+        // 原因: 是因为这里的路径写死了, 而且有盘符d:\\  c:\\  但是在Linux 当中和Mac 是没有盘符的概念的
+        // 以后我们代码要在Linux 系统上运行, 如果这样在你的电脑可以运行, 但是一旦运行在Linux 当中就运行不了
+        FileInputStream fileInputStream = new FileInputStream(new File("D:\\ideaproject\\VIP35\\src\\main\\resources\\db.properties"));
+        Properties properties  = new Properties();
+        properties.load(fileInputStream);
+
+        // 最红把信息存到User 中
+        String username = properties.getProperty("username");
+        String password = properties.getProperty("password");
+        System.out.println(username +"----" + password);
+    }
+}

+ 88 - 0
src/main/java/com/sf/day22/_01_properties/ProeprotiesTest.java

@@ -0,0 +1,88 @@
+package com.sf.day22._01_properties;
+
+import com.sf.day22._01_properties.dt.Result;
+import com.sf.day22._01_properties.ex.LoginException;
+import com.sf.day22._01_properties.service.ILoginService;
+import com.sf.day22._01_properties.service.impl.LoginServiceImpl;
+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.Properties;
+
+public class ProeprotiesTest {
+
+
+    // 加载配置文件内容 resources db.properties 内容
+    // Thread.currentThread().getContextClassLoader().getResourcesAsStream();
+    @Test
+    public void test() throws IOException {
+        // 获取类加载器
+        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+        // 通过类加载器获取resources db.properties 内容转成输入流
+        // 我们以后resources当中可能有很多配置文件   name 就是我们配置文件的名字
+        // 第二种方式相对于第一种方式自己new File(路径)  更好, 因为我是没有在这里写死盘符路径的
+        InputStream inputStream = contextClassLoader.getResourceAsStream("db.properties");
+        // 创建Properties
+        Properties properties = new Properties();
+        properties.load(inputStream);
+
+        // 获取配置文件当中账号和密码
+        String username = properties.getProperty("username");
+        String password = properties.getProperty("password");
+        System.out.println(username);
+        System.out.println(password);
+    }
+
+    /**
+     * 1 创建Data 然后在Data 的静态代码块中初始化一个Map<Long,User>
+     *     1 User(1L,"zhangsan","123")
+     *     2 User(2L,"lisi","567")
+     *     3 User(3L,"wangwu","666")
+     * 2 在配置文件当中定义账号和密码
+     * 3 完成登录功能
+     *    要求:1 面向接口编程
+     *         2 在接口实现类当中判断配置文件当中账号和密码 与 map 当中账号密码做对比
+     *         3 如果成功 在数据{code:200,msg:"操作成功"};
+     *         4 如果失败 {code:500,msg: "登录失败"}
+     *         5 扩展:登录成功或者登录失败 往d:\\login.txt 当中添加 姓名 +"--" +时间 + 成功/失败
+     *         注意如果账号密码不正确要求在方法方法中抛出LoginException("登录失败")
+     *  面向对象: 静态代码块 接口  IO  自定义异常   trycach
+     **/
+    @Test
+    public void test2() throws IOException, DocumentException {
+        /**
+         * 需要加载db.properties 文件内容
+         */
+        InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("db.xml");
+//        Properties properties = new Properties();
+//        properties.load(inputStream);
+        // 采用的xml
+        SAXReader saxReader = new SAXReader();
+        Document document = saxReader.read(inputStream);
+        // 1 获取根元素
+        Element element = document.getRootElement();
+        // 2 可以根据跟元素获取username 和password
+        Element usernameEle = element.element("username");
+        String username = usernameEle.getText();
+        Element passwordEle = element.element("password");
+        String password = passwordEle.getText();
+
+
+        ILoginService loginService = new LoginServiceImpl();
+        try{
+            loginService.login(username,password);
+            System.out.println(new Result(200,"登录成功"));
+        }catch (LoginException e){
+            e.printStackTrace();
+            System.out.println(new Result(500,e.getMessage()));
+        }finally {
+            inputStream.close();
+        }
+
+    }
+}

+ 18 - 0
src/main/java/com/sf/day22/_01_properties/data/Data.java

@@ -0,0 +1,18 @@
+package com.sf.day22._01_properties.data;
+
+import com.sf.day22._01_properties.dt.User;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Data {
+    /**
+     * 假设这个map 就是数据库数据
+     */
+    public static Map<Long, User> map = new HashMap<>();
+    static {
+        map.put(1L,new User(1L,"zhangsan","123"));
+        map.put(2L,new User(2L,"lisi","567"));
+        map.put(3L,new User(3L,"wangwu","666"));
+    }
+}

+ 19 - 0
src/main/java/com/sf/day22/_01_properties/dt/Result.java

@@ -0,0 +1,19 @@
+package com.sf.day22._01_properties.dt;
+
+public class Result {
+    private Integer code;
+    private String msg;
+
+    @Override
+    public String toString() {
+        return "Result{" +
+                "code=" + code +
+                ", msg='" + msg + '\'' +
+                '}';
+    }
+
+    public Result(Integer code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+}

+ 40 - 0
src/main/java/com/sf/day22/_01_properties/dt/User.java

@@ -0,0 +1,40 @@
+package com.sf.day22._01_properties.dt;
+
+public class User {
+    private Long id;
+    private String username;
+    private String password;
+
+    public User(Long id, String username, String password) {
+        this.id = id;
+        this.username = username;
+        this.password = password;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public User() {
+    }
+}

+ 11 - 0
src/main/java/com/sf/day22/_01_properties/ex/LoginException.java

@@ -0,0 +1,11 @@
+package com.sf.day22._01_properties.ex;
+
+public class LoginException extends RuntimeException {
+
+    public LoginException() {
+    }
+
+    public LoginException(String message) {
+        super(message);
+    }
+}

+ 8 - 0
src/main/java/com/sf/day22/_01_properties/service/ILoginService.java

@@ -0,0 +1,8 @@
+package com.sf.day22._01_properties.service;
+
+public interface ILoginService {
+    /**
+     * 登录方法
+     */
+    public void login(String username,String password);
+}

+ 52 - 0
src/main/java/com/sf/day22/_01_properties/service/impl/LoginServiceImpl.java

@@ -0,0 +1,52 @@
+package com.sf.day22._01_properties.service.impl;
+
+import com.sf.day22._01_properties.data.Data;
+import com.sf.day22._01_properties.dt.User;
+import com.sf.day22._01_properties.ex.LoginException;
+import com.sf.day22._01_properties.service.ILoginService;
+
+import java.util.Map;
+
+public class LoginServiceImpl implements ILoginService {
+
+    /**
+     *   2 在接口实现类当中判断配置文件当中账号和密码 与 map 当中账号密码做对比
+     *   3 如果成功 在数据{code:200,msg:"操作成功"};
+     *   4 如果失败 {code:500,msg: "登录失败"}
+     *   5 扩展:登录成功或者登录失败 往d:\\login.txt 当中添加 姓名 +"--" +时间 + 成功/失败
+     *   注意如果账号密码不正确要求在方法方法中抛出LoginException("登录失败")
+     *
+     *   username和password 就是配置文件的账号和密码
+     *   zhangsan  123
+     *   lisi      566
+     *   wangwu    666
+     *
+     *   配置文件
+     *   lisi123     566
+     */
+    @Override
+    public void login(String username, String password) {
+        Map<Long, User> map = Data.map;
+        // 如何那传入的账号和密码  与map 当中账号密码做对比
+        // 可以遍历map 拿到每一个账号和密码 , 进行一一对比即可
+        //lisi     lisi  666
+        //zhangsan zhangsan 123
+        boolean flag = false;
+        for (Map.Entry<Long, User> entry : map.entrySet()) {
+            /**
+             * zhangsan  123
+             * lisi      566
+             * wangwu    666
+             */
+            User user = entry.getValue();
+            if(user.getUsername().equals(username)&& user.getPassword().equals(password)){
+                flag = true;
+            }
+        }
+        if(!flag){
+            // 插入失败日志  username
+            throw new LoginException("账号密码错误");
+        }
+        // 插入成功日志
+    }
+}

+ 81 - 0
src/main/java/com/sf/day22/_02_xml/XMLTest.java

@@ -0,0 +1,81 @@
+package com.sf.day22._02_xml;
+
+import org.dom4j.Attribute;
+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.util.List;
+
+public class XMLTest {
+    /**
+     * 我今天主要是学习xml 格式语法
+     * 今天我们会xml 文件当中写一些<标签>, 今天写的标签他是没有什么限制的你可以随意起名
+     *
+     *
+     *
+     * 但是后续我们学习了框架比如学习了spring 框架, spring 他的配置也是xml 格式
+     * 他配置文件当中标签就不开业i随意的写了
+     * <bean></bean>  在spring 你必须要按照他的规范去写 , 他才能够识别
+     *
+     *  今天我们比较轻松我们没有学习框架, 那标签名字你可以随便写
+     *  但是切记: 后续学习了框架必须要按照人家的规范去写, 他才可以识别
+     *
+     *  不论是properties 配置文件 还是xml 配置文件 都属于配置文件
+     *  配置解决问题:  解决硬编码问题
+     *
+     *  最终都需要把配置文件当中内容读取到程序当中
+     *  今天我们学习xml 这个文件需要我们来解析读取  (了解)
+     *  后续我们学习了框架,这个信息是不需要我们来解析,框架来解析 ,后面我们的项目用的都是框架
+     *
+     *  在解析XML 的时候
+     *  他把属性封装到Attribute 当中
+     *  把标签内容封装到Text 对象当中
+     *  文档是用的Document 对象
+     *  元素是使用Element 元素
+     *
+     *
+     */
+
+
+
+
+
+    /**
+     * Element getRootElement():Document的方法,用来获取根元素;
+     * List elements():用来获取所有子元素
+     * Element element(String name):用来获取第一个指定名字的子元素;
+     * String getText() 用于获取元素的文本内容
+     */
+    @Test
+    public void test() throws DocumentException {
+        // 1 使用类加载器获取xml 文件内容
+        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+        InputStream inputStream = contextClassLoader.getResourceAsStream("user.xml");
+        // 2 创建SAXReader对象-xml read   Properties -properties   load
+        SAXReader saxReader = new SAXReader();
+        // 3 调用SAXReader.read(in) 方法 读取数据 Document 对象
+        Document document = saxReader.read(inputStream);
+        // 4 根据文档对象获取跟元素
+        Element element = document.getRootElement();
+        // 5 根据跟元素获取他的子元素
+        List<Element> elements = element.elements();
+        // 6 获取第二个节点
+        Element element1 = elements.get(1);
+        Attribute attribute = element1.attribute("id");
+        System.out.println(attribute.getValue());
+        // 7 获取name 元素
+        Element nameElement = element1.element("name");
+        // 8 获取name 的内容
+        String text = nameElement.getText();
+        System.out.println(text);
+    }
+
+    /**
+     * 把上午的Properties登录的案例 修改成使用XML 方式去操作
+     * 跟节点叫做db    下面有两个子节点  <username>zhangsan</username>  <password>123</password>
+     */
+}

+ 49 - 0
src/main/java/com/sf/day22/_03_class/dt/Cat.java

@@ -0,0 +1,49 @@
+package com.sf.day22._03_class.dt;
+
+public class Cat {
+    private String name;
+    private String color;
+    private  Integer age;
+
+    public Cat() {
+    }
+
+    @Override
+    public String toString() {
+        return "Cat{" +
+                "name='" + name + '\'' +
+                ", color='" + color + '\'' +
+                ", age=" + age +
+                '}';
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getColor() {
+        return color;
+    }
+
+    public void setColor(String color) {
+        this.color = color;
+    }
+
+    public Integer getAge() {
+        return age;
+    }
+
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    public Cat(String name, String color, Integer age) {
+        this.name = name;
+        this.color = color;
+        this.age = age;
+    }
+}

+ 56 - 0
src/main/java/com/sf/day22/_03_class/dt/Student.java

@@ -0,0 +1,56 @@
+package com.sf.day22._03_class.dt;
+
+public class Student {
+    private Long id;
+    private String name;
+    private Integer age;
+    private Integer score;
+
+    public Student(Long id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    @Override
+    public String toString() {
+        return "Student{" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ", age=" + age +
+                ", score=" + score +
+                '}';
+    }
+
+    private Student(Long id, String name, Integer age) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+    }
+
+    public Student(Long id, String name, Integer age, Integer score) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+        this.score = score;
+    }
+
+    public Student() {
+
+    }
+
+    private void eat(){
+        System.out.println("吃东西");
+    }
+
+    public void sleep(){
+        System.out.println("睡觉");
+    }
+
+    public void run(String shoe){
+        System.out.println("穿着"+shoe +"跑步");
+    }
+
+    public static void m1(){
+        System.out.println("这是一个静态方法");
+    }
+}

+ 30 - 0
src/main/java/com/sf/day22/_03_class/dt/User.java

@@ -0,0 +1,30 @@
+package com.sf.day22._03_class.dt;
+
+public class User {
+    private String name;
+    private Integer age;
+
+    public User() {
+    }
+
+    public User(String name, Integer age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Integer getAge() {
+        return age;
+    }
+
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+}

+ 185 - 0
src/main/java/com/sf/day22/_03_class/test/ClassTest.java

@@ -0,0 +1,185 @@
+package com.sf.day22._03_class.test;
+
+import com.sf.day22._03_class.dt.Cat;
+import com.sf.day22._03_class.dt.Student;
+import com.sf.day22._03_class.dt.User;
+import com.sf.day22._03_class.util.PrintJavaBeanUtil;
+import org.dom4j.Attribute;
+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.InvocationTargetException;
+import java.lang.reflect.Method;
+
+public class ClassTest {
+
+
+    // 我的需求是这个方法传入什么对象就打印什么对象
+    //
+    @Test
+    public void test(){
+        User user = new User("zhangsan",10);
+        Cat cat = new Cat("xiaomi","黄色",10);
+        PrintJavaBeanUtil.print(cat);
+    }
+
+    /**
+     * 获取字节码的三种方式
+     * 第一种方式 Class.forName("全限定名") com.sf.day22._03_class.test.ClassTest
+     * 第二种方式 Person.class    获取字节码
+     * 第三种方式 Object 当中有一个方法叫做getClass()  能够获取字节码信息
+     */
+
+    @Test
+    public void test1() throws ClassNotFoundException {
+        // 1 创建 字节码对象
+        Class<?> clz = Class.forName("com.sf.day22._03_class.dt.Cat");
+        System.out.println(clz);
+        // 2 调用是类名.class     在Object 当中有这样class 的字段
+        Class<Cat> clz1 = Cat.class;
+        System.out.println(clz1  == clz);
+        // 3 使用对象方式获取class
+        Cat cat = new Cat();
+        Class<? extends Cat> clz2 = cat.getClass();
+        System.out.println(clz2);
+
+        //选择 : 你如果有对象那就用getClass() ,
+        // 如果此时只有类 调用.class
+        // 如果你能够获取全限定名那用Class.forName
+    }
+
+    @Test
+    public void test2() throws NoSuchMethodException {
+        // 获取构造器
+        // 1 获取字节码对象
+        Class<Student> clz = Student.class;
+        // 2 通过字节码对象获取构造器
+        // 获取所有public 构造器
+//        Constructor<?>[] constructors = clz.getConstructors();
+        // 如果你想要获取所有的构造器包含非public privte
+//        Constructor<?>[] declaredConstructors = clz.getDeclaredConstructors();
+//
+//        for (Constructor<?> constructor : declaredConstructors) {
+//            System.out.println(constructor.getName());
+//            System.out.println(constructor.getParameterCount());
+//        }
+        // 我就想要获取 Student(id,name,age)
+//        Constructor<Student> constructor = clz.getConstructor(Long.class, String.class,Integer.class);
+        Constructor<Student> declaredConstructor = clz.getDeclaredConstructor(Long.class, String.class, Integer.class);
+        System.out.println(declaredConstructor.getName());
+        System.out.println(declaredConstructor.getParameterCount());
+    }
+
+
+    @Test
+    public void test3() throws NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {
+        // 创建对象 迪奥用Student 全参构造器
+        //1 获取字节码对象
+        Class<Student> clz = Student.class;
+        //2 通过字节码对象获取构造器
+//        Constructor<Student> constructor = clz.getConstructor(Long.class, String.class, Integer.class, Integer.class);
+//        //3 创建对象 new Instance(..);
+//        Student student = constructor.newInstance(1L, "zhangsan", 10, 30);
+//        System.out.println(student);
+        // 这种是一种省略写法 , 正常要先获取构造器在newInstance() 如果调用无参构造器clz.newInstance();
+        Student student = clz.newInstance();
+    }
+
+    /**
+     * 需求: 模拟spring 底层源码实现
+     * 步骤: 1 创建一个xml 文件, 在xml 文件中定义一个beans根标签
+     *      2 在根标签中定义 bean 标签里面有一个 class属性值为 = com.sf.day22._03_class.dt.Student
+     *       Element element1 = elements.get(1);
+     *       Attribute attribute = element1.attribute("属性名");
+     *       attribute.getValue() 可以获取值
+     *      3 要求创建出来Student 对象
+     *      4 如果把class 的值修改成com.sf.day22._03_class.dt.Cat
+     *      要创建Cat 对象java 不可以改动只能改动配置文件
+     *
+     *
+     */
+    @Test
+    public void test4() throws DocumentException, ClassNotFoundException, IllegalAccessException, InstantiationException {
+        //读取Xml文件信息
+        InputStream inputStream = Thread.currentThread().
+                getContextClassLoader().
+                getResourceAsStream("spring.xml");
+        // XARReader
+        SAXReader saxReader = new SAXReader();
+        Document document = saxReader.read(inputStream);
+        //获取根元素
+        Element element = document.getRootElement();
+        // 通过跟元素获取bean
+        Element bean = element.element("bean");
+        // 获取bean 标签属性
+        Attribute attribute = bean.attribute("class");
+        String value = attribute.getValue();
+        System.out.println(value);
+
+        // 通过反射创建出来Student 对象
+        Class<?> clz = Class.forName(value);
+        Object o = clz.newInstance();
+        System.out.println(o);
+    }
+
+    /**
+     * 通过字节码获取方法
+     */
+    @Test
+    public void test5() throws NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {
+        //1 获取字节码对象
+        Class<Student> clz = Student.class;
+        //2 通过字节吗获取方法
+        // getMethods() 获取所有public 方法, 还包含父类方法
+//        Method[] methods = clz.getMethods();
+        // getDeclaredMethods 获取的是当前类的所有方法包含非public
+//        Method[] methods = clz.getDeclaredMethods();
+//        for (Method method : methods) {
+//            System.out.println("方法的名字"+ method.getName());
+//            System.out.println("方法的参数"+method.getParameterCount());
+//        }
+        /**
+         * 第一个参数: 方法名字
+         * 第二个参数: 方法参数的类型
+         */
+        Method method = clz.getMethod("m1");
+//        System.out.println(method.getName());
+//        System.out.println("参数数量"+ method.getParameterCount());
+
+        // 获取eat 方法呢?
+//        Method method1 = clz.getDeclaredMethod("eat");
+//        System.out.println(method1);
+
+        // 调用run 方法
+        /**
+         * invoke 方法当中有两个参数
+         * 第一个参数: 对象
+         * 第二个参数: 你调用方法传递的参数
+         * publci void  run(String shpe)
+         */
+//        method.invoke(clz.newInstance(),"耐克");
+        // 如果调用的是静态方法,第一个参数是可以不用传递的
+        method.invoke(null);
+        //作用:
+        // 需求: 有一个类
+        /**
+         * class Common{
+         *     private String name = "123"
+         *     public String getName(){
+         *         return name;
+         *     }
+         * }
+         *
+         * 在测试类中已知条件
+         * String  str = 全限定名
+         * String  methodName = "name"
+         * 要求调用getName 获取返回值123
+         */
+    }
+
+}

+ 24 - 0
src/main/java/com/sf/day22/_03_class/util/PrintJavaBeanUtil.java

@@ -0,0 +1,24 @@
+package com.sf.day22._03_class.util;
+
+import com.sf.day22._03_class.dt.Cat;
+import com.sf.day22._03_class.dt.User;
+import com.sun.media.jfxmediaimpl.HostUtils;
+
+public class PrintJavaBeanUtil {
+    // 传入什么对象就打印什么对象的属性值
+    // 如果有一天我又创建了一个新的类我也想打印他的属性信息 这个方法能打印吗?
+    public static void print(Object object){
+//        System.out.println(user.getAge());
+//        System.out.println(user.getName());
+        if(object instanceof Cat){
+            Cat cat= (Cat) object;
+            System.out.println(cat.getAge());
+            System.out.println(cat.getName());
+            System.out.println(cat.getColor());
+        }else if(object instanceof User){
+            User user = (User) object;
+            System.out.println(user.getName());
+            System.out.println(user.getAge());
+        }
+    }
+}

+ 169 - 0
src/main/java/com/sf/day23/_01_javaBean/LombokTest.java

@@ -0,0 +1,169 @@
+package com.sf.day23._01_javaBean;
+
+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;
+
+public class LombokTest {
+
+    @Test
+    public void test(){
+        Person person = new Person();
+        person.setAge(10);
+        System.out.println(person.getAge());
+    }
+
+    @Test
+    public void test1() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
+        /**
+         *  已知条件有一个类全名 com.sf.day23._01_javaBean.Student
+         *  已知属性名   name
+         *  要求获取name 的值其实就是要调用getName方法获取值
+         *
+         *  使用反射如何操作?
+         */
+        // 我们现在目标要获取对象当中getName返回值,也就是说我要调用getName 方法
+        String className = "com.sf.day23._01_javaBean.Student";
+        String propertyName= "name";
+
+        // 1 获取字节码对象
+        Class<Student> clz = (Class<Student>) Class.forName(className);
+        // 2 通过字节码对象创建实力
+        Student student = clz.newInstance();
+        // 3 获取getName 方法
+        //  这个第三方如何获取getName 方法 get + N + amme
+        String methodName = "get"+ propertyName.substring(0,1).toUpperCase() +
+                propertyName.substring(1);
+        System.out.println(methodName);
+        // get+ 获取name 的第一个字符然后把他转换成大写 , 获取剩余内容进行拼接
+        // 4 通过反射去调用方法
+        Method method = clz.getMethod(methodName);
+        // 5 调用方法
+        System.out.println(method.invoke(student));
+
+    }
+
+    @Test
+    public void test2() throws IntrospectionException, IllegalAccessException, InstantiationException, InvocationTargetException {
+        // 获取对象的属性
+        // 内省是在反射的基础上去进行操作的, 也是要用到我们的字节吗对象
+        // 1 需要获取到字节码信息
+        Class<Person> clas = Person.class;
+        // 2 获取javaBean 信息
+        // 现在我们的javaBean 信息就已经是封装到了beanInfo 当中了
+        // 这在获取javaBean 信息的时候他不仅会获取本来当中属性还会获取他父类的属性 Object class
+        BeanInfo beanInfo = Introspector.getBeanInfo(clas,Object.class);
+        // 3 在beanInfo 当中有一个方法可以获取到我们javaBean 当中属性信息
+        // 由于我们javaBean 当中可能存在着多个属性,所以返回是一个数组
+        // 每一个属性比如name 他都会封装到PropertyDescriptor 当中 比如我们属性name 我们属性类型
+        PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
+        // 4 遍历拿到每一个属性描述器
+        // 注意: 这个属性描述器当中是包含了咱们属性的所有信息 名字 类型...
+        for (PropertyDescriptor propertyDescriptor :descriptors){
+            System.out.println("属性名字---" +propertyDescriptor.getName());
+            System.out.println("属性的类型---"+propertyDescriptor.getPropertyType() );
+            // 一个getReadMethod 相当于get属性名   getWriteMethod 相当于set方法
+            // 还记得我们在拼接getName 方法的时候有多麻烦吗? 需要不断调用字符串方法进行转换
+            // 需求: 如果属性的name 是name , 我们就给他的值设置为zhangsan
+            if("name".equals(propertyDescriptor.getName())){
+                // set 方法
+                Person person = clas.newInstance();
+                Method method = propertyDescriptor.getWriteMethod();
+                method.invoke(person,"zhangsan");
+                // 获取name 内容
+                //get 方法
+                System.out.println(propertyDescriptor.getReadMethod().invoke(person));
+            }
+        }
+    }
+
+    // Javabean 转 map
+    // 要求提供一个方法, 方法传递一个对象,对象的类型不固定, 要求返回一个map
+    // 比如我传递是一个User(id,name,sn) id=1,name=zhangsan,sn=123   返回map{id=1,name=zhangsan,sn=123}
+    // 如果我们传递的Cat(color,name)   返回的就是 map{color=黄色,name=小黄}
+    public Map<String,Object> beanToMap(Object object) throws IntrospectionException, IllegalAccessException, InstantiationException, InvocationTargetException {
+        // 创建map
+        Map<String,Object> map = new HashMap<>();
+        // 最终 要把javaBean 当中属性 放到map
+        // 以为这我要获取javaBean 属性,如果我能获取到, 放到map 当中put
+        // 问题转移到了如何获取javaBean 属性 -> 内省
+        Class<?> clz = object.getClass();
+        // 1 获取beanInfo 信息
+        BeanInfo beanInfo = Introspector.getBeanInfo(clz, Object.class);
+        // 2 根据beanInfo 获取到类当中所有的属性描述器
+        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+        // 3 遍历所有的属性描述器拿到每一个属性描述器
+        for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
+            // 拿到属性描述起 我就可以拿到属性的名字, 我也可以拿到属性的值
+            // 有属性的名字和属性的值 我们不就可以往map 当中去存储数据了吗
+            String name = propertyDescriptor.getName();
+            // 获取属性值如何获取?  调用get方法去获取  , 在属性名描述起中 getReadMethod();
+            Object val = propertyDescriptor.getReadMethod().invoke(object);
+            // 往map 当中存储数据
+            map.put(name,val);
+        }
+        return map;
+    }
+
+    @Test
+    public void test3() throws InvocationTargetException, IntrospectionException, InstantiationException, IllegalAccessException {
+        Map<String, Object> map = beanToMap(new Student("lisi"));
+        System.out.println(map);
+    }
+
+
+    /**
+     * 把Map 转成JavaBean
+     * 传递Map<String,Object>  map(id=1,name=zhangsan,age=10)   Person()
+     *                        map(name="xiaoming")             Student();
+     *
+     *  需求: 把Map 转成JavaBean 对象
+     *  public Object mapTojavaBean(Map<String,Object) map, Class clz>)
+     */
+    @Test
+    public void test4() throws InvocationTargetException, IntrospectionException, InstantiationException, IllegalAccessException {
+        Map<String,Object> map = new HashMap<>();
+        map.put("name","zhangsan");
+        // 现在功能已经是实现完了,有一点缺陷我们返回值是一个Object 对象需要进行强转
+        // 我想要的效果我们传入了什么类型 返回值就是什么类型, 这里就要用到我们之前学习过泛型
+        Person person = mapToJavaBean(map, Person.class);
+        System.out.println(person);
+    }
+
+    public <T>T mapToJavaBean(Map<String,Object> map,Class<T> clz) throws IllegalAccessException, InstantiationException, IntrospectionException, InvocationTargetException {
+        // 把map 准成javaBean
+        // 把map 当中数据取出来, 存到javaBean
+        // 把map 当中数据取出来,可以通过遍历方式拿到每一个key-value
+        // 把数据存到javaBean属性中,  使用内省getWriteMethod():
+        T t = clz.newInstance();
+
+        // 使用内省
+        BeanInfo beanInfo = Introspector.getBeanInfo(clz, Object.class);
+        // id name age
+        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+        /**
+         *  key   value
+         *  id     1
+         *  name   zhangsan
+         *  age    10
+         *
+         *  Student(1,zhangsan,10)
+         */
+        for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
+            // 对象当中属性名
+            // map 当中key - 属性名 , map 当中value 属性值
+            String key = propertyDescriptor.getName();
+            Object val = map.get(key);
+            // 最终要把value 存储对象的字段中 要调用set 方法 getWriteMethod
+            propertyDescriptor.getWriteMethod().invoke(t,val);
+        }
+        return t;
+    }
+}

+ 24 - 0
src/main/java/com/sf/day23/_01_javaBean/Person.java

@@ -0,0 +1,24 @@
+package com.sf.day23._01_javaBean;
+
+import lombok.*;
+
+/**
+ * @Getter  代码get 方法
+ * @Setter  代表set 方法
+ * @ToString  toString 方法
+ * @AllArgsConstructor 全参数构造器
+ * @NoArgsConstructor  无参数构造器
+ * @Data  这里不建议用这个, 需要什么就贴什么注解
+ */
+@Getter
+@Setter
+@ToString
+@AllArgsConstructor
+@NoArgsConstructor
+@Data
+public class Person {
+    private Long id;
+    private String name;
+    private Integer age;
+
+}

+ 15 - 0
src/main/java/com/sf/day23/_01_javaBean/Student.java

@@ -0,0 +1,15 @@
+package com.sf.day23._01_javaBean;
+
+
+import lombok.*;
+
+@Getter
+@Setter
+@ToString
+@AllArgsConstructor
+@NoArgsConstructor
+public class Student {
+    private String name = "123";
+
+
+}

+ 243 - 0
src/main/java/com/sf/day23/_02_lombda/LombdaTest.java

@@ -0,0 +1,243 @@
+package com.sf.day23._02_lombda;
+
+import com.sf.day23._02_lombda.dt.Data;
+import com.sf.day23._02_lombda.dt.Product;
+import com.sf.day23._02_lombda.service.*;
+import org.junit.Test;
+
+import java.util.*;
+
+public class LombdaTest {
+    @Test
+    public void test(){
+        // 创建一个线程 ,并且把这个线程启动起来, 启动以后执行run方法
+        // 通过匿名内部类的方式进行传递参数
+//        new Thread(new Runnable() {
+//            public void run() {
+//                System.out.println("开一个子线程处理一个耗时操作");
+//            }
+//        }).start();
+
+        // lambda 表达式的初体验
+        /**
+         * lombda 表达式有一个很大作用就是简化我们匿名内部类的写法
+         *
+         */
+        new Thread(()-> System.out.println("开启一个线程")).start();
+    }
+//
+
+
+//    private void findProductByPrice(List<Product> products) {
+//        for (Product product : products) {
+//            if(product.getPrice()>1000){
+//                System.out.println(product);
+//            }
+//        }
+//    }
+
+//    public void findProductByName(List<Product> list){
+//        // 遍历list 集合 判断proudct.getName.contains("手机")
+//        for (Product product : list) {
+//            if(product.getName().contains("手机")){
+//                System.out.println(product);
+//            }
+//        }
+//    }
+//
+//    需求1: 筛选出所有名称包含手机的商品
+//    需求2: 筛选出所有价格大于1000的商品
+    @Test
+    public void test2(){
+        List<Product> products = Data.products;
+//        findProduct(products);
+//        findProduct(products, new IMyPredicate() {
+//            @Override
+//            public boolean isFlag(Product product) {
+//                return product.getName().contains("手机");
+//            }
+//        });
+        findProduct(products,p-> p.getName().contains("手机"));
+    }
+    @Test
+    public void test3(){
+        List<Product> products = Data.products;
+//        findProduct(products, new IMyPredicate() {
+//            @Override
+//            public boolean isFlag(Product product) {
+//                return product.getPrice()>1000;
+//            }
+//        });
+        findProduct(products,p-> {
+            return p.getPrice()>1000;
+        });
+    }
+    /**
+     *  想要优化一下代码:
+     *  定义一个接口-方法, boolean isFlag()
+     *  要求吧提供一个方法 findProduct(List<Product> products, MyPredicate predicate)
+     *  在测试类当中调用这个方法去实现之前的两个需求
+     */
+
+    public void findProduct(List<Product> list, IMyPredicate predicate){
+        for (Product product : list) {
+            if(predicate.isFlag(product)){
+                System.out.println(product);
+            }
+        }
+    }
+
+//   练习1:编写一个接口 IShowable,接口中存在一个抽象方法show,
+//    无参数无返回值,在方法里面打印无参数无返回值
+//   在定义方法这方法需要传递一个参数, 参数类型就是IShowable   public void metho1(IShowable show){}
+
+    /**
+     * lamda表示主要就是为了解决特定条件的匿名内部类的一个语法糖
+     * 条件: 必须是一个接口当中只有一个方法
+     *  方法类型: 无参数无返回值  无参数有返回值  有参数有返回值  有参数无发回执
+     *  我们就是学习这几个类型方法, 使用lamda 表达式如何去写
+     *
+     *  简化语法
+     *  (形参)->  {}
+     *  多个形参要用,进行分割, 如果只有一个参数 () 可以省略不写,如果有多个参数必须写()
+     *  {} 方法体,如果只有一行代码, 可以省略{}  如果有多行内容必须写}{}
+     *
+     *  练习2:编写一个接口 IPrintable,接口中存在一个抽象方法print,
+     *  有参数无返回值,定义一个方法(接口) 在测试方法中调用  使用lambda表达式
+     */
+    @Test
+    public void test4(){
+//        printInfo(new IShowAble() {
+//            @Override
+//            public void show() {
+//                System.out.println("无参数无返回值");
+//            }
+//        });
+        // 使用lambda表达式进行简化
+        printInfo(()-> {
+            System.out.println("第一行代码");
+            System.out.println("第二行代码");
+        });
+    }
+
+    @Test
+    public void test5(){
+//        print("123123", new IPrintable() {
+//            @Override
+//            public void print(String name) {
+//                System.out.println(name);
+//            }
+//        });
+        print("!123",10,(e,a) -> System.out.println(e + "---" + a));
+    }
+
+    public void printInfo(IShowAble showAble){
+        showAble.show();
+    }
+
+    public void print(String name,Integer age,IPrintable iPrintable){
+        iPrintable.print(name,10);
+    }
+
+
+
+    @Test
+    public void test56(){
+//        random(new IRandomable() {
+//            @Override
+//            public String getRandom() {
+//                return "随机数";
+//            }
+//        });
+
+        // lambda表达式简化
+        random(()-> {
+//            return "随机数";
+            StringBuilder sb = new StringBuilder();
+            for (int i = 0; i < 5; i++) {
+                Random random = new Random();
+                int randomVal = random.nextInt(10);
+                sb.append(randomVal);
+            }
+            return sb.toString();
+        });
+
+
+    }
+
+    //练习3:编写一个接口 IRandomable,接口中存在一个抽象方法getRandom,
+    // 无参数有返回值,传入对应的lambda表达式
+
+    public void random(IRandomable randomable){
+        String random = randomable.getRandom();
+        System.out.println(random);
+    }
+
+
+    /**
+     * 需求1
+     * 一个接口有一个方法getRandom(),
+     * 先在要求提供一个方法返回5个数数字验证码
+     * 要求使用使用lambda 表达式
+     *
+     * 需求2
+     * 定义一个接口-接口有一个方法,
+     * String(是集合内容)  get(List<String> list , int index)
+     * 调用的时候要使用lambda 表达式
+     */
+
+    @Test
+    public void test6(){
+        List<String> list = Arrays.asList("zhangsan", "lisi", "wangwu");
+        String result = method1(list, 1, (l, i) -> l.get(i));
+        System.out.println(result);
+    }
+
+
+    public String method1(List<String> list,int index,IFunctionAble able){
+        return able.get(list,index);
+    }
+
+    @Test
+    public void test7(){
+        // 先在有一个List 集合我想要遍历List
+        List<String> list = Arrays.asList("1123", "@34", "@#4234");
+        // for 循环
+//        for (int i = 0; i < list.size(); i++) {
+//            System.out.println(list.get(i));
+//        }
+        // forEach
+//        for(String str: list){
+//            System.out.println(str);
+//        }
+        // 调用forEach 方法进行遍历
+//        list.forEach(new Consumer<String>() {
+//            @Override
+//            public void accept(String s) {
+//                System.out.println(s);
+//            }
+//        });
+//        list.forEach(s -> System.out.println(s));
+
+        Map<String,String> map = new HashMap<>();
+        map.put("手机","小米");
+        map.put("笔记本","苹果笔记本");
+        map.put("鼠标","罗技鼠标");
+
+        // map 遍历方式主要有两种方式
+        // map.entrySet()  map.keySet();
+//        for (Map.Entry<String, String> stringStringEntry : map.entrySet()) {
+//            System.out.println(stringStringEntry);
+//        }
+//        Set<String> keys = map.keySet();
+//        for (String key : keys) {
+//            System.out.println(key +"="+ map.get(key));
+//        }
+        // 使用foreach 进行遍历
+        map.forEach((key,value)->{
+            System.out.println(key +"="+value);
+        });
+
+    }
+
+}

+ 15 - 0
src/main/java/com/sf/day23/_02_lombda/dt/Data.java

@@ -0,0 +1,15 @@
+package com.sf.day23._02_lombda.dt;
+
+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,"鼠标"));
+    }
+}

+ 15 - 0
src/main/java/com/sf/day23/_02_lombda/dt/Product.java

@@ -0,0 +1,15 @@
+package com.sf.day23._02_lombda.dt;
+
+import lombok.*;
+
+@Getter
+@Setter
+@ToString
+@AllArgsConstructor
+@NoArgsConstructor
+public class Product {
+    private Long    id;         // 序号
+    private String  name;       // 商品名称
+    private Double 	price;      // 价格
+    private String  type;       // 类型
+}

+ 8 - 0
src/main/java/com/sf/day23/_02_lombda/service/IFunctionAble.java

@@ -0,0 +1,8 @@
+package com.sf.day23._02_lombda.service;
+
+import java.util.List;
+
+@FunctionalInterface
+public interface IFunctionAble {
+    String get(List<String> list,int index);
+}

+ 9 - 0
src/main/java/com/sf/day23/_02_lombda/service/IMyPredicate.java

@@ -0,0 +1,9 @@
+package com.sf.day23._02_lombda.service;
+
+import com.sf.day23._02_lombda.dt.Product;
+
+public interface IMyPredicate {
+    boolean isFlag(Product product);
+
+//    void test();
+}

+ 5 - 0
src/main/java/com/sf/day23/_02_lombda/service/IPrintable.java

@@ -0,0 +1,5 @@
+package com.sf.day23._02_lombda.service;
+
+public interface IPrintable {
+    void print(String name,Integer age);
+}

+ 5 - 0
src/main/java/com/sf/day23/_02_lombda/service/IRandomable.java

@@ -0,0 +1,5 @@
+package com.sf.day23._02_lombda.service;
+
+public interface IRandomable {
+    String getRandom();
+}

+ 6 - 0
src/main/java/com/sf/day23/_02_lombda/service/IShowAble.java

@@ -0,0 +1,6 @@
+package com.sf.day23._02_lombda.service;
+
+public interface IShowAble {
+    // 定义一个无参数无返回值
+    void show();
+}

+ 122 - 0
src/main/java/com/sf/day24/_01_lombda/LambdaTest.java

@@ -0,0 +1,122 @@
+package com.sf.day24._01_lombda;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+
+public class LambdaTest {
+
+    /**
+     * 没有jdk 提供函数时间接口我们还需要自己去定义函数式接口,现在在做需求之前
+     * 一定是要看jdk 是否有提供如果没有提供或者提供没有办法满足我们的需求在去自己创建
+     *
+     * 要求使用lambda 表达式去实现
+     * 需求1:编写 shop 方法输出消费多少元 monety      有参数无返回值     Consumer 接口
+     * 需求2:编写 getCode 方法返回指定位数的5随机验证码  无参数有返回值  Supplier
+     * 需求3:编写 getStringRealLength 方法返回字符串真实长度   有参数有返回值 Function
+     * 需求4:编写 getString 方法返回长度大于5的字符串的集合     有参数 判断 Predicate     */
+
+    //需求1:编写 shop 方法输出消费多少元 monety      有参数无返回值     Consumer 接口
+    @Test
+    public void test(){
+//        shop(10.00, new Consumer<Double>() {
+//            @Override
+//            public void accept(Double money) {
+//                System.out.println("消费了:"+money);
+//            }
+//        });
+        shop(10.00, e-> System.out.println(e));
+    }
+
+
+    public void shop(double money, Consumer<Double> consumer){
+        consumer.accept(money);
+    }
+
+
+//    需求2:编写 getCode 方法返回指定位数的5随机验证码  无参数有返回值  Supplier
+
+    @Test
+    public void test2(){
+//        String code = getCode(new Supplier<String>() {
+//            @Override
+//            public String get() {
+//                StringBuilder sb = new StringBuilder();
+//                for (int i = 0; i < 5; i++) {
+//                    sb.append(new Random().nextInt(10));
+//                }
+//                return sb.toString();
+//            }
+//        });
+//        System.out.println(code);
+        //其实在调用PrintStream 当中pringln 方法
+        System.out.println();
+        String code = getCode(() -> {
+            StringBuilder sb = new StringBuilder();
+            for (int i = 0; i < 5; i++) {
+                sb.append(new Random().nextInt(10));
+            }
+            return sb.toString();
+        });
+        System.out.println(code);
+    }
+
+    public String getCode(Supplier<String> supplier){
+        return supplier.get();
+    }
+
+
+//    需求3:编写 getStringRealLength 方法返回字符串真实长度   有参数有返回值 Function
+    @Test
+    public void test3(){
+//        Integer length = getStringRealLength("   abcd  ", new Function<String, Integer>() {
+//            @Override
+//            public Integer apply(String s) {
+//                // "   str   "
+//                return s.trim().length();
+//            }
+//        });
+//        System.out.println(length);
+        System.out.println(getStringRealLength("  abcd  ", e -> e.trim().length()));
+    }
+
+    public Integer getStringRealLength(String str, Function<String,Integer> function){
+        return function.apply(str);
+    }
+
+//    需求4:编写 getString 方法返回长度大于5的字符串的集合     有参数 判断 Predicate
+    @Test
+    public void test4(){
+        List<String> list = Arrays.asList("abcded", "abc", "aaaaaaa", "bb", "cccccccc");
+//        List<String> e = getString(list, new Predicate<String>() {
+//            @Override
+//            public boolean test(String s) {
+//                return s.length() > 5;
+//            }
+//        });
+        List<String> newList = getString(list, s -> s.length() > 5);
+        System.out.println(newList);
+    }
+
+    public List<String> getString(List<String> list, Predicate<String> predicate){
+        //1 遍历传入的list集合
+        List<String> newList = new ArrayList<>();
+        list.forEach(e ->{
+            //2 拿到集合当中每一元素
+            //3 调用predicate 方法去判断是否符合条件
+            //4 如果符合条件放到一个新的集合中
+            if(predicate.test(e)){
+                //5 返回新的集合
+                newList.add(e);
+            }
+        });
+      return newList;
+    }
+}

+ 165 - 0
src/main/java/com/sf/day24/_02_method_ref/MethodRefrenceTest.java

@@ -0,0 +1,165 @@
+package com.sf.day24._02_method_ref;
+
+import com.sf.day24._02_method_ref.dt.Product;
+import com.sf.day24._02_method_ref.servcie.FuntionService;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+public class MethodRefrenceTest {
+
+
+    @Test
+    public void test(){
+        // 拿遍历集合去体验方法引用
+        // 使用forEach 遍历集合
+        List<String> list = Arrays.asList("123","456","789");
+        list.forEach(new Consumer<String>() {
+            // 这个s 我们集合当中元素
+            @Override
+            public void accept(String s) {
+                System.out.println(s);
+            }
+        });
+
+        // 使用lambda 表达式
+        list.forEach(s -> System.out.println(s));
+        // 使用方法引用方式
+        list.forEach(System.out::println);
+    }
+
+    //静态方法 的 方法引用语法
+    @Test
+    public void test1(){
+        Supplier supplier = new Supplier() {
+            @Override
+            public Object get() {
+                return Math.random();
+            }
+        };
+
+
+        //使用lambda 表达式去简化上面写法
+        Supplier supplier1 = () -> Math.random();
+        //使用方法引用
+        Supplier supplier2 = Math::random;
+        Object o = supplier2.get();
+        System.out.println(o);
+    }
+
+    /**
+     * 需求: 利用Supplier 接口 , 在方法中返回new Product
+     * 分别使用匿名内部类防腐蚀
+     * 使用lombda 表达式方式
+     * 使用方法引用方法
+     *
+     * 针对于构造器 简化类名 :: new
+     *
+     */
+    @Test
+    public void test4(){
+        Supplier<Product> supplier = new Supplier<Product>() {
+            @Override
+            public Product get() {
+                return new Product();
+            }
+        };
+
+        // 使用lambda 表达式去简化
+        Supplier<Product> supplier1 = () -> new Product();
+        // 使用方法引用方式进行简化
+        Supplier<Product> supplier2 = Product::new;
+        System.out.println(supplier2);
+    }
+
+    /**
+     * 需求: 利用Function 接口方法 要查看我们传入字符串长度
+     * 要求: 分别使用 匿名内部类  lambda 表达式  方法引用
+     */
+    @Test
+    public void test5(){
+        Function<String,Integer> function = new Function<String, Integer>() {
+            @Override
+            public Integer apply(String s) {
+                return s.length();
+            }
+        };
+
+        // 使用lambda 表达式简化
+        Function<String,Integer> function1 = s -> s.length();
+        // 使用方法引用方式简化
+        Function<String,Integer> function2 = String::length;
+        System.out.println(function2.apply("123123"));
+    }
+    /**
+     * 需求
+     * 要求提供一个函数式接口 里面有两个参数List<String> ,int size
+     * 要求把长度大于3的字符串 放到一个新的集合中,这个新的集合大小size
+     *
+     * 要求分别使用匿名内部类 , lambda 表达式 , 方法引用去操作
+     *
+     */
+
+    @Test
+    public void test6(){
+        // 使用匿名内部类方式
+        FuntionService funtionService = new FuntionService() {
+            @Override
+            public List<String> fun(List<String> list, Integer size) {
+                List<String> newList = new ArrayList<>();
+                for (String item : list) {
+                    if(item.length()>3){
+                        if(newList.size() <size){
+                            newList.add(item);
+                        }
+                    }
+                }
+                return newList;
+            }
+        };
+
+        List<String> list = Arrays.asList("aaaaaaa","ssssssss", "ab", "a", "ssssss");
+//        List<String> list1 = funtionService.fun(list, 2);
+//        System.out.println(list1);
+
+        // 使用Lambda 表达式进行优化
+        FuntionService funtionService1 = (l,size)->{
+            List<String> newList = new ArrayList<>();
+            for (String item : list) {
+                if(item.length()>3){
+                    if(newList.size() <size){
+                        newList.add(item);
+                    }
+                }
+            }
+            return newList;
+        };
+
+        List<String> stringList = funtionService1.fun(list, 2);
+        System.out.println(stringList);
+
+        // 方法引用如何使用
+        // 方法作用简化咱们lambda 表达式方法体的写法, 若有有一个方法的内容和lambda 表达的方法体的内容
+        // 相同的就可以使用方法引用语法
+        FuntionService funtionService2 = MethodRefrenceTest::method11;
+        List<String> list1 = funtionService2.fun(list, 2);
+        System.out.println(list1);
+    }
+
+    public static List<String> method11(List<String> list, Integer size){
+        List<String> newList = new ArrayList<>();
+        for (String item : list) {
+            if(item.length()>3){
+                if(newList.size() <size){
+                    newList.add(item);
+                }
+            }
+        }
+        return newList;
+    }
+}

+ 7 - 0
src/main/java/com/sf/day24/_02_method_ref/dt/Product.java

@@ -0,0 +1,7 @@
+package com.sf.day24._02_method_ref.dt;
+
+public class Product {
+    //构造器也是一个特殊的方法
+    public Product() {
+    }
+}

+ 12 - 0
src/main/java/com/sf/day24/_02_method_ref/servcie/FuntionService.java

@@ -0,0 +1,12 @@
+package com.sf.day24._02_method_ref.servcie;
+
+import java.util.List;
+
+public interface FuntionService {
+
+    List<String> fun(List<String> list , Integer size);
+
+    static void eat(){
+        System.out.println(123);
+    }
+}

+ 7 - 0
src/main/java/com/sf/day24/_02_method_ref/servcie/IRunService.java

@@ -0,0 +1,7 @@
+package com.sf.day24._02_method_ref.servcie;
+
+public interface IRunService {
+    void shoeRun();
+
+    default void carRun(){}
+}

+ 15 - 0
src/main/java/com/sf/day24/_02_method_ref/servcie/impl/Person1Impl.java

@@ -0,0 +1,15 @@
+package com.sf.day24._02_method_ref.servcie.impl;
+
+import com.sf.day24._02_method_ref.servcie.IRunService;
+
+public class Person1Impl implements IRunService {
+    @Override
+    public void shoeRun() {
+        System.out.println("李宁运动鞋跑步");
+    }
+
+    @Override
+    public void carRun() {
+        System.out.println("开着比亚迪上班");
+    }
+}

+ 11 - 0
src/main/java/com/sf/day24/_02_method_ref/servcie/impl/Person2Impl.java

@@ -0,0 +1,11 @@
+package com.sf.day24._02_method_ref.servcie.impl;
+
+import com.sf.day24._02_method_ref.servcie.IRunService;
+
+public class Person2Impl implements IRunService {
+    @Override
+    public void shoeRun() {
+        System.out.println("nike运动鞋跑步");
+    }
+
+}

+ 317 - 0
src/main/java/com/sf/day24/_03_stream/StreamTest.java

@@ -0,0 +1,317 @@
+package com.sf.day24._03_stream;
+
+import com.sf.day24._03_stream.dt.Product;
+import com.sf.day24._03_stream.dt.User;
+import org.junit.Test;
+
+import java.util.*;
+import java.util.stream.Stream;
+
+public class StreamTest {
+
+    /**
+     * 需求:
+     * 操作1:对每个元素求平方
+     * 操作2:请找出数组中的偶数元素
+     * 操作3:对偶数进行升序排序
+     * 操作4:打印
+     * ArrayList(1,3,2,4)    (1,9,4,16)      ->(4,16)
+     */
+
+    @Test
+    public void test1(){
+        //1 先定义一个集合
+        List<Integer> list = Arrays.asList(1, 3, 2, 4);
+        Collections.sort(list);
+        //2 遍历拿到结合当中每一个元素
+        List<Integer> list1 = new ArrayList<>();
+        list.forEach(e ->{
+            //3 拿集合当中元素进行平方 c =   e * e
+            Integer pow = e * e;
+            //4 判断是否是偶数 if(c%2 == 0) 添加一个新的集合中
+            if(pow % 2 == 0){
+                //5 调用Collections.sort(list) 进行排序
+                list1.add(pow);
+            }
+        });
+        System.out.println(list1);
+    }
+
+    /**
+     * jdk 提供的4个函数式接口
+     * Consumer  有参数无返回值
+     * Supplier  无参数有返回值
+     * Function  有参数有返回值
+     * Predicaete   有参数有返回 返回boolean
+     */
+    @Test
+    public void test2(){
+        // 1 创建Stream 流
+        List<Integer> list = Arrays.asList(1, 3, 2, 4);
+        // stream 流他是支持链式编程    x.x.x.x.x
+        list.stream().                            // 1 创建steram 流
+                map(e -> e * e).                  // map 其实就是对于集合元素要进行什么样处理  中间操作
+                filter(e -> e % 2 == 0).           // filter表示过滤, 过滤偶数                中间操作
+                sorted().                         // 这个叫做排序                            中间操作
+                forEach(e -> System.out.println(e));   // 遍历
+    }
+
+    /**
+     *  创建Steram 流三种方式
+     *  集合.steram()
+     *  Arrays.stream()
+     *  Stream.of(元素)
+     *
+     */
+    @Test
+    public void test3(){
+        // 集合创建Stream
+        List<Integer> list = Arrays.asList(1, 2, 3, 3, 4);
+        // 遍历集合.foreach 没有中间操作就原样打印
+//        list.stream().forEach(System.out::println);
+
+        // 使用数组创建Stream
+        Integer[] arr = {1,2,3,3,4,5};
+        Stream<Integer> stream = Arrays.stream(arr);
+        stream.forEach(System.out::println);
+
+        // 使用Stream.of(1,2,3,4,5)
+        Stream.of(1,2,3,34,5).forEach(System.out::println);
+    }
+
+    @Test
+    public void test4(){
+        // 已知有这样集合{1,2,3,3,4,5,6,7}
+        // 要求求出大于3 有哪些数据
+        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
+        // 创建stream流
+        list.stream().filter(e-> e>3).forEach(System.out::println);
+    }
+
+    /**
+     * 需求: List<String>   abc   a   abcd  cd
+     *     要求找出集合当中包含 ab,进行遍历
+     */
+    @Test
+    public void tes5(){
+        List<String> list = Arrays.asList("abc", "a", "abcd", "cd");
+        list.stream().filter(e-> e.contains("ab")).forEach(System.out::println);
+    }
+
+    /**
+     * 需求: List<String>  abc dd  abcd  abc   a   abcd  cd
+     *     要求找出集合当中包含 ab,进行遍历,并且要去重
+     */
+    @Test
+    public void test6(){
+        List<String> list = Arrays.asList("abc","abcd","abc", "a", "abcd", "cd");
+        list.stream().
+                filter(e-> e.contains("ab")).
+                distinct().
+                forEach(System.out::println);
+    }
+
+
+    /**
+     * 需求: List<String>  abc,abe,cabc, dd  abcd  abc   a   abcd  cd
+     *     要求找出集合当中包含 ab,进行遍历,并且要去重
+     *     值获取2个
+     */
+    @Test
+    public void test7(){
+        List<String> list = Arrays.asList("abc","abe","cabc","abcd","abc", "a", "abcd", "cd");
+        list.stream().
+                filter(e-> e.contains("ab")).    // filter 表示过滤
+                distinct().                      // 对数据进行去重
+                limit(3).                        // 保留多少个元素
+                forEach(System.out::println);
+    }
+
+
+    /**
+     * 需求: List<String>  abc,abe,cabc, dd  abcd  abc   a   abcd  cd
+     *     要求找出集合当中包含 ab,进行遍历,并且要去重
+     *     保留3个
+     *     跳过第一个
+     */
+    @Test
+    public void test8(){
+        List<String> list = Arrays.asList("abc","abe","cabc","abcd","abc", "a", "abcd", "cd");
+        list.stream().
+                filter(e-> e.contains("ab")).    // filter 表示过滤
+                distinct().                      // 对数据进行去重
+                limit(3).                        // 保留多少个元素
+                skip(1).                         // 跳过几个元素
+                forEach(System.out::println);
+    }
+
+    /**
+     * 需求: 现在有List<Product> 集合 id name price
+     * 结合当中有5个元素(1L,小米手机,1000)  (2L,手表, 5000) ,(3L,"华为手机",2000)
+     * (4L,小米电脑,2000) (5L,"苹果手机",4000-) (6L,"金立手机",5000-)
+     *
+     *  要求1 要求查询是手机 价格大于1000
+     *        保留2个元素
+     *
+     *
+
+     */
+
+    @Test
+    public void test9(){
+
+        List<Product> products = Arrays.asList(
+                new Product(1L, "小米手机", 1000),
+                new Product(2L, "华为手机", 2000),
+                new Product(3L, "小米电脑", 2000),
+                new Product(4L, "苹果手机", 4000),
+                new Product(5L, "金立手机", 5000),
+                new Product(6L, "三星手机", 1500)
+        );
+        products.stream().
+                filter(e-> e.getName().contains("手机") && e.getPrice() >1000).
+                limit(2).
+                forEach(System.out::println);
+    }
+
+    /**
+     *  需求2  :  List<String> list {"a",'b","c","d","e","f","g"}
+     *   要求打印d 和 e
+     */
+    @Test
+    public void test10(){
+        List<String> list = Arrays.asList("a", "b", "c", "d", "e", "f", "g");
+        list.stream().skip(3).limit(2).forEach(System.out::println);
+    }
+
+    /**
+     *  已知条件 ArrayList ("abc","bcd","cc","ddd")
+     *  要求: 把结合当中每一个元素都变成大写
+     *  解决: 使用map (额外处理元素)
+     */
+    @Test
+    public void test11(){
+        List<String> list = Arrays.asList("abc", "bcd", "Cc", "ddd");
+        // function 函数式接口 有参有返回
+        list.stream().
+                map(e -> e.toUpperCase()).
+                forEach(System.out::println);
+    }
+
+    /**
+     * 需求: ArrayList ("abc","bcd","cc","ddd")
+     * 求出集合当中所有字符串长度
+     */
+    @Test
+    public void test12(){
+        List<String> list = Arrays.asList("abc", "bcd", "Cc", "ddd");
+        list.stream().map(e->e.length()).forEach(System.out::println);
+    }
+
+
+    /**
+     * 需求: 已知 集合[1,2,2,3,5,6,7,8,9]
+     * 要求将集合当中的每一个元素 加10   map
+     * 要求过滤出来 大于15的元素,并且不能有重复 filter distinct
+      */
+    @Test
+    public void test14(){
+        List<Integer> list = Arrays.asList(1, 2, 2, 3, 5, 6, 7, 8, 9);
+        list.stream().
+                map(e-> e+10).
+                filter(e-> e>15).
+                distinct().
+                forEach(System.out::println);
+    }
+
+    /**
+     * 需求: 已知有一个List<User> 集合  User id name age intergral
+     *      (1L,"zhang_san",10,10)  (1L,"li_si",20,20) (1L,"wang_wu",30,10)
+     *      要求过滤出来年龄大于18岁的
+     *      要求吧名字变成ZS   LS   WW
+     *      如果年龄大于21岁就加10积分
+     */
+    @Test
+    public void test15(){
+        List<User> list = Arrays.asList(
+                new User(1L, "zhang_san", 10, 10),
+                new User(1L, "li_si", 20, 20),
+                new User(1L, "wang_wu", 30, 10)
+        );
+        list.stream().
+                filter(e-> e.getAge()>18).
+                map(e->{
+                     //1 获取user 的name
+                     String name = e.getName();
+                     //2 按照_ 进行分割 [zhangsan,san]
+                     String[] arr = name.split("_");
+                     StringBuilder sb = new StringBuilder();
+                     for (String s : arr) {
+                         // zhangsan   san
+                         // z-第一个字母-> 大写    s - 第一个字母->大写
+                         sb.append(s.substring(0,1).toUpperCase());
+                     }
+                     //3 把名字重新设置到对象中
+                     e.setName(sb.toString());
+                     return e;
+                }).
+                map(e-> {
+                    if(e.getAge()>21){
+                        e.setIntegal(e.getIntegal()+10);
+                    }
+                    return e;
+                }).
+                forEach(System.out::println);
+    }
+
+    /**
+     * 需求: 已知 {1,2,4,6,3}
+     * 从小到大进行排序
+     *
+     * 如果我想要倒序如何操作呢?
+     * 默认是sorted 是从小到大进行排序的
+     * 有其他排序规则 那要调用有参构造器
+     * sorted(比较器)
+     */
+    @Test
+    public void test16(){
+        List<Integer> list = Arrays.asList(1, 2, 4, 6, 3);
+//        list.stream().sorted().forEach(System.out::println);
+//        list.stream().sorted(new Comparator<Integer>() {
+//            @Override
+//            public int compare(Integer o1, Integer o2) {
+//                return o2-o1;
+//            }
+//        }).forEach(System.out::println);
+        list.stream().sorted((o1,o2)-> o2-o1).forEach(System.out::println);
+    }
+
+    // 需求
+    //需求: 已知有一个List<User> 集合  User id name age intergral
+    //(1L,"zhang_san",10,10)  (1L,"li_si",20,30) (1L,"wang_wu",30,15) (1L,"wang_ba",30,20)
+
+    @Test
+    public void test(){
+        List<User> list = Arrays.asList(
+                new User(1L, "zhang_san", 10, 5),
+                new User(2L, "li_si", 20, 30),
+                new User(3L, "wang_wu", 30, 10),
+                new User(4L, "wang_ba", 30, 20)
+        );
+        // 1 要求1 按照积分降序
+        // 2 筛选出来名字带有wang
+        // 3 把小写wang变成大写的WANG
+        // 4 保留2 个
+        list.stream().
+                sorted((o1,o2)-> o2.getIntegal()-o1.getIntegal()).
+                filter(e-> e.getName().contains("wang")).
+                map(e->{
+                    String name = e.getName().toUpperCase();
+                    e.setName(name);
+                    return e;
+                }).
+                limit(1).
+                forEach(System.out::println);
+    }
+
+}

+ 12 - 0
src/main/java/com/sf/day24/_03_stream/dt/Product.java

@@ -0,0 +1,12 @@
+package com.sf.day24._03_stream.dt;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class Product {
+    private Long id;
+    private String name;
+    private Integer price;
+}

+ 13 - 0
src/main/java/com/sf/day24/_03_stream/dt/User.java

@@ -0,0 +1,13 @@
+package com.sf.day24._03_stream.dt;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class User {
+    private Long id;
+    private String name;
+    private Integer age;
+    private Integer integal;
+}