From d861c02d8ba5923eba27cba547e41330b331de9e Mon Sep 17 00:00:00 2001 From: "xuehui.zhu" Date: Mon, 16 Nov 2020 18:58:31 +0800 Subject: [PATCH 1/6] homework 0902 --- .../src/main/java/homework0902/0902.md | 1 + .../main/java/homework0902/Homework0902.java | 31 +++++++++++++++++++ .../java/homework0902/pojo/StuConfig.java | 13 ++++++++ .../main/java/homework0902/pojo/Student.java | 8 +++++ .../main/java/homework0902/pojo/Student1.java | 21 +++++++++++++ .../main/java/homework0902/pojo/Student2.java | 25 +++++++++++++++ .../main/resources/hwApplicationContext.xml | 19 ++++++++++++ 7 files changed, 118 insertions(+) create mode 100644 04fx/spring01/src/main/java/homework0902/0902.md create mode 100644 04fx/spring01/src/main/java/homework0902/Homework0902.java create mode 100644 04fx/spring01/src/main/java/homework0902/pojo/StuConfig.java create mode 100644 04fx/spring01/src/main/java/homework0902/pojo/Student.java create mode 100644 04fx/spring01/src/main/java/homework0902/pojo/Student1.java create mode 100644 04fx/spring01/src/main/java/homework0902/pojo/Student2.java create mode 100644 04fx/spring01/src/main/resources/hwApplicationContext.xml diff --git a/04fx/spring01/src/main/java/homework0902/0902.md b/04fx/spring01/src/main/java/homework0902/0902.md new file mode 100644 index 00000000..5c1fc1fb --- /dev/null +++ b/04fx/spring01/src/main/java/homework0902/0902.md @@ -0,0 +1 @@ +写代码实现Spring Bean的装配,方式越多越好(XML、Annotation都可以) \ No newline at end of file diff --git a/04fx/spring01/src/main/java/homework0902/Homework0902.java b/04fx/spring01/src/main/java/homework0902/Homework0902.java new file mode 100644 index 00000000..5819fe22 --- /dev/null +++ b/04fx/spring01/src/main/java/homework0902/Homework0902.java @@ -0,0 +1,31 @@ +package homework0902; + +import homework0902.pojo.Student; +import homework0902.pojo.Student1; +import homework0902.pojo.Student2; +import homework0902.pojo.StuConfig; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class Homework0902 { + public static void main(String[] args) { + ApplicationContext applicationContext = new ClassPathXmlApplicationContext("hwApplicationContext.xml"); + ApplicationContext configContext = new AnnotationConfigApplicationContext(StuConfig.class); + + Student student1 = (Student1) applicationContext.getBean("student1"); + System.out.println("方法1:" + student1.toString()); + + Student student2 = (Student2) applicationContext.getBean("student2"); + System.out.println("方法2:" + student2.toString()); + + Student student3 = applicationContext.getBean(Student2.class); + System.out.println("方法3:" + student3.toString()); + + Student student4 = (Student) configContext.getBean("stu1"); + System.out.println("方法4:" + student4.toString()); + + } + + +} diff --git a/04fx/spring01/src/main/java/homework0902/pojo/StuConfig.java b/04fx/spring01/src/main/java/homework0902/pojo/StuConfig.java new file mode 100644 index 00000000..9e0fee4f --- /dev/null +++ b/04fx/spring01/src/main/java/homework0902/pojo/StuConfig.java @@ -0,0 +1,13 @@ +package homework0902.pojo; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class StuConfig{ + @Bean(name = "stu1") + public Student getStudent() { + return new Student1(3,"xiyuan3"); + } + +} diff --git a/04fx/spring01/src/main/java/homework0902/pojo/Student.java b/04fx/spring01/src/main/java/homework0902/pojo/Student.java new file mode 100644 index 00000000..17d1bc97 --- /dev/null +++ b/04fx/spring01/src/main/java/homework0902/pojo/Student.java @@ -0,0 +1,8 @@ +package homework0902.pojo; + + +import java.io.Serializable; + +public interface Student extends Serializable { + void dingdo(); +} diff --git a/04fx/spring01/src/main/java/homework0902/pojo/Student1.java b/04fx/spring01/src/main/java/homework0902/pojo/Student1.java new file mode 100644 index 00000000..3a4e8feb --- /dev/null +++ b/04fx/spring01/src/main/java/homework0902/pojo/Student1.java @@ -0,0 +1,21 @@ +package homework0902.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class Student1 implements Student { + + private int id; + private String name; + + @Override + public void dingdo() { + System.out.println("Student1"); + } +} diff --git a/04fx/spring01/src/main/java/homework0902/pojo/Student2.java b/04fx/spring01/src/main/java/homework0902/pojo/Student2.java new file mode 100644 index 00000000..847dc745 --- /dev/null +++ b/04fx/spring01/src/main/java/homework0902/pojo/Student2.java @@ -0,0 +1,25 @@ +package homework0902.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString +@Component(value = "student2") +public class Student2 implements Student { + @Value("002") + private int id; + @Value("西元2") + private String name; + + @Override + public void dingdo() { + System.out.println("Student2"); + } +} diff --git a/04fx/spring01/src/main/resources/hwApplicationContext.xml b/04fx/spring01/src/main/resources/hwApplicationContext.xml new file mode 100644 index 00000000..43dc3e20 --- /dev/null +++ b/04fx/spring01/src/main/resources/hwApplicationContext.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + \ No newline at end of file From aa6a782ea0054c2e5ef4fe83fb04f8aeffec19ac Mon Sep 17 00:00:00 2001 From: "xuehui.zhu" Date: Tue, 17 Nov 2020 19:44:39 +0800 Subject: [PATCH 2/6] =?UTF-8?q?11.17=20Starter=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 04fx/homework1003/pom.xml | 40 ++++++++++++ .../src/main/java/config/StuConfigration.java | 22 +++++++ .../src/main/java/pojo/Student.java | 25 ++++++++ .../main/resources/META-INF/spring.factories | 1 + .../io/kimmking/springjms/SendService.java | 6 +- .../target/classes/applicationContext.xml | 61 +++++++++++++++++++ .../target/classes/hwApplicationContext.xml | 19 ++++++ 04fx/spring01/target/classes/log4j.xml | 27 ++++++++ .../target/classes/springjms-receiver.xml | 36 +++++++++++ .../target/classes/springjms-sender.xml | 25 ++++++++ 04fx/springboot01/pom.xml | 6 ++ .../src/main/java/homework1003/1003.md | 1 + .../SpringBoot1003Application.java | 11 ++++ .../main/java/homework1003/web/WebPage.java | 23 +++++++ .../src/main/resources/application.yml | 7 ++- .../target/classes/application.yml | 53 ++++++++++++++++ 16 files changed, 360 insertions(+), 3 deletions(-) create mode 100644 04fx/homework1003/pom.xml create mode 100644 04fx/homework1003/src/main/java/config/StuConfigration.java create mode 100644 04fx/homework1003/src/main/java/pojo/Student.java create mode 100644 04fx/homework1003/src/main/resources/META-INF/spring.factories create mode 100644 04fx/spring01/target/classes/applicationContext.xml create mode 100644 04fx/spring01/target/classes/hwApplicationContext.xml create mode 100644 04fx/spring01/target/classes/log4j.xml create mode 100644 04fx/spring01/target/classes/springjms-receiver.xml create mode 100644 04fx/spring01/target/classes/springjms-sender.xml create mode 100644 04fx/springboot01/src/main/java/homework1003/1003.md create mode 100644 04fx/springboot01/src/main/java/homework1003/SpringBoot1003Application.java create mode 100644 04fx/springboot01/src/main/java/homework1003/web/WebPage.java create mode 100644 04fx/springboot01/target/classes/application.yml diff --git a/04fx/homework1003/pom.xml b/04fx/homework1003/pom.xml new file mode 100644 index 00000000..1ad8f24d --- /dev/null +++ b/04fx/homework1003/pom.xml @@ -0,0 +1,40 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.0.9.RELEASE + + + + len.xiyuan.spring.boot + len-xiyuan-spring-boot-starter + 0.0.1-SNAPSHOT + jar + Demo project for Spring Boot Starter + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-autoconfigure + + + org.springframework.boot + spring-boot-configuration-processor + + + io.kimmking + springboot01 + 0.0.1-SNAPSHOT + compile + + + + + diff --git a/04fx/homework1003/src/main/java/config/StuConfigration.java b/04fx/homework1003/src/main/java/config/StuConfigration.java new file mode 100644 index 00000000..8ce271ad --- /dev/null +++ b/04fx/homework1003/src/main/java/config/StuConfigration.java @@ -0,0 +1,22 @@ +package config; + +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import pojo.Student; + +import java.util.HashMap; +import java.util.Map; + +@Configuration +@EnableConfigurationProperties(Student.class) +public class StuConfigration { + @Bean + public Map getBean(Student student){ + Map result = new HashMap(); + result.put("ID",student.getId()); + result.put("name",student.getName()); + return result; + } + +} diff --git a/04fx/homework1003/src/main/java/pojo/Student.java b/04fx/homework1003/src/main/java/pojo/Student.java new file mode 100644 index 00000000..8ed73c82 --- /dev/null +++ b/04fx/homework1003/src/main/java/pojo/Student.java @@ -0,0 +1,25 @@ +package pojo; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "diy.stu") +public class Student { + private int id; + private String name; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/04fx/homework1003/src/main/resources/META-INF/spring.factories b/04fx/homework1003/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..751af5d3 --- /dev/null +++ b/04fx/homework1003/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=config.StuConfigration diff --git a/04fx/spring01/src/main/java/io/kimmking/springjms/SendService.java b/04fx/spring01/src/main/java/io/kimmking/springjms/SendService.java index 1c09e4c5..bc3c7625 100644 --- a/04fx/spring01/src/main/java/io/kimmking/springjms/SendService.java +++ b/04fx/spring01/src/main/java/io/kimmking/springjms/SendService.java @@ -1,6 +1,7 @@ package io.kimmking.springjms; import io.kimmking.spring01.Student; +import org.apache.activemq.command.ActiveMQQueue; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.core.MessageCreator; @@ -14,9 +15,10 @@ public class SendService { @Autowired JmsTemplate jmsTemplate; - + @Autowired + ActiveMQQueue queue; public void send(final Student user) { - jmsTemplate.send("test.queue", new MessageCreator() { + jmsTemplate.send(queue, new MessageCreator() { public Message createMessage(Session session) throws JMSException { return session.createObjectMessage(user); diff --git a/04fx/spring01/target/classes/applicationContext.xml b/04fx/spring01/target/classes/applicationContext.xml new file mode 100644 index 00000000..985a106e --- /dev/null +++ b/04fx/spring01/target/classes/applicationContext.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/04fx/spring01/target/classes/hwApplicationContext.xml b/04fx/spring01/target/classes/hwApplicationContext.xml new file mode 100644 index 00000000..d4e5ed13 --- /dev/null +++ b/04fx/spring01/target/classes/hwApplicationContext.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/04fx/spring01/target/classes/log4j.xml b/04fx/spring01/target/classes/log4j.xml new file mode 100644 index 00000000..efc1f4f6 --- /dev/null +++ b/04fx/spring01/target/classes/log4j.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/04fx/spring01/target/classes/springjms-receiver.xml b/04fx/spring01/target/classes/springjms-receiver.xml new file mode 100644 index 00000000..e0d9fbc6 --- /dev/null +++ b/04fx/spring01/target/classes/springjms-receiver.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/04fx/spring01/target/classes/springjms-sender.xml b/04fx/spring01/target/classes/springjms-sender.xml new file mode 100644 index 00000000..119ec07a --- /dev/null +++ b/04fx/spring01/target/classes/springjms-sender.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/04fx/springboot01/pom.xml b/04fx/springboot01/pom.xml index 93d83574..51aabd22 100644 --- a/04fx/springboot01/pom.xml +++ b/04fx/springboot01/pom.xml @@ -43,6 +43,12 @@ org.springframework.boot spring-boot-starter-data-mongodb + + + len.xiyuan.spring.boot + len-xiyuan-spring-boot-starter + 0.0.1-SNAPSHOT + diff --git a/04fx/springboot01/src/main/java/homework1003/1003.md b/04fx/springboot01/src/main/java/homework1003/1003.md new file mode 100644 index 00000000..2d9c3b48 --- /dev/null +++ b/04fx/springboot01/src/main/java/homework1003/1003.md @@ -0,0 +1 @@ +给前面课程提供的 Student/Klass/School 实现自动配置和 Starter. \ No newline at end of file diff --git a/04fx/springboot01/src/main/java/homework1003/SpringBoot1003Application.java b/04fx/springboot01/src/main/java/homework1003/SpringBoot1003Application.java new file mode 100644 index 00000000..108efaf5 --- /dev/null +++ b/04fx/springboot01/src/main/java/homework1003/SpringBoot1003Application.java @@ -0,0 +1,11 @@ +package homework1003; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication(scanBasePackages = {"homework1003"}) +public class SpringBoot1003Application { + public static void main(String[] args) { + SpringApplication.run(SpringBoot1003Application.class, args); + } +} diff --git a/04fx/springboot01/src/main/java/homework1003/web/WebPage.java b/04fx/springboot01/src/main/java/homework1003/web/WebPage.java new file mode 100644 index 00000000..1e91f176 --- /dev/null +++ b/04fx/springboot01/src/main/java/homework1003/web/WebPage.java @@ -0,0 +1,23 @@ +package homework1003.web; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +public class WebPage { + + @RequestMapping("/test") + @ResponseBody + public String hello() { + return "hello SpringBoot"; + } + + @RequestMapping("/myStarter") + @ResponseBody + public String xiyuan() { + return ""; + } +} diff --git a/04fx/springboot01/src/main/resources/application.yml b/04fx/springboot01/src/main/resources/application.yml index f18263ac..0af33ee8 100644 --- a/04fx/springboot01/src/main/resources/application.yml +++ b/04fx/springboot01/src/main/resources/application.yml @@ -1,5 +1,10 @@ server: - port: 8080 + port: 8081 + +diy: + stu: + id: 1 + name: xiyaun spring: activemq: diff --git a/04fx/springboot01/target/classes/application.yml b/04fx/springboot01/target/classes/application.yml new file mode 100644 index 00000000..4b7302f1 --- /dev/null +++ b/04fx/springboot01/target/classes/application.yml @@ -0,0 +1,53 @@ +server: + port: 8081 + +spring: + activemq: + broker-url: tcp://127.0.0.1:61616 + user: admin + password: admin + close-timeout: 15s # 在考虑结束之前等待的时间 + in-memory: true # 默认代理URL是否应该在内存中。如果指定了显式代理,则忽略此值。 + non-blocking-redelivery: false # 是否在回滚回滚消息之前停止消息传递。这意味着当启用此命令时,消息顺序不会被保留。 + send-timeout: 0 # 等待消息发送响应的时间。设置为0等待永远。 + queue-name: active.queue + topic-name: active.topic.name.model + packages: + trust-all: true #不配置此项,会报错 + pool: + enabled: true + max-connections: 10 #连接池最大连接数 + idle-timeout: 30000 #空闲的连接过期时间,默认为30秒 + data: + mongodb: + uri: mongodb://localhost:27017/mydb + +# jms: +# pub-sub-domain: true #默认情况下activemq提供的是queue模式,若要使用topic模式需要配置下面配置 + +# 是否信任所有包 +#spring.activemq.packages.trust-all= +# 要信任的特定包的逗号分隔列表(当不信任所有包时) +#spring.activemq.packages.trusted= +# 当连接请求和池满时是否阻塞。设置false会抛“JMSException异常”。 +#spring.activemq.pool.block-if-full=true +# 如果池仍然满,则在抛出异常前阻塞时间。 +#spring.activemq.pool.block-if-full-timeout=-1ms +# 是否在启动时创建连接。可以在启动时用于加热池。 +#spring.activemq.pool.create-connection-on-startup=true +# 是否用Pooledconnectionfactory代替普通的ConnectionFactory。 +#spring.activemq.pool.enabled=false +# 连接过期超时。 +#spring.activemq.pool.expiry-timeout=0ms +# 连接空闲超时 +#spring.activemq.pool.idle-timeout=30s +# 连接池最大连接数 +#spring.activemq.pool.max-connections=1 +# 每个连接的有效会话的最大数目。 +#spring.activemq.pool.maximum-active-session-per-connection=500 +# 当有"JMSException"时尝试重新连接 +#spring.activemq.pool.reconnect-on-exception=true +# 在空闲连接清除线程之间运行的时间。当为负数时,没有空闲连接驱逐线程运行。 +#spring.activemq.pool.time-between-expiration-check=-1ms +# 是否只使用一个MessageProducer +#spring.activemq.pool.use-anonymous-producers=true \ No newline at end of file From ca5f7f14840155dd43217df3168a9116d111aaa9 Mon Sep 17 00:00:00 2001 From: "xuehui.zhu" Date: Wed, 18 Nov 2020 20:52:12 +0800 Subject: [PATCH 3/6] =?UTF-8?q?11.17=20Starter=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/java0/conc0303/Homework03.java | 2 +- .../java/java0/conc0303/HomeworkDemo1.java | 217 ++++++++++++++++++ 04fx/homework1003/pom.xml | 16 +- .../spring-configuration-metadata.json | 23 ++ .../target/classes/META-INF/spring.factories | 1 + .../target/maven-archiver/pom.properties | 4 + .../compile/default-compile/createdFiles.lst | 3 + .../compile/default-compile/inputFiles.lst | 2 + .../default-testCompile/inputFiles.lst | 0 .../test-starter-0.0.1-SNAPSHOT.jar.original | Bin 0 -> 4010 bytes 04fx/jdbc-demo/pom.xml | 65 ++++++ .../java/com/jeekbang/jdbc/H2JdbcDemo.java | 69 ++++++ .../java/com/jeekbang/jdbc/H2JdbcDemo2.java | 89 +++++++ .../java/com/jeekbang/jdbc/HikariDemo.java | 94 ++++++++ .../main/java/com/jeekbang/jdbc/Student.java | 30 +++ .../src/main/resources/application.xml | 19 ++ .../src/main/resources/sql/h2-data.sql | 2 + .../src/main/resources/sql/h2-schema.sql | 8 + 04fx/springboot01/pom.xml | 2 +- .../SpringBoot1003Application.java | 3 +- .../main/java/homework1003/web/WebPage.java | 1 + .../src/main/resources/application.yml | 2 +- 22 files changed, 641 insertions(+), 11 deletions(-) create mode 100644 03concurrency/0301/src/main/java/java0/conc0303/HomeworkDemo1.java create mode 100644 04fx/homework1003/target/classes/META-INF/spring-configuration-metadata.json create mode 100644 04fx/homework1003/target/classes/META-INF/spring.factories create mode 100644 04fx/homework1003/target/maven-archiver/pom.properties create mode 100644 04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst create mode 100644 04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst create mode 100644 04fx/homework1003/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst create mode 100644 04fx/homework1003/target/test-starter-0.0.1-SNAPSHOT.jar.original create mode 100644 04fx/jdbc-demo/pom.xml create mode 100644 04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/H2JdbcDemo.java create mode 100644 04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/H2JdbcDemo2.java create mode 100644 04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/HikariDemo.java create mode 100644 04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/Student.java create mode 100644 04fx/jdbc-demo/src/main/resources/application.xml create mode 100644 04fx/jdbc-demo/src/main/resources/sql/h2-data.sql create mode 100644 04fx/jdbc-demo/src/main/resources/sql/h2-schema.sql diff --git a/03concurrency/0301/src/main/java/java0/conc0303/Homework03.java b/03concurrency/0301/src/main/java/java0/conc0303/Homework03.java index dd7d4375..ed592a98 100644 --- a/03concurrency/0301/src/main/java/java0/conc0303/Homework03.java +++ b/03concurrency/0301/src/main/java/java0/conc0303/Homework03.java @@ -27,7 +27,7 @@ public static void main(String[] args) { // 然后退出main线程 } - private static int sum() { + static int sum() { return fibo(36); } diff --git a/03concurrency/0301/src/main/java/java0/conc0303/HomeworkDemo1.java b/03concurrency/0301/src/main/java/java0/conc0303/HomeworkDemo1.java new file mode 100644 index 00000000..62c05ae3 --- /dev/null +++ b/03concurrency/0301/src/main/java/java0/conc0303/HomeworkDemo1.java @@ -0,0 +1,217 @@ +package java0.conc0303; + +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; +import java.util.function.Supplier; + +public class HomeworkDemo1 { + public static void main(String[] args) { + +// long start = System.currentTimeMillis(); +// // 在这里创建一个线程或线程池, +// // 异步执行 下面方法 +// +// int result = sum(); //这是得到的返回值 +// +// // 确保 拿到result 并输出 +// System.out.println("异步计算结果为:" + result); +// +// System.out.println("使用时间:" + (System.currentTimeMillis() - start) + " ms"); +// +// // 然后退出main线程 + run(bySleep, "bySleep"); + + run(byJoin, "byJoin"); + + run(byCAS, "byCAS"); + + run(byLock, "byLock"); + + run(byObjectNotify, "byObjectNotify"); + + run(byCountDownLatch, "byCountDownLatch"); + + run(byFuture, "byFuture"); + + run(byFutureTask, "byFutureTask"); + + run(byCompletableFuture, "byCompletableFuture"); + } + + public static void run(Supplier supplier, String type) { + System.out.println(type); + long start = System.currentTimeMillis(); + // 在这里创建一个线程或线程池, + // 异步执行 下面方法 + // 这是得到的返回值 + int result = supplier.get(); + + // 确保 拿到result 并输出 + System.out.print("异步计算结果为:" + result + " "); + + System.out.println("使用时间:" + (System.currentTimeMillis() - start) + " ms"); + + // 然后退出main线程 + } + + private static int sum() { + return fibo(36); + } + + private static int fibo(int a) { + if (a < 2) { + return 1; + } + return fibo(a - 1) + fibo(a - 2); + } + + private static final Supplier bySleep = () -> { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + AtomicInteger result = new AtomicInteger(); + executorService.execute(() -> result.set(sum())); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + executorService.shutdown(); + return result.get(); + }; + + private static final Supplier byJoin = () -> { + AtomicInteger result = new AtomicInteger(); + Thread thread = new Thread(() -> result.set(sum())); + thread.start(); + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return result.get(); + }; + + public static final Supplier byCAS = () -> { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + AtomicBoolean isDone = new AtomicBoolean(false); + AtomicInteger result = new AtomicInteger(); + executorService.execute(() -> { + result.set(sum()); + isDone.set(true); + }); + while (!isDone.get()) { + } + executorService.shutdown(); + return result.get(); + }; + + public static final Supplier byLock = () -> { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + Lock lock = new ReentrantLock(); + Condition condition = lock.newCondition(); + AtomicInteger result = new AtomicInteger(); + AtomicBoolean isDone = new AtomicBoolean(false); + executorService.execute(() -> { + lock.lock(); + try { + result.set(sum()); + isDone.set(true); + condition.signalAll(); + } finally { + lock.unlock(); + } + }); + + lock.lock(); + try { + while (!isDone.get()) { + condition.await(); + } + condition.signalAll(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + lock.unlock(); + } + executorService.shutdown(); + return result.get(); + }; + + public static final Supplier byObjectNotify = () -> { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + Object object = new Object(); + AtomicInteger result = new AtomicInteger(); + AtomicBoolean isDone = new AtomicBoolean(false); + executorService.execute(() -> { + synchronized (object) { + result.set(sum()); + isDone.set(true); + object.notifyAll(); + } + }); + + synchronized (object) { + while (!isDone.get()) { + try { + object.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + executorService.shutdown(); + return result.get(); + }; + + public static final Supplier byCountDownLatch = () -> { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + CountDownLatch countDownLatch = new CountDownLatch(1); + AtomicInteger result = new AtomicInteger(); + executorService.execute(() -> { + result.set(sum()); + countDownLatch.countDown(); + }); + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + executorService.shutdown(); + return result.get(); + }; + + private static final Supplier byFuture = () -> { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + Future future = executorService.submit(()->sum()); + Integer result = null; + try { + result = future.get(); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + executorService.shutdown(); + return result; + }; + + private static final Supplier byFutureTask = () -> { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + FutureTask futureTask = new FutureTask<>(Homework03::sum); + executorService.submit(futureTask); + Integer result = null; + try { + result = futureTask.get(); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + executorService.shutdown(); + return result; + }; + + public static final Supplier byCompletableFuture = () -> { + CompletableFuture completableFuture = CompletableFuture.supplyAsync(Homework03::sum); + return completableFuture.join(); + }; +} diff --git a/04fx/homework1003/pom.xml b/04fx/homework1003/pom.xml index 1ad8f24d..a24054e8 100644 --- a/04fx/homework1003/pom.xml +++ b/04fx/homework1003/pom.xml @@ -10,7 +10,7 @@ len.xiyuan.spring.boot - len-xiyuan-spring-boot-starter + test-starter 0.0.1-SNAPSHOT jar Demo project for Spring Boot Starter @@ -28,13 +28,15 @@ org.springframework.boot spring-boot-configuration-processor - - io.kimmking - springboot01 - 0.0.1-SNAPSHOT - compile - + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/04fx/homework1003/target/classes/META-INF/spring-configuration-metadata.json b/04fx/homework1003/target/classes/META-INF/spring-configuration-metadata.json new file mode 100644 index 00000000..fcc25683 --- /dev/null +++ b/04fx/homework1003/target/classes/META-INF/spring-configuration-metadata.json @@ -0,0 +1,23 @@ +{ + "hints": [], + "groups": [ + { + "sourceType": "pojo.Student", + "name": "diy.stu", + "type": "pojo.Student" + } + ], + "properties": [ + { + "sourceType": "pojo.Student", + "defaultValue": 0, + "name": "diy.stu.id", + "type": "java.lang.Integer" + }, + { + "sourceType": "pojo.Student", + "name": "diy.stu.name", + "type": "java.lang.String" + } + ] +} \ No newline at end of file diff --git a/04fx/homework1003/target/classes/META-INF/spring.factories b/04fx/homework1003/target/classes/META-INF/spring.factories new file mode 100644 index 00000000..751af5d3 --- /dev/null +++ b/04fx/homework1003/target/classes/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=config.StuConfigration diff --git a/04fx/homework1003/target/maven-archiver/pom.properties b/04fx/homework1003/target/maven-archiver/pom.properties new file mode 100644 index 00000000..e4cf11a2 --- /dev/null +++ b/04fx/homework1003/target/maven-archiver/pom.properties @@ -0,0 +1,4 @@ +#Created by Apache Maven 3.6.3 +version=0.0.1-SNAPSHOT +groupId=len.xiyuan.spring.boot +artifactId=test-starter diff --git a/04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 00000000..852f78cf --- /dev/null +++ b/04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,3 @@ +META-INF\spring-configuration-metadata.json +pojo\Student.class +config\StuConfigration.class diff --git a/04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 00000000..84c497d2 --- /dev/null +++ b/04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,2 @@ +D:\workspace\IdeaProject\JavaCourseCodes\04fx\homework1003\src\main\java\config\StuConfigration.java +D:\workspace\IdeaProject\JavaCourseCodes\04fx\homework1003\src\main\java\pojo\Student.java diff --git a/04fx/homework1003/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/04fx/homework1003/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 00000000..e69de29b diff --git a/04fx/homework1003/target/test-starter-0.0.1-SNAPSHOT.jar.original b/04fx/homework1003/target/test-starter-0.0.1-SNAPSHOT.jar.original new file mode 100644 index 0000000000000000000000000000000000000000..3527e9a43b867ac542b77fc25ae7ad4b0f7b67e3 GIT binary patch literal 4010 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 VMzI3nf + + + org.springframework.boot + spring-boot-starter-parent + 2.0.9.RELEASE + + + 4.0.0 + + jdbc-demo + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + + + + + + org.springframework + spring-jdbc + 5.1.10.RELEASE + + + + com.h2database + h2 + 1.4.197 + runtime + + + + org.springframework + spring-core + 5.1.10.RELEASE + + + org.springframework + spring-beans + 5.1.10.RELEASE + + + org.springframework + spring-context + 5.1.10.RELEASE + + + + + com.zaxxer + HikariCP + 3.4.5 + + + \ No newline at end of file diff --git a/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/H2JdbcDemo.java b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/H2JdbcDemo.java new file mode 100644 index 00000000..3db0ea7f --- /dev/null +++ b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/H2JdbcDemo.java @@ -0,0 +1,69 @@ +package com.jeekbang.jdbc; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + + +/** + * 使用 JDBC 原生接口,实现数据库的增删改查操作 + */ +public class H2JdbcDemo { + public static void main(String[] args) throws ClassNotFoundException { + ApplicationContext context = new ClassPathXmlApplicationContext("classpath:application.xml"); + jdbc(); + } + + public static void jdbc() { + String url = "jdbc:h2:mem:dataSource;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false"; + String username = "sa"; + String password = ""; + try { + final Connection connection = DriverManager.getConnection(url, username, password); + // 查询 + find(connection); + + // 新增 + String sql = "insert into student(name) values('测试')"; + update(connection, sql); + find(connection); + + // 修改 + sql = "update student set name='测试-修改' where name='测试'"; + update(connection, sql); + find(connection); + + // 删除 + sql = "delete from student where name='测试-修改'"; + update(connection, sql); + find(connection); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private static void find(Connection connection) throws SQLException { + final Statement statement = connection.createStatement(); + statement.execute("select * from student"); + final ResultSet resultSet = statement.getResultSet(); + List students = new ArrayList<>(); + while (resultSet.next()){ + final int id = resultSet.getInt("id"); + final String name = resultSet.getString("name"); + Student student = new Student(); + student.setId(id); + student.setName(name); + students.add(student); + } + System.out.println(students); + } + + private static void update(Connection connection, String sql) throws SQLException { + final Statement statement = connection.createStatement(); + statement.executeUpdate(sql); + } +} diff --git a/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/H2JdbcDemo2.java b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/H2JdbcDemo2.java new file mode 100644 index 00000000..18548d75 --- /dev/null +++ b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/H2JdbcDemo2.java @@ -0,0 +1,89 @@ +package com.jeekbang.jdbc; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + + +/** + * 使用事务,PrepareStatement 方式,批处理方式 + */ +public class H2JdbcDemo2 { + public static void main(String[] args) throws ClassNotFoundException { + ApplicationContext context = new ClassPathXmlApplicationContext("classpath:application.xml"); + jdbc(); + } + + public static void jdbc() { + String url = "jdbc:h2:mem:dataSource;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false"; + String username = "sa"; + String password = ""; + try { + final Connection connection = DriverManager.getConnection(url, username, password); + // 查询 + find(connection); + + // 新增 + add(connection); + find(connection); + + // 修改 + update(connection); + find(connection); + + // 删除 + delete(connection); + find(connection); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private static void find(Connection connection) throws SQLException { + final PreparedStatement statement = connection.prepareStatement("select * from student"); + final ResultSet resultSet = statement.executeQuery(); + List students = new ArrayList<>(); + while (resultSet.next()) { + final int id = resultSet.getInt("id"); + final String name = resultSet.getString("name"); + Student student = new Student(); + student.setId(id); + student.setName(name); + students.add(student); + } + System.out.println(students); + } + + private static void add(Connection connection) throws SQLException { + String sql = "insert into student(name) values(?)"; + connection.setAutoCommit(false); + final PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, "测试 - add"); + preparedStatement.executeUpdate(); + connection.commit(); + } + + + private static void update(Connection connection) throws SQLException { + String sql = "update student set name=? where name=?"; + connection.setAutoCommit(false); + final PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, "测试 - update"); + preparedStatement.setString(2, "测试 - add"); + preparedStatement.executeUpdate(); + connection.commit(); + } + + private static void delete(Connection connection) throws SQLException { + String sql = "delete from student where name=?"; + connection.setAutoCommit(false); + final PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, "测试 - update"); + preparedStatement.executeUpdate(); + connection.commit(); + } +} diff --git a/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/HikariDemo.java b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/HikariDemo.java new file mode 100644 index 00000000..18601e02 --- /dev/null +++ b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/HikariDemo.java @@ -0,0 +1,94 @@ +package com.jeekbang.jdbc; + +import com.zaxxer.hikari.HikariDataSource; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import javax.sql.DataSource; +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + + +/** + * 配置 Hikari 连接池 + */ +public class HikariDemo { + + public static DataSource hikariDataSource(){ + HikariDataSource hikariDataSource = new HikariDataSource(); + hikariDataSource.setDriverClassName("org.h2.Driver"); + hikariDataSource.setJdbcUrl("jdbc:h2:mem:dataSource;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false"); + hikariDataSource.setUsername("sa"); + hikariDataSource.setPassword(""); + + return hikariDataSource; + } + + + public static void main(String[] args) throws SQLException { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:application.xml"); + final DataSource dataSource = hikariDataSource(); + final Connection connection = dataSource.getConnection(); + // 查询 + find(connection); + + // 新增 + add(connection); + find(connection); + + // 修改 + update(connection); + find(connection); + + // 删除 + delete(connection); + find(connection); + } + + + + + private static void find(Connection connection) throws SQLException { + final PreparedStatement statement = connection.prepareStatement("select * from student"); + final ResultSet resultSet = statement.executeQuery(); + List students = new ArrayList<>(); + while (resultSet.next()) { + final int id = resultSet.getInt("id"); + final String name = resultSet.getString("name"); + Student student = new Student(); + student.setId(id); + student.setName(name); + students.add(student); + } + System.out.println(students); + } + + private static void add(Connection connection) throws SQLException { + String sql = "insert into student(name) values(?)"; + connection.setAutoCommit(false); + final PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, "测试 - add"); + preparedStatement.executeUpdate(); + connection.commit(); + } + + + private static void update(Connection connection) throws SQLException { + String sql = "update student set name=? where name=?"; + connection.setAutoCommit(false); + final PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, "测试 - update"); + preparedStatement.setString(2, "测试 - add"); + preparedStatement.executeUpdate(); + connection.commit(); + } + + private static void delete(Connection connection) throws SQLException { + String sql = "delete from student where name=?"; + connection.setAutoCommit(false); + final PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, "测试 - update"); + preparedStatement.executeUpdate(); + connection.commit(); + } +} diff --git a/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/Student.java b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/Student.java new file mode 100644 index 00000000..8ca32838 --- /dev/null +++ b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/Student.java @@ -0,0 +1,30 @@ +package com.jeekbang.jdbc; + +public class Student { + private int id; + private String name; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "Student{" + + "id=" + id + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/04fx/jdbc-demo/src/main/resources/application.xml b/04fx/jdbc-demo/src/main/resources/application.xml new file mode 100644 index 00000000..31e0d38b --- /dev/null +++ b/04fx/jdbc-demo/src/main/resources/application.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/04fx/jdbc-demo/src/main/resources/sql/h2-data.sql b/04fx/jdbc-demo/src/main/resources/sql/h2-data.sql new file mode 100644 index 00000000..54fb77e8 --- /dev/null +++ b/04fx/jdbc-demo/src/main/resources/sql/h2-data.sql @@ -0,0 +1,2 @@ +insert into student(name) values('张三'); +insert into student(name) values('李四'); \ No newline at end of file diff --git a/04fx/jdbc-demo/src/main/resources/sql/h2-schema.sql b/04fx/jdbc-demo/src/main/resources/sql/h2-schema.sql new file mode 100644 index 00000000..9ad88972 --- /dev/null +++ b/04fx/jdbc-demo/src/main/resources/sql/h2-schema.sql @@ -0,0 +1,8 @@ +-- h2-schame.sql +drop table if exists student ; + +-- 创建表 +create table student( + id int primary key auto_increment, + name varchar(20) +); \ No newline at end of file diff --git a/04fx/springboot01/pom.xml b/04fx/springboot01/pom.xml index 51aabd22..8e668f43 100644 --- a/04fx/springboot01/pom.xml +++ b/04fx/springboot01/pom.xml @@ -46,7 +46,7 @@ len.xiyuan.spring.boot - len-xiyuan-spring-boot-starter + test-starter 0.0.1-SNAPSHOT diff --git a/04fx/springboot01/src/main/java/homework1003/SpringBoot1003Application.java b/04fx/springboot01/src/main/java/homework1003/SpringBoot1003Application.java index 108efaf5..6390ceab 100644 --- a/04fx/springboot01/src/main/java/homework1003/SpringBoot1003Application.java +++ b/04fx/springboot01/src/main/java/homework1003/SpringBoot1003Application.java @@ -2,10 +2,11 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; @SpringBootApplication(scanBasePackages = {"homework1003"}) public class SpringBoot1003Application { public static void main(String[] args) { - SpringApplication.run(SpringBoot1003Application.class, args); + ConfigurableApplicationContext context =SpringApplication.run(SpringBoot1003Application.class, args); } } diff --git a/04fx/springboot01/src/main/java/homework1003/web/WebPage.java b/04fx/springboot01/src/main/java/homework1003/web/WebPage.java index 1e91f176..5fa7f12b 100644 --- a/04fx/springboot01/src/main/java/homework1003/web/WebPage.java +++ b/04fx/springboot01/src/main/java/homework1003/web/WebPage.java @@ -18,6 +18,7 @@ public String hello() { @RequestMapping("/myStarter") @ResponseBody public String xiyuan() { + return ""; } } diff --git a/04fx/springboot01/src/main/resources/application.yml b/04fx/springboot01/src/main/resources/application.yml index 0af33ee8..32cd966c 100644 --- a/04fx/springboot01/src/main/resources/application.yml +++ b/04fx/springboot01/src/main/resources/application.yml @@ -4,7 +4,7 @@ server: diy: stu: id: 1 - name: xiyaun + name: xiyuan spring: activemq: From 7ed19f65a715e081fbdb12773e72d125136202f5 Mon Sep 17 00:00:00 2001 From: "xuehui.zhu" Date: Tue, 24 Nov 2020 18:21:42 +0800 Subject: [PATCH 4/6] MySQL homework --- .../src/main/java/leetcode/ListNode.java | 18 ++++ .../src/main/java/leetcode/Solution.java | 42 ++++++++++ 04fx/homework1003/pom.xml | 42 ---------- .../src/main/java/config/StuConfigration.java | 22 ----- .../src/main/java/pojo/Student.java | 25 ------ .../main/resources/META-INF/spring.factories | 1 - .../spring-configuration-metadata.json | 23 ----- .../target/classes/META-INF/spring.factories | 1 - .../target/maven-archiver/pom.properties | 4 - .../compile/default-compile/createdFiles.lst | 3 - .../compile/default-compile/inputFiles.lst | 2 - .../default-testCompile/inputFiles.lst | 0 .../test-starter-0.0.1-SNAPSHOT.jar.original | Bin 4010 -> 0 bytes 04fx/jdbc-demo/pom.xml | 7 ++ .../java/com/jeekbang/jdbc/MyDataSql.java | 79 ++++++++++++++++++ 04fx/springboot01/pom.xml | 7 -- 16 files changed, 146 insertions(+), 130 deletions(-) create mode 100644 02nio/nio01/src/main/java/leetcode/ListNode.java create mode 100644 02nio/nio01/src/main/java/leetcode/Solution.java delete mode 100644 04fx/homework1003/pom.xml delete mode 100644 04fx/homework1003/src/main/java/config/StuConfigration.java delete mode 100644 04fx/homework1003/src/main/java/pojo/Student.java delete mode 100644 04fx/homework1003/src/main/resources/META-INF/spring.factories delete mode 100644 04fx/homework1003/target/classes/META-INF/spring-configuration-metadata.json delete mode 100644 04fx/homework1003/target/classes/META-INF/spring.factories delete mode 100644 04fx/homework1003/target/maven-archiver/pom.properties delete mode 100644 04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst delete mode 100644 04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst delete mode 100644 04fx/homework1003/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst delete mode 100644 04fx/homework1003/target/test-starter-0.0.1-SNAPSHOT.jar.original create mode 100644 04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/MyDataSql.java diff --git a/02nio/nio01/src/main/java/leetcode/ListNode.java b/02nio/nio01/src/main/java/leetcode/ListNode.java new file mode 100644 index 00000000..a306d8fc --- /dev/null +++ b/02nio/nio01/src/main/java/leetcode/ListNode.java @@ -0,0 +1,18 @@ +package leetcode; + +public class ListNode { + int val; + ListNode next; + + ListNode() { + } + + ListNode(int val) { + this.val = val; + } + + ListNode(int val, ListNode next) { + this.val = val; + this.next = next; + } +} diff --git a/02nio/nio01/src/main/java/leetcode/Solution.java b/02nio/nio01/src/main/java/leetcode/Solution.java new file mode 100644 index 00000000..db7eda4d --- /dev/null +++ b/02nio/nio01/src/main/java/leetcode/Solution.java @@ -0,0 +1,42 @@ +package leetcode; + +public class Solution { + public static void main(String[] args) { + ListNode head = new ListNode(4); + head.next = new ListNode(2); + head.next.next = new ListNode(1); + head.next.next.next = new ListNode(3); + new Solution().numDecodings("12"); + } + + public int numDecodings(String s) { + if (s.charAt(0) == '0') return 0; + + int[] dp = new int[s.length() + 1]; + dp[0] = 1; + dp[1] = 1; + + if (s.length()==1) return dp[1]; + + for (int i=2; i '2') return 0; + + if (c1 == '0' || c2 == '0') { + dp[i] = c1=='0'? dp[i-2] : dp[i-1]; + } else { + if (c2 <= '2' && c1 <= '6') { + dp[i] = dp[i-2] + dp[i-1]; + } else { + dp[i] = dp[i-1]; + } + } + + } + return dp[s.length()]; + } + +} diff --git a/04fx/homework1003/pom.xml b/04fx/homework1003/pom.xml deleted file mode 100644 index a24054e8..00000000 --- a/04fx/homework1003/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.0.9.RELEASE - - - - len.xiyuan.spring.boot - test-starter - 0.0.1-SNAPSHOT - jar - Demo project for Spring Boot Starter - - - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-autoconfigure - - - org.springframework.boot - spring-boot-configuration-processor - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/04fx/homework1003/src/main/java/config/StuConfigration.java b/04fx/homework1003/src/main/java/config/StuConfigration.java deleted file mode 100644 index 8ce271ad..00000000 --- a/04fx/homework1003/src/main/java/config/StuConfigration.java +++ /dev/null @@ -1,22 +0,0 @@ -package config; - -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import pojo.Student; - -import java.util.HashMap; -import java.util.Map; - -@Configuration -@EnableConfigurationProperties(Student.class) -public class StuConfigration { - @Bean - public Map getBean(Student student){ - Map result = new HashMap(); - result.put("ID",student.getId()); - result.put("name",student.getName()); - return result; - } - -} diff --git a/04fx/homework1003/src/main/java/pojo/Student.java b/04fx/homework1003/src/main/java/pojo/Student.java deleted file mode 100644 index 8ed73c82..00000000 --- a/04fx/homework1003/src/main/java/pojo/Student.java +++ /dev/null @@ -1,25 +0,0 @@ -package pojo; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties(prefix = "diy.stu") -public class Student { - private int id; - private String name; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/04fx/homework1003/src/main/resources/META-INF/spring.factories b/04fx/homework1003/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 751af5d3..00000000 --- a/04fx/homework1003/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=config.StuConfigration diff --git a/04fx/homework1003/target/classes/META-INF/spring-configuration-metadata.json b/04fx/homework1003/target/classes/META-INF/spring-configuration-metadata.json deleted file mode 100644 index fcc25683..00000000 --- a/04fx/homework1003/target/classes/META-INF/spring-configuration-metadata.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "hints": [], - "groups": [ - { - "sourceType": "pojo.Student", - "name": "diy.stu", - "type": "pojo.Student" - } - ], - "properties": [ - { - "sourceType": "pojo.Student", - "defaultValue": 0, - "name": "diy.stu.id", - "type": "java.lang.Integer" - }, - { - "sourceType": "pojo.Student", - "name": "diy.stu.name", - "type": "java.lang.String" - } - ] -} \ No newline at end of file diff --git a/04fx/homework1003/target/classes/META-INF/spring.factories b/04fx/homework1003/target/classes/META-INF/spring.factories deleted file mode 100644 index 751af5d3..00000000 --- a/04fx/homework1003/target/classes/META-INF/spring.factories +++ /dev/null @@ -1 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=config.StuConfigration diff --git a/04fx/homework1003/target/maven-archiver/pom.properties b/04fx/homework1003/target/maven-archiver/pom.properties deleted file mode 100644 index e4cf11a2..00000000 --- a/04fx/homework1003/target/maven-archiver/pom.properties +++ /dev/null @@ -1,4 +0,0 @@ -#Created by Apache Maven 3.6.3 -version=0.0.1-SNAPSHOT -groupId=len.xiyuan.spring.boot -artifactId=test-starter diff --git a/04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst deleted file mode 100644 index 852f78cf..00000000 --- a/04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ /dev/null @@ -1,3 +0,0 @@ -META-INF\spring-configuration-metadata.json -pojo\Student.class -config\StuConfigration.class diff --git a/04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst deleted file mode 100644 index 84c497d2..00000000 --- a/04fx/homework1003/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ /dev/null @@ -1,2 +0,0 @@ -D:\workspace\IdeaProject\JavaCourseCodes\04fx\homework1003\src\main\java\config\StuConfigration.java -D:\workspace\IdeaProject\JavaCourseCodes\04fx\homework1003\src\main\java\pojo\Student.java diff --git a/04fx/homework1003/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/04fx/homework1003/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst deleted file mode 100644 index e69de29b..00000000 diff --git a/04fx/homework1003/target/test-starter-0.0.1-SNAPSHOT.jar.original b/04fx/homework1003/target/test-starter-0.0.1-SNAPSHOT.jar.original deleted file mode 100644 index 3527e9a43b867ac542b77fc25ae7ad4b0f7b67e3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4010 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 VMzI3nfruntime + + mysql + mysql-connector-java + 5.1.42 + runtime + + org.springframework spring-core diff --git a/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/MyDataSql.java b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/MyDataSql.java new file mode 100644 index 00000000..143ae41d --- /dev/null +++ b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/MyDataSql.java @@ -0,0 +1,79 @@ +package com.jeekbang.jdbc; + +import com.zaxxer.hikari.HikariDataSource; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import javax.sql.DataSource; +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + + +/** + * 配置 Hikari 连接池 + */ +public class MyDataSql { + static final String dbDriver = "com.mysql.jdbc.Driver"; + static final String url = "jdbc:mysql://localhost:3306/eplat?rewriteBatchedStatements=true"; + static final String username = "july"; + static final String password = "a123"; + + + public static DataSource hikariDataSource() { + HikariDataSource hikariDataSource = new HikariDataSource(); + hikariDataSource.setDriverClassName(dbDriver); + hikariDataSource.setJdbcUrl(url); + hikariDataSource.setUsername(username); + hikariDataSource.setPassword(password); + + return hikariDataSource; + } + + + public static void main(String[] args) throws SQLException { + //数据库连接 + DataSource dataSource = hikariDataSource(); + Connection conn = dataSource.getConnection(); + + //订单数据 + long start=System.currentTimeMillis(); + createBigOrderData(conn,1000000); + System.out.println("生成订单数据耗时:"+ (System.currentTimeMillis()-start) / 1000 + " s"); + + } + + private static void createBigOrderData(Connection conn, int count) { + String sql = "insert into t_order(id,user_id,addr_id,goods_id,unit_price,quantity,amount,actice_id,snapshot_id,real_price,real_amount)" + + " values(?,?,?,?,?,?,?,?,?,?,?)"; + try { + PreparedStatement pst = conn.prepareStatement(sql); + int i=0; + while (i < count) { + for (int j=0; j<10000 && jspring-boot-starter-data-mongodb - - len.xiyuan.spring.boot - test-starter - 0.0.1-SNAPSHOT - - - org.springframework.boot spring-boot-starter-test From ed46ea5cb4f49d55dcb4bb55a5a6cac6b633db89 Mon Sep 17 00:00:00 2001 From: July Date: Thu, 3 Dec 2020 00:23:15 +0800 Subject: [PATCH 5/6] week07 --- .../src/main/java/com/jeekbang/jdbc/MyDataSql.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/MyDataSql.java b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/MyDataSql.java index 143ae41d..3fd87911 100644 --- a/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/MyDataSql.java +++ b/04fx/jdbc-demo/src/main/java/com/jeekbang/jdbc/MyDataSql.java @@ -16,7 +16,7 @@ public class MyDataSql { static final String dbDriver = "com.mysql.jdbc.Driver"; static final String url = "jdbc:mysql://localhost:3306/eplat?rewriteBatchedStatements=true"; static final String username = "july"; - static final String password = "a123"; + static final String password = "!QAZ2wsx"; public static DataSource hikariDataSource() { @@ -38,10 +38,15 @@ public static void main(String[] args) throws SQLException { //订单数据 long start=System.currentTimeMillis(); createBigOrderData(conn,1000000); - System.out.println("生成订单数据耗时:"+ (System.currentTimeMillis()-start) / 1000 + " s"); + System.out.println("生成100万条订单数据耗时:"+ (System.currentTimeMillis()-start) / 1000 + " s"); } + /** + * 生成数据 + * @param conn + * @param count + */ private static void createBigOrderData(Connection conn, int count) { String sql = "insert into t_order(id,user_id,addr_id,goods_id,unit_price,quantity,amount,actice_id,snapshot_id,real_price,real_amount)" + " values(?,?,?,?,?,?,?,?,?,?,?)"; From f2e843ec6a6fe953cbbd4a7fb35d6f466f658daa Mon Sep 17 00:00:00 2001 From: July Date: Sun, 13 Dec 2020 12:06:44 +0800 Subject: [PATCH 6/6] week09 --- .../src/main/java/leetcode/ListNode.java | 18 -------- .../src/main/java/leetcode/Solution.java | 42 ------------------- .../target/classes/application.yml | 11 +++++ 3 files changed, 11 insertions(+), 60 deletions(-) delete mode 100644 02nio/nio01/src/main/java/leetcode/ListNode.java delete mode 100644 02nio/nio01/src/main/java/leetcode/Solution.java diff --git a/02nio/nio01/src/main/java/leetcode/ListNode.java b/02nio/nio01/src/main/java/leetcode/ListNode.java deleted file mode 100644 index a306d8fc..00000000 --- a/02nio/nio01/src/main/java/leetcode/ListNode.java +++ /dev/null @@ -1,18 +0,0 @@ -package leetcode; - -public class ListNode { - int val; - ListNode next; - - ListNode() { - } - - ListNode(int val) { - this.val = val; - } - - ListNode(int val, ListNode next) { - this.val = val; - this.next = next; - } -} diff --git a/02nio/nio01/src/main/java/leetcode/Solution.java b/02nio/nio01/src/main/java/leetcode/Solution.java deleted file mode 100644 index db7eda4d..00000000 --- a/02nio/nio01/src/main/java/leetcode/Solution.java +++ /dev/null @@ -1,42 +0,0 @@ -package leetcode; - -public class Solution { - public static void main(String[] args) { - ListNode head = new ListNode(4); - head.next = new ListNode(2); - head.next.next = new ListNode(1); - head.next.next.next = new ListNode(3); - new Solution().numDecodings("12"); - } - - public int numDecodings(String s) { - if (s.charAt(0) == '0') return 0; - - int[] dp = new int[s.length() + 1]; - dp[0] = 1; - dp[1] = 1; - - if (s.length()==1) return dp[1]; - - for (int i=2; i '2') return 0; - - if (c1 == '0' || c2 == '0') { - dp[i] = c1=='0'? dp[i-2] : dp[i-1]; - } else { - if (c2 <= '2' && c1 <= '6') { - dp[i] = dp[i-2] + dp[i-1]; - } else { - dp[i] = dp[i-1]; - } - } - - } - return dp[s.length()]; - } - -} diff --git a/04fx/springboot01/target/classes/application.yml b/04fx/springboot01/target/classes/application.yml index 4b7302f1..7db96b12 100644 --- a/04fx/springboot01/target/classes/application.yml +++ b/04fx/springboot01/target/classes/application.yml @@ -1,6 +1,11 @@ server: port: 8081 +diy: + stu: + id: 1 + name: xiyuan + spring: activemq: broker-url: tcp://127.0.0.1:61616 @@ -18,9 +23,15 @@ spring: enabled: true max-connections: 10 #连接池最大连接数 idle-timeout: 30000 #空闲的连接过期时间,默认为30秒 + + + data: mongodb: uri: mongodb://localhost:27017/mydb + + profiles: + active: true # jms: # pub-sub-domain: true #默认情况下activemq提供的是queue模式,若要使用topic模式需要配置下面配置