Bläddra i källkod

mybatis Plus task page 02

zhangxiaoyu 3 år sedan
förälder
incheckning
a85e0d2081

+ 34 - 0
src/main/java/com/example/Thread/Thread01.java

@@ -0,0 +1,34 @@
1
+package com.example.Thread;
2
+
3
+public class Thread01 {
4
+    public static void main(String[] args) throws InterruptedException {
5
+        Cat cat = new Cat();
6
+        cat.start();
7
+        for(int i=0;i<40;i++) {
8
+            Thread.sleep(1000);
9
+            System.out.println(i);
10
+        }
11
+        System.out.println(Thread.currentThread().getName());
12
+    }
13
+}
14
+
15
+class Cat extends Thread{
16
+    @Override
17
+    public void run() {
18
+        int i = 0;
19
+        while (true) {
20
+            i++;
21
+            try {
22
+                System.out.println("mmm");
23
+                System.out.println(Thread.currentThread().getName());
24
+                Thread.sleep(1000);
25
+            } catch (InterruptedException e) {
26
+                e.printStackTrace();
27
+            }
28
+            if(i==60) {
29
+                break;
30
+            }
31
+        }
32
+
33
+    }
34
+}

+ 57 - 0
src/main/java/com/example/Thread/ThreadRunnable.java

@@ -0,0 +1,57 @@
1
+package com.example.Thread;
2
+
3
+public class ThreadRunnable {
4
+    public static void main(String[] args) {
5
+        ThreadRun threadRun = new ThreadRun();
6
+        Thread thread = new Thread(threadRun);
7
+        thread.start();
8
+        System.out.println(Thread.currentThread().getName());
9
+          ProxyTest proxyTest = new ProxyTest();
10
+          ThreadProxy threadProxy = new ThreadProxy(proxyTest);
11
+          threadProxy.start();
12
+    }
13
+}
14
+class ThreadRun implements Runnable {
15
+    int i = 0;
16
+    @Override
17
+    public void run() {
18
+        while (true) {
19
+            i++;
20
+            System.out.println(i + Thread.currentThread().getName());
21
+            try {
22
+                Thread.sleep(1000);
23
+            } catch (InterruptedException e) {
24
+                e.printStackTrace();
25
+            }
26
+            if(i == 10) {
27
+                break;
28
+            }
29
+        }
30
+    }
31
+}
32
+class ProxyTest implements Runnable {
33
+    @Override
34
+    public void run() {
35
+        System.out.println("proxyTest---" + Thread.currentThread().getName());
36
+    }
37
+}
38
+// 代理模式,可以把它当成是Thread 类
39
+class ThreadProxy implements Runnable {
40
+    private Runnable target = null; //属性 类型是Runnable
41
+    @Override
42
+    public void run() {
43
+        if (target !=null) {
44
+            target.run();
45
+        }
46
+    }
47
+
48
+    public ThreadProxy(Runnable target) {
49
+        this.target = target;
50
+    }
51
+    public void start() {
52
+        start0();
53
+    }
54
+    public void start0() {
55
+        run();
56
+    }
57
+}

+ 12 - 0
src/main/java/com/example/demo/static07/Person.java

@@ -0,0 +1,12 @@
1
+package com.example.demo.static07;
2
+
3
+public class Person {
4
+    {
5
+        System.out.println("匿名代码块");
6
+    }
7
+    static  {
8
+        System.out.println(
9
+                "静态代码块"
10
+        );
11
+    }
12
+}

+ 7 - 0
src/main/java/com/example/demo/static07/Session.java

@@ -0,0 +1,7 @@
1
+package com.example.demo.static07;
2
+
3
+public class Session {
4
+
5
+    
6
+
7
+}

+ 21 - 0
src/main/java/com/example/demo/static07/Student.java

@@ -0,0 +1,21 @@
1
+package com.example.demo.static07;
2
+
3
+import java.util.Arrays;
4
+import java.util.Optional;
5
+
6
+public class Student {
7
+    private static int age = 1;
8
+    private double score;
9
+    private static String name;
10
+
11
+
12
+
13
+    public static void main(String[] args) {
14
+        Object s = new Student();
15
+        Person p = new Person();
16
+        String w = TestEnum.END_FORCE.getName();
17
+        System.out.println(w);
18
+        System.out.println(s instanceof Person);
19
+    }
20
+
21
+}

+ 33 - 0
src/main/java/com/example/demo/static07/TestEnum.java

@@ -0,0 +1,33 @@
1
+package com.example.demo.static07;
2
+
3
+public enum TestEnum {
4
+    NO_START("未开始", 1),
5
+    READY("准备中", 2),
6
+    PROCESSING("进行中", 3),
7
+    END_NO_FINISH("已结束领取未完成", 4),
8
+    END_YES_FINISH("已结束领取完成", 5),
9
+    END_FORCE("强制结束",6);
10
+
11
+    private String name;
12
+    private Integer value;
13
+    private TestEnum(String name, Integer value) {
14
+        this.name = name;
15
+        this.value = value;
16
+    }
17
+
18
+    public String getName() {
19
+        return name;
20
+    }
21
+
22
+    public void setName(String name) {
23
+        this.name = name;
24
+    }
25
+
26
+    public Integer getValue() {
27
+        return value;
28
+    }
29
+
30
+    public void setValue(Integer value) {
31
+        this.value = value;
32
+    }
33
+}

+ 20 - 0
src/main/java/com/example/javaIO/CopyFileStream.java

@@ -0,0 +1,20 @@
1
+package com.example.javaIO;
2
+
3
+import java.io.FileInputStream;
4
+import java.io.FileOutputStream;
5
+import java.io.IOException;
6
+
7
+public class CopyFileStream {
8
+    public static void main(String[] args) throws IOException {
9
+        FileInputStream fileInputStream = new FileInputStream("C:\\Users\\77179\\Desktop\\picture\\");
10
+        byte [] bytes = new byte[1024*1024];
11
+        FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\77179\\Desktop\\picture\\copy1.jpg");
12
+        int count;
13
+        while ((count=fileInputStream.read(bytes))!=-1) {
14
+
15
+            fileOutputStream.write(bytes,0,count);
16
+        }
17
+        fileOutputStream.close();
18
+        fileInputStream.close();
19
+    }
20
+}

+ 22 - 0
src/main/java/com/example/javaIO/fileInputStream.java

@@ -0,0 +1,22 @@
1
+package com.example.javaIO;
2
+
3
+import java.io.FileInputStream;
4
+import java.io.FileOutputStream;
5
+import java.io.IOException;
6
+
7
+public class fileInputStream {
8
+    public static void main(String[] args) throws IOException {
9
+        String filePath = "D:\\disk\\ttt.txt";
10
+        FileInputStream fs = new FileInputStream(filePath);
11
+        byte [] bytes = new byte[3];
12
+        int count;
13
+        while ((count=fs.read(bytes))!=-1) {
14
+            System.out.println(new String(bytes,0,count));
15
+        }
16
+        fs.close();
17
+        FileOutputStream fileOutputStream = new FileOutputStream("D:\\disk\\ttt1.txt",true);
18
+        String h = "hello";
19
+        fileOutputStream.write(h.getBytes());
20
+        fileOutputStream.close();
21
+    }
22
+}

+ 4 - 0
src/main/java/com/example/springbootdemo/entity/Device.java

@@ -29,4 +29,8 @@ public class Device implements Serializable {
29 29
     private String extraInfo;
30 30
     private String deviceSecret;
31 31
     private Long deviceType;
32
+    public void hi() {
33
+        System.out.println("hi111");
34
+    }
35
+
32 36
 }

+ 0 - 2
src/main/java/com/example/springbootdemo/service/GoodsBindsShoesLastService.java

@@ -1,7 +1,5 @@
1 1
 package com.example.springbootdemo.service;
2 2
 
3
-import java.util.ArrayList;
4
-import java.util.Collection;
5 3
 import java.util.List;
6 4
 
7 5
 /**

+ 12 - 1
src/main/java/com/example/springbootdemo/zxyTeST/getProperties.java

@@ -1,14 +1,25 @@
1 1
 package com.example.springbootdemo.zxyTeST;
2 2
 
3 3
 import com.example.springbootdemo.zxyTeST.Enum.SystemType;
4
+import org.springframework.beans.factory.annotation.Autowired;
4 5
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 6
 
6 7
 
7 8
 //@SpringBootApplication
8 9
 public class getProperties {
9 10
     public static void main(String[] args){
11
+        int [] arr = {1,2,3};
12
+        int [] arr2 = new int[arr.length];
13
+        int [] a3 = arr;
14
+
15
+        for (int i1 = 0;i1<arr.length; i1++) {
16
+            arr2[i1] = arr[i1];
17
+        }
18
+        System.out.println(arr);
19
+        System.out.println(a3);
20
+        System.out.println(arr2);
21
+        for (int i = 0; i< SystemType.values().length; i++) {
10 22
 
11
-      for (int i = 0; i< SystemType.values().length; i++) {
12 23
           System.out.println("索引"+SystemType.values()[i].ordinal()+",值:"+SystemType.values()[i]);
13 24
           System.out.println("值"+ SystemType.values()[i].getSystemName());
14 25
       }

+ 2 - 0
src/main/java/re.properties

@@ -0,0 +1,2 @@
1
+classfull=com.example.springbootdemo.entity.Device
2
+method=hi

+ 24 - 0
src/main/java/reflaction/question/testReflaction.java

@@ -0,0 +1,24 @@
1
+package reflaction.question;
2
+
3
+import com.example.springbootdemo.entity.Device;
4
+
5
+import java.io.FileInputStream;
6
+import java.io.IOException;
7
+import java.lang.reflect.InvocationTargetException;
8
+import java.lang.reflect.Method;
9
+import java.util.Properties;
10
+
11
+public class testReflaction {
12
+    public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
13
+        Properties properties = new Properties();
14
+        properties.load(new FileInputStream("src\\main\\java\\re.properties"));
15
+        String classPath = properties.get("classfull").toString();
16
+        String methods = properties.get("method").toString();
17
+        Class cls = Class.forName(classPath);
18
+        Object o = cls.newInstance();
19
+        Method method = cls.getMethod(methods);
20
+        method.invoke(o);
21
+        Runtime runtime = Runtime.getRuntime();
22
+        System.out.println(runtime.availableProcessors());
23
+    }
24
+}

+ 3 - 1
src/main/resources/application.yml

@@ -18,4 +18,6 @@ spring:
18 18
   jpa:
19 19
     database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
20 20
     open-in-view: false
21
-
21
+mybatis-plus:
22
+  configuration:
23
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

+ 14 - 0
src/test/java/com/example/springbootdemo/SpringbootdemoApplicationTests.java

@@ -1,5 +1,6 @@
1 1
 package com.example.springbootdemo;
2 2
 
3
+import jdk.nashorn.internal.ir.annotations.Ignore;
3 4
 import lombok.extern.slf4j.Slf4j;
4 5
 import org.junit.jupiter.api.Test;
5 6
 import org.springframework.beans.factory.annotation.Autowired;
@@ -10,6 +11,7 @@ import javax.sql.DataSource;
10 11
 
11 12
 @Slf4j
12 13
 @SpringBootTest
14
+@Ignore
13 15
 class SpringbootdemoApplicationTests {
14 16
     @Autowired
15 17
     JdbcTemplate jdbcTemplate;
@@ -21,5 +23,17 @@ class SpringbootdemoApplicationTests {
21 23
         log.info("记录 all count {}",count);
22 24
         log.info("数据源类型 {}",dataSource.getClass());
23 25
     }
26
+    @Test
27
+     void testEquals() {
28
+        Integer i = 128;
29
+        Integer i1 = 128;
30
+        System.out.println(i == i1);
31
+        System.out.println(i.equals(i1));
32
+    }
33
+    @Test
34
+    void getCPUNum() {
35
+        Runtime runtime = Runtime.getRuntime();
36
+        System.out.println(runtime.availableProcessors());
37
+    }
24 38
 
25 39
 }