diff --git a/Spring/Spring5/code/shangguigu01/.idea/.gitignore b/Spring/Spring5/code/shangguigu01/.idea/.gitignore new file mode 100644 index 00000000..0a8642fa --- /dev/null +++ b/Spring/Spring5/code/shangguigu01/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Zeppelin ignored files +/ZeppelinRemoteNotebooks/ diff --git a/Spring/Spring5/code/shangguigu01/.idea/compiler.xml b/Spring/Spring5/code/shangguigu01/.idea/compiler.xml new file mode 100644 index 00000000..a0eb064f --- /dev/null +++ b/Spring/Spring5/code/shangguigu01/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu01/.idea/jarRepositories.xml b/Spring/Spring5/code/shangguigu01/.idea/jarRepositories.xml new file mode 100644 index 00000000..54f518fe --- /dev/null +++ b/Spring/Spring5/code/shangguigu01/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu01/.idea/misc.xml b/Spring/Spring5/code/shangguigu01/.idea/misc.xml new file mode 100644 index 00000000..132404bc --- /dev/null +++ b/Spring/Spring5/code/shangguigu01/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu01/pom.xml b/Spring/Spring5/code/shangguigu01/pom.xml new file mode 100644 index 00000000..4bc75ba6 --- /dev/null +++ b/Spring/Spring5/code/shangguigu01/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + + + spring-boot + org.springframework.boot + 2.2.1.RELEASE + + org.example + shangguigu01 + 1.0-SNAPSHOT + + + 8 + 8 + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu01/src/main/java/com/ykl/HelloWorld.java b/Spring/Spring5/code/shangguigu01/src/main/java/com/ykl/HelloWorld.java new file mode 100644 index 00000000..df1bef46 --- /dev/null +++ b/Spring/Spring5/code/shangguigu01/src/main/java/com/ykl/HelloWorld.java @@ -0,0 +1,15 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl; + +/** + * @author yinkanglong + * @version : HelloWorld, v 0.1 2022-10-08 11:06 yinkanglong Exp $ + */ +public class HelloWorld { + public static void main(String[] args) { + System.out.println("hello world"); + } +} diff --git a/Spring/Spring5/code/shangguigu01/src/main/java/com/ykl/reactor/ObserverDemo.java b/Spring/Spring5/code/shangguigu01/src/main/java/com/ykl/reactor/ObserverDemo.java new file mode 100644 index 00000000..7618b57e --- /dev/null +++ b/Spring/Spring5/code/shangguigu01/src/main/java/com/ykl/reactor/ObserverDemo.java @@ -0,0 +1,12 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.reactor; + +/** + * @author yinkanglong + * @version : ObserverDemo, v 0.1 2022-10-12 19:43 yinkanglong Exp $ + */ +public class ObserverDemo { +} diff --git a/Spring/Spring5/code/shangguigu02/.idea/.gitignore b/Spring/Spring5/code/shangguigu02/.idea/.gitignore new file mode 100644 index 00000000..0a8642fa --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Zeppelin ignored files +/ZeppelinRemoteNotebooks/ diff --git a/Spring/Spring5/code/shangguigu02/.idea/misc.xml b/Spring/Spring5/code/shangguigu02/.idea/misc.xml new file mode 100644 index 00000000..05483570 --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu02/.idea/modules.xml b/Spring/Spring5/code/shangguigu02/.idea/modules.xml new file mode 100644 index 00000000..25a4e288 --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu02/.idea/uiDesigner.xml b/Spring/Spring5/code/shangguigu02/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu02/lib/commons-logging-1.2.jar b/Spring/Spring5/code/shangguigu02/lib/commons-logging-1.2.jar new file mode 100644 index 00000000..93a3b9f6 Binary files /dev/null and b/Spring/Spring5/code/shangguigu02/lib/commons-logging-1.2.jar differ diff --git a/Spring/Spring5/code/shangguigu02/lib/spring-beans-5.3.23.jar b/Spring/Spring5/code/shangguigu02/lib/spring-beans-5.3.23.jar new file mode 100644 index 00000000..fcc7cfd6 Binary files /dev/null and b/Spring/Spring5/code/shangguigu02/lib/spring-beans-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu02/lib/spring-context-5.3.23.jar b/Spring/Spring5/code/shangguigu02/lib/spring-context-5.3.23.jar new file mode 100644 index 00000000..e80b5da4 Binary files /dev/null and b/Spring/Spring5/code/shangguigu02/lib/spring-context-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu02/lib/spring-core-5.3.23.jar b/Spring/Spring5/code/shangguigu02/lib/spring-core-5.3.23.jar new file mode 100644 index 00000000..78ff1cae Binary files /dev/null and b/Spring/Spring5/code/shangguigu02/lib/spring-core-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu02/lib/spring-expression-5.3.23.jar b/Spring/Spring5/code/shangguigu02/lib/spring-expression-5.3.23.jar new file mode 100644 index 00000000..3d10ecea Binary files /dev/null and b/Spring/Spring5/code/shangguigu02/lib/spring-expression-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu02/out/production/shangguigu02/bean01.xml b/Spring/Spring5/code/shangguigu02/out/production/shangguigu02/bean01.xml new file mode 100644 index 00000000..32eeb34a --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/out/production/shangguigu02/bean01.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu02/out/production/shangguigu02/bean02.xml b/Spring/Spring5/code/shangguigu02/out/production/shangguigu02/bean02.xml new file mode 100644 index 00000000..59a11892 --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/out/production/shangguigu02/bean02.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu02/out/production/shangguigu02/bean03.xml b/Spring/Spring5/code/shangguigu02/out/production/shangguigu02/bean03.xml new file mode 100644 index 00000000..6218817b --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/out/production/shangguigu02/bean03.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu02/shangguigu02.iml b/Spring/Spring5/code/shangguigu02/shangguigu02.iml new file mode 100644 index 00000000..e7266aab --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/shangguigu02.iml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu02/src/Main.java b/Spring/Spring5/code/shangguigu02/src/Main.java new file mode 100644 index 00000000..3e1ab5fd --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/Main.java @@ -0,0 +1,17 @@ +import com.ykl.User; + +/** + * @author yinkanglong + * @version $Id: ${NAME}, v 0.1 ${YEAR}-${MONTH}-${DAY} ${TIME} yinkanglong Exp $ + */ +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + //自己创建对象 +// User user = new User(); +// user.add(); + + //通过spring创建对象 + + } +} \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu02/src/bean01.xml b/Spring/Spring5/code/shangguigu02/src/bean01.xml new file mode 100644 index 00000000..32eeb34a --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/bean01.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu02/src/bean02.xml b/Spring/Spring5/code/shangguigu02/src/bean02.xml new file mode 100644 index 00000000..59a11892 --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/bean02.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu02/src/bean03.xml b/Spring/Spring5/code/shangguigu02/src/bean03.xml new file mode 100644 index 00000000..6218817b --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/bean03.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu02/src/com/ykl/Book.java b/Spring/Spring5/code/shangguigu02/src/com/ykl/Book.java new file mode 100644 index 00000000..0b21a472 --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/com/ykl/Book.java @@ -0,0 +1,45 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl; + +/** + * @author yinkanglong + * @version : Book, v 0.1 2022-10-08 14:32 yinkanglong Exp $ + */ +public class Book { + /** + * Getter method for property name. + * + * @return property value of name + */ + public String getName() { + return name; + } + + private String name; + + //set方法注入 + public void setName(String name) { + this.name = name; + } + + //有参构造函数注入 + public Book(String name){ + this.name = name; + } + + public Book(){ + + } + + public static void main(String[] args) { + //使用set方法注入 + Book book = new Book(); + book.setName("123"); + + //使用有参构造函数注入 + Book book2 = new Book("abc"); + } +} diff --git a/Spring/Spring5/code/shangguigu02/src/com/ykl/Order.java b/Spring/Spring5/code/shangguigu02/src/com/ykl/Order.java new file mode 100644 index 00000000..c663d25c --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/com/ykl/Order.java @@ -0,0 +1,23 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl; + +/** + * @author yinkanglong + * @version : Order, v 0.1 2022-10-08 14:47 yinkanglong Exp $ + */ +public class Order { + private String oname; + private String address; + + public Order(String oname, String address) { + this.oname = oname; + this.address = address; + } + + public void test(){ + System.out.println(this.oname+this.address); + } +} diff --git a/Spring/Spring5/code/shangguigu02/src/com/ykl/User.java b/Spring/Spring5/code/shangguigu02/src/com/ykl/User.java new file mode 100644 index 00000000..77741a28 --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/com/ykl/User.java @@ -0,0 +1,42 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl; + +/** + * @author yinkanglong + * @version : User, v 0.1 2022-10-08 11:22 yinkanglong Exp $ + */ +public class User { + public User(String username) { + Username = username; + } + + public User() { + } + /** + * Getter method for property Username. + * + * @return property value of Username + */ + public String getUsername() { + return Username; + } + + /** + * Setter method for property counterType. + * + * @param Username value to be assigned to property Username + */ + public void setUsername(String username) { + Username = username; + } + + private String Username; + + + public void add(){ + System.out.println("add user"); + } +} diff --git a/Spring/Spring5/code/shangguigu02/src/com/ykl/bean/Dept.java b/Spring/Spring5/code/shangguigu02/src/com/ykl/bean/Dept.java new file mode 100644 index 00000000..40e50d75 --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/com/ykl/bean/Dept.java @@ -0,0 +1,29 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.bean; + +/** + * @author yinkanglong + * @version : Dept, v 0.1 2022-10-08 15:33 yinkanglong Exp $ + */ +public class Dept { + private String dname; + + /** + * Setter method for property counterType. + * + * @param dname value to be assigned to property pname + */ + public void setDname(String dname) { + this.dname = dname; + } + + @Override + public String toString() { + return "Dept{" + + "pname='" + dname + '\'' + + '}'; + } +} diff --git a/Spring/Spring5/code/shangguigu02/src/com/ykl/bean/Emp.java b/Spring/Spring5/code/shangguigu02/src/com/ykl/bean/Emp.java new file mode 100644 index 00000000..a5179f76 --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/com/ykl/bean/Emp.java @@ -0,0 +1,38 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.bean; + +/** + * @author yinkanglong + * @version : Emp, v 0.1 2022-10-08 15:34 yinkanglong Exp $ + */ +public class Emp { + private String ename; + private String gender; + + @Override + public String toString() { + return "Emp{" + + "ename='" + ename + '\'' + + ", gender='" + gender + '\'' + + ", dept=" + dept + + '}'; + } + + public void setDept(Dept dept) { + this.dept = dept; + } + + private Dept dept; + + public void setEname(String ename) { + this.ename = ename; + } + + + public void setGender(String gender) { + this.gender = gender; + } +} diff --git a/Spring/Spring5/code/shangguigu02/src/com/ykl/dao/UserDao.java b/Spring/Spring5/code/shangguigu02/src/com/ykl/dao/UserDao.java new file mode 100644 index 00000000..24c78c4a --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/com/ykl/dao/UserDao.java @@ -0,0 +1,13 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.dao; + +/** + * @author yinkanglong + * @version : UserDao, v 0.1 2022-10-08 15:15 yinkanglong Exp $ + */ +public interface UserDao { + public void update(); +} diff --git a/Spring/Spring5/code/shangguigu02/src/com/ykl/dao/UserDaoImpl.java b/Spring/Spring5/code/shangguigu02/src/com/ykl/dao/UserDaoImpl.java new file mode 100644 index 00000000..e3568189 --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/com/ykl/dao/UserDaoImpl.java @@ -0,0 +1,17 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.dao; + +/** + * @author yinkanglong + * @version : UserDaoImpl, v 0.1 2022-10-08 15:15 yinkanglong Exp $ + */ +public class UserDaoImpl implements UserDao{ + + @Override + public void update(){ + System.out.println("dao update ..."); + } +} diff --git a/Spring/Spring5/code/shangguigu02/src/com/ykl/service/UserService.java b/Spring/Spring5/code/shangguigu02/src/com/ykl/service/UserService.java new file mode 100644 index 00000000..fd459163 --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/com/ykl/service/UserService.java @@ -0,0 +1,31 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.service; + +import com.ykl.dao.UserDao; + +/** + * @author yinkanglong + * @version : UserService, v 0.1 2022-10-08 15:14 yinkanglong Exp $ + */ +public class UserService { + + public UserDao getUserDao() { + return userDao; + } + + public void setUserDao(UserDao userDao) { + this.userDao = userDao; + } + + UserDao userDao; + + + public void add(){ + System.out.println("service add ..."); + + userDao.update(); + } +} diff --git a/Spring/Spring5/code/shangguigu02/src/com/ykl/testdemo/Test01.java b/Spring/Spring5/code/shangguigu02/src/com/ykl/testdemo/Test01.java new file mode 100644 index 00000000..b9c0009f --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/com/ykl/testdemo/Test01.java @@ -0,0 +1,52 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.testdemo; + +import com.ykl.Book; +import com.ykl.Order; +import com.ykl.User; +import org.junit.Test; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author yinkanglong + * @version : Test01, v 0.1 2022-10-08 11:27 yinkanglong Exp $ + */ +public class Test01 { + @Test + public void testAdd(){ +// 加载spring的配置文件 +// ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml"); + BeanFactory context = new ClassPathXmlApplicationContext("bean01.xml"); + + // 获取配置创建的对象 + User user = context.getBean("user", User.class); + System.out.println(user); + user.add(); + } + + @Test + public void testBook(){ + +// 在创建对象的过程中就完成了属性的注入 + ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml"); + + Book book = context.getBean("book", Book.class); + + System.out.println(book.getName()); + + } + + @Test + public void testOrder(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml"); + + Order order = context.getBean("order", Order.class); + + order.test(); + } +} diff --git a/Spring/Spring5/code/shangguigu02/src/com/ykl/testdemo/Test02.java b/Spring/Spring5/code/shangguigu02/src/com/ykl/testdemo/Test02.java new file mode 100644 index 00000000..e239ffca --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/com/ykl/testdemo/Test02.java @@ -0,0 +1,28 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.testdemo; + +import com.ykl.User; +import com.ykl.service.UserService; +import org.junit.Test; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author yinkanglong + * @version : Tst02, v 0.1 2022-10-08 15:23 yinkanglong Exp $ + */ +public class Test02 { + @Test + public void testAdd(){ +// 加载spring的配置文件 + ApplicationContext context = new ClassPathXmlApplicationContext("bean02.xml"); + + // 获取配置创建的对象 + UserService user = context.getBean("userService", UserService.class); + user.add(); + } +} diff --git a/Spring/Spring5/code/shangguigu02/src/com/ykl/testdemo/Test03.java b/Spring/Spring5/code/shangguigu02/src/com/ykl/testdemo/Test03.java new file mode 100644 index 00000000..73b27960 --- /dev/null +++ b/Spring/Spring5/code/shangguigu02/src/com/ykl/testdemo/Test03.java @@ -0,0 +1,29 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.testdemo; + +import com.ykl.bean.Emp; +import com.ykl.service.UserService; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author yinkanglong + * @version : Test03, v 0.1 2022-10-08 15:45 yinkanglong Exp $ + */ +public class Test03 { + @Test + public void testAdd(){ +// 加载spring的配置文件 + ApplicationContext context = new ClassPathXmlApplicationContext("bean03.xml"); + + // 获取配置创建的对象 + Emp emp = context.getBean("emp", Emp.class); + System.out.println(emp); + } + + +} diff --git a/Spring/Spring5/code/shangguigu03/.idea/.gitignore b/Spring/Spring5/code/shangguigu03/.idea/.gitignore new file mode 100644 index 00000000..0a8642fa --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Zeppelin ignored files +/ZeppelinRemoteNotebooks/ diff --git a/Spring/Spring5/code/shangguigu03/.idea/misc.xml b/Spring/Spring5/code/shangguigu03/.idea/misc.xml new file mode 100644 index 00000000..05483570 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu03/.idea/modules.xml b/Spring/Spring5/code/shangguigu03/.idea/modules.xml new file mode 100644 index 00000000..3d36e8c9 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu03/.idea/uiDesigner.xml b/Spring/Spring5/code/shangguigu03/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu03/lib/commons-logging-1.2.jar b/Spring/Spring5/code/shangguigu03/lib/commons-logging-1.2.jar new file mode 100644 index 00000000..93a3b9f6 Binary files /dev/null and b/Spring/Spring5/code/shangguigu03/lib/commons-logging-1.2.jar differ diff --git a/Spring/Spring5/code/shangguigu03/lib/druid-1.2.13.jar b/Spring/Spring5/code/shangguigu03/lib/druid-1.2.13.jar new file mode 100644 index 00000000..9cc27d34 Binary files /dev/null and b/Spring/Spring5/code/shangguigu03/lib/druid-1.2.13.jar differ diff --git a/Spring/Spring5/code/shangguigu03/lib/spring-beans-5.3.23.jar b/Spring/Spring5/code/shangguigu03/lib/spring-beans-5.3.23.jar new file mode 100644 index 00000000..fcc7cfd6 Binary files /dev/null and b/Spring/Spring5/code/shangguigu03/lib/spring-beans-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu03/lib/spring-context-5.3.23.jar b/Spring/Spring5/code/shangguigu03/lib/spring-context-5.3.23.jar new file mode 100644 index 00000000..e80b5da4 Binary files /dev/null and b/Spring/Spring5/code/shangguigu03/lib/spring-context-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu03/lib/spring-core-5.3.23.jar b/Spring/Spring5/code/shangguigu03/lib/spring-core-5.3.23.jar new file mode 100644 index 00000000..78ff1cae Binary files /dev/null and b/Spring/Spring5/code/shangguigu03/lib/spring-core-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu03/lib/spring-expression-5.3.23.jar b/Spring/Spring5/code/shangguigu03/lib/spring-expression-5.3.23.jar new file mode 100644 index 00000000..3d10ecea Binary files /dev/null and b/Spring/Spring5/code/shangguigu03/lib/spring-expression-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean01.xml b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean01.xml new file mode 100644 index 00000000..9375d729 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean01.xml @@ -0,0 +1,54 @@ + + + + + + java + c + + + + + + zhangsan + xiaosan + + + + + + + + + + + + + msyql + redis + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean02.xml b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean02.xml new file mode 100644 index 00000000..fa57323d --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean02.xml @@ -0,0 +1,18 @@ + + + + + zhangsan + xiaosan + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean03.xml b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean03.xml new file mode 100644 index 00000000..86ab379c --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean03.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean04.xml b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean04.xml new file mode 100644 index 00000000..aedf8b2b --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean04.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean05.xml b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean05.xml new file mode 100644 index 00000000..ab6da799 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean05.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean06.xml b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean06.xml new file mode 100644 index 00000000..2c1d7e0d --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean06.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean07.xml b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean07.xml new file mode 100644 index 00000000..550c2789 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/bean07.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/jdbc.properties b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/jdbc.properties new file mode 100644 index 00000000..90b61e10 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/out/production/shangguigu03/jdbc.properties @@ -0,0 +1,4 @@ +prop.driverClass=com.mysql.jdbc.Driver +prop.url=jdbc:mysql://localhost:3306/user +prop.username=root +prop.password=123456 \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu03/shangguigu03.iml b/Spring/Spring5/code/shangguigu03/shangguigu03.iml new file mode 100644 index 00000000..6f95e92c --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/shangguigu03.iml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu03/src/Main.java b/Spring/Spring5/code/shangguigu03/src/Main.java new file mode 100644 index 00000000..7cf1a648 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/Main.java @@ -0,0 +1,9 @@ +/** + * @author yinkanglong + * @version $Id: ${NAME}, v 0.1 ${YEAR}-${MONTH}-${DAY} ${TIME} yinkanglong Exp $ + */ +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu03/src/bean01.xml b/Spring/Spring5/code/shangguigu03/src/bean01.xml new file mode 100644 index 00000000..9375d729 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/bean01.xml @@ -0,0 +1,54 @@ + + + + + + java + c + + + + + + zhangsan + xiaosan + + + + + + + + + + + + + msyql + redis + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu03/src/bean02.xml b/Spring/Spring5/code/shangguigu03/src/bean02.xml new file mode 100644 index 00000000..fa57323d --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/bean02.xml @@ -0,0 +1,18 @@ + + + + + zhangsan + xiaosan + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu03/src/bean03.xml b/Spring/Spring5/code/shangguigu03/src/bean03.xml new file mode 100644 index 00000000..86ab379c --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/bean03.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/Spring/Spring5/code/shangguigu03/src/bean04.xml b/Spring/Spring5/code/shangguigu03/src/bean04.xml new file mode 100644 index 00000000..aedf8b2b --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/bean04.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu03/src/bean05.xml b/Spring/Spring5/code/shangguigu03/src/bean05.xml new file mode 100644 index 00000000..ab6da799 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/bean05.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu03/src/bean06.xml b/Spring/Spring5/code/shangguigu03/src/bean06.xml new file mode 100644 index 00000000..2c1d7e0d --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/bean06.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu03/src/bean07.xml b/Spring/Spring5/code/shangguigu03/src/bean07.xml new file mode 100644 index 00000000..c8d4e7ca --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/bean07.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/autowire/Dept.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/autowire/Dept.java new file mode 100644 index 00000000..e403e641 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/autowire/Dept.java @@ -0,0 +1,38 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.autowire; + +/** + * @author yinkanglong + * @version : Detp, v 0.1 2022-10-09 10:55 yinkanglong Exp $ + */ +public class Dept { + private String dname; + + /** + * Getter method for property dname. + * + * @return property value of dname + */ + public String getDname() { + return dname; + } + + /** + * Setter method for property counterType. + * + * @param dname value to be assigned to property dname + */ + public void setDname(String dname) { + this.dname = dname; + } + + @Override + public String toString() { + return "Dept{" + + "dname='" + dname + '\'' + + '}'; + } +} diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/autowire/Emp.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/autowire/Emp.java new file mode 100644 index 00000000..cad66dc6 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/autowire/Emp.java @@ -0,0 +1,38 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.autowire; + +/** + * @author yinkanglong + * @version : Emp, v 0.1 2022-10-09 10:55 yinkanglong Exp $ + */ +public class Emp { + private Dept dept; + + /** + * Getter method for property dept. + * + * @return property value of dept + */ + public Dept getDept() { + return dept; + } + + /** + * Setter method for property counterType. + * + * @param dept value to be assigned to property dept + */ + public void setDept(Dept dept) { + this.dept = dept; + } + + @Override + public String toString() { + return "Emp{" + + "dept=" + dept + + '}'; + } +} diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/bean/MyBeanPost.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/bean/MyBeanPost.java new file mode 100644 index 00000000..6c7dafe9 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/bean/MyBeanPost.java @@ -0,0 +1,28 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.bean; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.lang.Nullable; + +/** + * @author yinkanglong + * @version : MyBeanPost, v 0.1 2022-10-09 10:42 yinkanglong Exp $ + */ +public class MyBeanPost implements BeanPostProcessor { + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + System.out.println("后置处理器,前置任务");; + return bean; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + System.out.println("后置处理器,后置任务"); + return bean; + } +} diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/bean/Order.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/bean/Order.java new file mode 100644 index 00000000..4902c15c --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/bean/Order.java @@ -0,0 +1,40 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.bean; + +/** + * @author yinkanglong + * @version : order, v 0.1 2022-10-09 10:17 yinkanglong Exp $ + */ +public class Order { + private String oname; + + public Order(String oname) { + this.oname = oname; + } + + public Order() { + System.out.println("第一步 执行无参构造函数创建bean实例"); + } + + + public void setOname(String oname) { + this.oname = oname; + System.out.println("第二步 调用set方法设置属性值"); + } + + public String getOname() { + return oname; + } + + public void initMethod(){ + System.out.println("第三部 调用初始化方法"); + } + + public void destroyMethod(){ + System.out.println("第五步 调用销毁方法"); + } + +} diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/collectiontype/Book.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/collectiontype/Book.java new file mode 100644 index 00000000..f6c2e526 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/collectiontype/Book.java @@ -0,0 +1,27 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.collectiontype; + +import java.util.List; + +/** + * @author yinkanglong + * @version : Book, v 0.1 2022-10-08 16:29 yinkanglong Exp $ + */ +public class Book { + private List bookList; + + + public void setBookList(List bookList) { + this.bookList = bookList; + } + + @Override + public String toString() { + return "Book{" + + "bookList=" + bookList + + '}'; + } +} diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/collectiontype/Course.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/collectiontype/Course.java new file mode 100644 index 00000000..e23a5e28 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/collectiontype/Course.java @@ -0,0 +1,29 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.collectiontype; + +/** + * @author yinkanglong + * @version : Course, v 0.1 2022-10-08 16:15 yinkanglong Exp $ + */ +public class Course { + private String cname; + + /** + * Setter method for property counterType. + * + * @param cname value to be assigned to property cname + */ + public void setCname(String cname) { + this.cname = cname; + } + + @Override + public String toString() { + return "Course{" + + "cname='" + cname + '\'' + + '}'; + } +} diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/collectiontype/Student.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/collectiontype/Student.java new file mode 100644 index 00000000..da96ef76 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/collectiontype/Student.java @@ -0,0 +1,61 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.collectiontype; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author yinkanglong + * @version : Student, v 0.1 2022-10-08 16:01 yinkanglong Exp $ + */ +public class Student { + private String[] courses; + + private List list; + + private Map maps; + + private Set sets; + + private List courseList; + + + public void setCourseList(List courseList) { + this.courseList = courseList; + } + + public Student() { + } + + public void setList(List list) { + this.list = list; + } + + public void setMaps(Map maps) { + this.maps = maps; + } + + public void setSets(Set sets) { + this.sets = sets; + } + + public void setCourses(String[] courses) { + this.courses = courses; + } + + @Override + public String toString() { + return "Student{" + + "courses=" + Arrays.toString(courses) + + ", list=" + list + + ", maps=" + maps + + ", sets=" + sets + + ", courseList=" + courseList + + '}'; + } +} diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/factorybean/MyBean.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/factorybean/MyBean.java new file mode 100644 index 00000000..65bb81e0 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/factorybean/MyBean.java @@ -0,0 +1,33 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.factorybean; + +import com.ykl.collectiontype.Course; +import org.hamcrest.Factory; +import org.springframework.beans.factory.FactoryBean; + +/** + * @author yinkanglong + * @version : MyBean, v 0.1 2022-10-08 16:42 yinkanglong Exp $ + */ +public class MyBean implements FactoryBean { + + //定义返回bea + @Override + public Course getObject() throws Exception { + Course course = new Course(); + return course; + } + + @Override + public Class getObjectType() { + return null; + } + + @Override + public boolean isSingleton() { + return FactoryBean.super.isSingleton(); + } +} diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test01.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test01.java new file mode 100644 index 00000000..0a55dff9 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test01.java @@ -0,0 +1,25 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +import com.ykl.collectiontype.Student; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author yinkanglong + * @version : Test01, v 0.1 2022-10-08 16:09 yinkanglong Exp $ + */ +public class Test01 { + + @Test + public void testCollection(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml"); + Student student = context.getBean("student",Student.class); + System.out.println(student); + } + +} diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test02.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test02.java new file mode 100644 index 00000000..3be68d21 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test02.java @@ -0,0 +1,26 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +import com.ykl.collectiontype.Book; +import com.ykl.collectiontype.Student; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author yinkanglong + * @version : Test01, v 0.1 2022-10-08 16:09 yinkanglong Exp $ + */ +public class Test02 { + + @Test + public void testCollection(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean02.xml"); + Book book = context.getBean("book",Book.class); + System.out.println(book); + } + +} diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test03.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test03.java new file mode 100644 index 00000000..976e3817 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test03.java @@ -0,0 +1,26 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +import com.ykl.collectiontype.Book; +import com.ykl.collectiontype.Course; +import com.ykl.factorybean.MyBean; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author yinkanglong + * @version : Test03, v 0.1 2022-10-09 09:39 yinkanglong Exp $ + */ +public class Test03 { + + @Test + public void testCollection(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean03.xml"); + Course myBean = context.getBean("mybean", Course.class); + System.out.println(myBean); + } +} diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test04.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test04.java new file mode 100644 index 00000000..706dba4f --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test04.java @@ -0,0 +1,27 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +import com.ykl.collectiontype.Book; +import com.ykl.collectiontype.Course; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author yinkanglong + * @version : Test04, v 0.1 2022-10-09 10:01 yinkanglong Exp $ + */ +public class Test04 { + @Test + public void testCollection(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean04.xml"); + Book book01 = context.getBean("book", Book.class); + System.out.println(book01.hashCode()); + + Book book02 = context.getBean("book",Book.class); + System.out.println(book02.hashCode()); + } +} diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test05.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test05.java new file mode 100644 index 00000000..8ffc5228 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test05.java @@ -0,0 +1,25 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +import com.ykl.bean.Order; +import com.ykl.collectiontype.Book; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author yinkanglong + * @version : Test05, v 0.1 2022-10-09 10:22 yinkanglong Exp $ + */ +public class Test05 { + @Test + public void testCollection(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean05.xml"); + Order order = context.getBean("order", Order.class); + System.out.println("第四步 获取bean实例对象"); + ((ClassPathXmlApplicationContext)context).close(); + } +} diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test06.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test06.java new file mode 100644 index 00000000..fc36f791 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test06.java @@ -0,0 +1,24 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +import com.ykl.autowire.Emp; +import com.ykl.bean.Order; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author yinkanglong + * @version : Test05, v 0.1 2022-10-09 10:22 yinkanglong Exp $ + */ +public class Test06 { + @Test + public void testCollection(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean06.xml"); + Emp emp = context.getBean("emp", Emp.class); + System.out.println(emp); + } +} diff --git a/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test07.java b/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test07.java new file mode 100644 index 00000000..577e94d4 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/com/ykl/test/Test07.java @@ -0,0 +1,24 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +import com.alibaba.druid.pool.DruidDataSource; +import com.ykl.autowire.Emp; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author yinkanglong + * @version : Test07, v 0.1 2022-10-09 11:27 yinkanglong Exp $ + */ +public class Test07 { + @Test + public void testCollection(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean07.xml"); + DruidDataSource dataSource = context.getBean("dataSource", DruidDataSource.class); + System.out.println(dataSource); + } +} diff --git a/Spring/Spring5/code/shangguigu03/src/jdbc.properties b/Spring/Spring5/code/shangguigu03/src/jdbc.properties new file mode 100644 index 00000000..90b61e10 --- /dev/null +++ b/Spring/Spring5/code/shangguigu03/src/jdbc.properties @@ -0,0 +1,4 @@ +prop.driverClass=com.mysql.jdbc.Driver +prop.url=jdbc:mysql://localhost:3306/user +prop.username=root +prop.password=123456 \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu04/.idea/.gitignore b/Spring/Spring5/code/shangguigu04/.idea/.gitignore new file mode 100644 index 00000000..0a8642fa --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Zeppelin ignored files +/ZeppelinRemoteNotebooks/ diff --git a/Spring/Spring5/code/shangguigu04/.idea/misc.xml b/Spring/Spring5/code/shangguigu04/.idea/misc.xml new file mode 100644 index 00000000..05483570 --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu04/.idea/modules.xml b/Spring/Spring5/code/shangguigu04/.idea/modules.xml new file mode 100644 index 00000000..e6724950 --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu04/.idea/uiDesigner.xml b/Spring/Spring5/code/shangguigu04/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu04/lib/commons-logging-1.2.jar b/Spring/Spring5/code/shangguigu04/lib/commons-logging-1.2.jar new file mode 100644 index 00000000..93a3b9f6 Binary files /dev/null and b/Spring/Spring5/code/shangguigu04/lib/commons-logging-1.2.jar differ diff --git a/Spring/Spring5/code/shangguigu04/lib/druid-1.2.13.jar b/Spring/Spring5/code/shangguigu04/lib/druid-1.2.13.jar new file mode 100644 index 00000000..9cc27d34 Binary files /dev/null and b/Spring/Spring5/code/shangguigu04/lib/druid-1.2.13.jar differ diff --git a/Spring/Spring5/code/shangguigu04/lib/spring-aop-5.3.23.jar b/Spring/Spring5/code/shangguigu04/lib/spring-aop-5.3.23.jar new file mode 100644 index 00000000..c7ee78de Binary files /dev/null and b/Spring/Spring5/code/shangguigu04/lib/spring-aop-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu04/lib/spring-beans-5.3.23.jar b/Spring/Spring5/code/shangguigu04/lib/spring-beans-5.3.23.jar new file mode 100644 index 00000000..fcc7cfd6 Binary files /dev/null and b/Spring/Spring5/code/shangguigu04/lib/spring-beans-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu04/lib/spring-context-5.3.23.jar b/Spring/Spring5/code/shangguigu04/lib/spring-context-5.3.23.jar new file mode 100644 index 00000000..e80b5da4 Binary files /dev/null and b/Spring/Spring5/code/shangguigu04/lib/spring-context-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu04/lib/spring-core-5.3.23.jar b/Spring/Spring5/code/shangguigu04/lib/spring-core-5.3.23.jar new file mode 100644 index 00000000..78ff1cae Binary files /dev/null and b/Spring/Spring5/code/shangguigu04/lib/spring-core-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu04/lib/spring-expression-5.3.23.jar b/Spring/Spring5/code/shangguigu04/lib/spring-expression-5.3.23.jar new file mode 100644 index 00000000..3d10ecea Binary files /dev/null and b/Spring/Spring5/code/shangguigu04/lib/spring-expression-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean01.xml b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean01.xml new file mode 100644 index 00000000..9375d729 --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean01.xml @@ -0,0 +1,54 @@ + + + + + + java + c + + + + + + zhangsan + xiaosan + + + + + + + + + + + + + msyql + redis + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean02.xml b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean02.xml new file mode 100644 index 00000000..fa57323d --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean02.xml @@ -0,0 +1,18 @@ + + + + + zhangsan + xiaosan + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean03.xml b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean03.xml new file mode 100644 index 00000000..86ab379c --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean03.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean04.xml b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean04.xml new file mode 100644 index 00000000..aedf8b2b --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean04.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean05.xml b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean05.xml new file mode 100644 index 00000000..ab6da799 --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean05.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean06.xml b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean06.xml new file mode 100644 index 00000000..2c1d7e0d --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean06.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean07.xml b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean07.xml new file mode 100644 index 00000000..550c2789 --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/bean07.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/jdbc.properties b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/jdbc.properties new file mode 100644 index 00000000..90b61e10 --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/out/production/shangguigu03/jdbc.properties @@ -0,0 +1,4 @@ +prop.driverClass=com.mysql.jdbc.Driver +prop.url=jdbc:mysql://localhost:3306/user +prop.username=root +prop.password=123456 \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu04/out/production/shangguigu04/bean01.xml b/Spring/Spring5/code/shangguigu04/out/production/shangguigu04/bean01.xml new file mode 100644 index 00000000..6cb049f4 --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/out/production/shangguigu04/bean01.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu04/out/production/shangguigu04/jdbc.properties b/Spring/Spring5/code/shangguigu04/out/production/shangguigu04/jdbc.properties new file mode 100644 index 00000000..90b61e10 --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/out/production/shangguigu04/jdbc.properties @@ -0,0 +1,4 @@ +prop.driverClass=com.mysql.jdbc.Driver +prop.url=jdbc:mysql://localhost:3306/user +prop.username=root +prop.password=123456 \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu04/shangguigu04.iml b/Spring/Spring5/code/shangguigu04/shangguigu04.iml new file mode 100644 index 00000000..ca06320e --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/shangguigu04.iml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu04/src/Main.java b/Spring/Spring5/code/shangguigu04/src/Main.java new file mode 100644 index 00000000..7cf1a648 --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/src/Main.java @@ -0,0 +1,9 @@ +/** + * @author yinkanglong + * @version $Id: ${NAME}, v 0.1 ${YEAR}-${MONTH}-${DAY} ${TIME} yinkanglong Exp $ + */ +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu04/src/bean01.xml b/Spring/Spring5/code/shangguigu04/src/bean01.xml new file mode 100644 index 00000000..6cb049f4 --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/src/bean01.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu04/src/com/ykl/config/SpringConfig.java b/Spring/Spring5/code/shangguigu04/src/com/ykl/config/SpringConfig.java new file mode 100644 index 00000000..29b0f0da --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/src/com/ykl/config/SpringConfig.java @@ -0,0 +1,19 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; + +/** + * @author yinkanglong + * @version : SpringConfig, v 0.1 2022-10-09 13:18 yinkanglong Exp $ + */ +@Configuration +@ComponentScan(basePackages = {"com.ykl"}) +public class SpringConfig { + +} diff --git a/Spring/Spring5/code/shangguigu04/src/com/ykl/dao/UserDo.java b/Spring/Spring5/code/shangguigu04/src/com/ykl/dao/UserDo.java new file mode 100644 index 00000000..882bddd9 --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/src/com/ykl/dao/UserDo.java @@ -0,0 +1,13 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.dao; + +/** + * @author yinkanglong + * @version : UserDo, v 0.1 2022-10-09 12:03 yinkanglong Exp $ + */ +public interface UserDo { + public void add(); +} diff --git a/Spring/Spring5/code/shangguigu04/src/com/ykl/dao/UserDoImpl.java b/Spring/Spring5/code/shangguigu04/src/com/ykl/dao/UserDoImpl.java new file mode 100644 index 00000000..4aa08f64 --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/src/com/ykl/dao/UserDoImpl.java @@ -0,0 +1,19 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.dao; + +import org.springframework.stereotype.Repository; + +/** + * @author yinkanglong + * @version : UserDoImpl, v 0.1 2022-10-09 12:04 yinkanglong Exp $ + */ +@Repository +public class UserDoImpl implements UserDo{ + @Override + public void add() { + System.out.println("dao add ... ..."); + } +} diff --git a/Spring/Spring5/code/shangguigu04/src/com/ykl/service/UserService.java b/Spring/Spring5/code/shangguigu04/src/com/ykl/service/UserService.java new file mode 100644 index 00000000..be37815c --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/src/com/ykl/service/UserService.java @@ -0,0 +1,28 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.service; + +import com.ykl.dao.UserDo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +/** + * 与xml配置等价,value值可以省略不写 + * 默认值是类名称,首字母小写。 + */ +@Service +public class UserService { + + @Autowired + @Qualifier(value = "userDoImpl") + private UserDo userDo; + public void add(){ + System.out.println("service add ... ..."); + + userDo.add(); + } +} diff --git a/Spring/Spring5/code/shangguigu04/src/com/ykl/test/Test01.java b/Spring/Spring5/code/shangguigu04/src/com/ykl/test/Test01.java new file mode 100644 index 00000000..b762d22b --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/src/com/ykl/test/Test01.java @@ -0,0 +1,36 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +import com.ykl.config.SpringConfig; +import com.ykl.service.UserService; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author yinkanglong + * @version : Test01, v 0.1 2022-10-08 16:09 yinkanglong Exp $ + */ +public class Test01 { + + @Test + public void testService(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml"); + UserService userService = context.getBean("userService", UserService.class); + userService.add(); + } + + + @Test + public void testConfig(){ + //加载配置类 + ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class); + UserService userService = context.getBean("userService", UserService.class); + userService.add(); + } + +} diff --git a/Spring/Spring5/code/shangguigu04/src/jdbc.properties b/Spring/Spring5/code/shangguigu04/src/jdbc.properties new file mode 100644 index 00000000..90b61e10 --- /dev/null +++ b/Spring/Spring5/code/shangguigu04/src/jdbc.properties @@ -0,0 +1,4 @@ +prop.driverClass=com.mysql.jdbc.Driver +prop.url=jdbc:mysql://localhost:3306/user +prop.username=root +prop.password=123456 \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu05/.idea/.gitignore b/Spring/Spring5/code/shangguigu05/.idea/.gitignore new file mode 100644 index 00000000..0a8642fa --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Zeppelin ignored files +/ZeppelinRemoteNotebooks/ diff --git a/Spring/Spring5/code/shangguigu05/.idea/misc.xml b/Spring/Spring5/code/shangguigu05/.idea/misc.xml new file mode 100644 index 00000000..05483570 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu05/.idea/modules.xml b/Spring/Spring5/code/shangguigu05/.idea/modules.xml new file mode 100644 index 00000000..fb234afc --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu05/.idea/uiDesigner.xml b/Spring/Spring5/code/shangguigu05/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu05/lib/aopalliance-1.0.jar b/Spring/Spring5/code/shangguigu05/lib/aopalliance-1.0.jar new file mode 100644 index 00000000..578b1a0c Binary files /dev/null and b/Spring/Spring5/code/shangguigu05/lib/aopalliance-1.0.jar differ diff --git a/Spring/Spring5/code/shangguigu05/lib/aspectjweaver-1.9.9.1.jar b/Spring/Spring5/code/shangguigu05/lib/aspectjweaver-1.9.9.1.jar new file mode 100644 index 00000000..4a1b98cc Binary files /dev/null and b/Spring/Spring5/code/shangguigu05/lib/aspectjweaver-1.9.9.1.jar differ diff --git a/Spring/Spring5/code/shangguigu05/lib/cglib-3.3.0.jar b/Spring/Spring5/code/shangguigu05/lib/cglib-3.3.0.jar new file mode 100644 index 00000000..ed830f40 Binary files /dev/null and b/Spring/Spring5/code/shangguigu05/lib/cglib-3.3.0.jar differ diff --git a/Spring/Spring5/code/shangguigu05/lib/commons-logging-1.2.jar b/Spring/Spring5/code/shangguigu05/lib/commons-logging-1.2.jar new file mode 100644 index 00000000..93a3b9f6 Binary files /dev/null and b/Spring/Spring5/code/shangguigu05/lib/commons-logging-1.2.jar differ diff --git a/Spring/Spring5/code/shangguigu05/lib/druid-1.2.13.jar b/Spring/Spring5/code/shangguigu05/lib/druid-1.2.13.jar new file mode 100644 index 00000000..9cc27d34 Binary files /dev/null and b/Spring/Spring5/code/shangguigu05/lib/druid-1.2.13.jar differ diff --git a/Spring/Spring5/code/shangguigu05/lib/spring-aop-5.3.23.jar b/Spring/Spring5/code/shangguigu05/lib/spring-aop-5.3.23.jar new file mode 100644 index 00000000..c7ee78de Binary files /dev/null and b/Spring/Spring5/code/shangguigu05/lib/spring-aop-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu05/lib/spring-aspects-5.3.23.jar b/Spring/Spring5/code/shangguigu05/lib/spring-aspects-5.3.23.jar new file mode 100644 index 00000000..3857b886 Binary files /dev/null and b/Spring/Spring5/code/shangguigu05/lib/spring-aspects-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu05/lib/spring-beans-5.3.23.jar b/Spring/Spring5/code/shangguigu05/lib/spring-beans-5.3.23.jar new file mode 100644 index 00000000..fcc7cfd6 Binary files /dev/null and b/Spring/Spring5/code/shangguigu05/lib/spring-beans-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu05/lib/spring-context-5.3.23.jar b/Spring/Spring5/code/shangguigu05/lib/spring-context-5.3.23.jar new file mode 100644 index 00000000..e80b5da4 Binary files /dev/null and b/Spring/Spring5/code/shangguigu05/lib/spring-context-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu05/lib/spring-core-5.3.23.jar b/Spring/Spring5/code/shangguigu05/lib/spring-core-5.3.23.jar new file mode 100644 index 00000000..78ff1cae Binary files /dev/null and b/Spring/Spring5/code/shangguigu05/lib/spring-core-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu05/lib/spring-expression-5.3.23.jar b/Spring/Spring5/code/shangguigu05/lib/spring-expression-5.3.23.jar new file mode 100644 index 00000000..3d10ecea Binary files /dev/null and b/Spring/Spring5/code/shangguigu05/lib/spring-expression-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean01.xml b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean01.xml new file mode 100644 index 00000000..9375d729 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean01.xml @@ -0,0 +1,54 @@ + + + + + + java + c + + + + + + zhangsan + xiaosan + + + + + + + + + + + + + msyql + redis + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean02.xml b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean02.xml new file mode 100644 index 00000000..fa57323d --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean02.xml @@ -0,0 +1,18 @@ + + + + + zhangsan + xiaosan + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean03.xml b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean03.xml new file mode 100644 index 00000000..86ab379c --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean03.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean04.xml b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean04.xml new file mode 100644 index 00000000..aedf8b2b --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean04.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean05.xml b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean05.xml new file mode 100644 index 00000000..ab6da799 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean05.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean06.xml b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean06.xml new file mode 100644 index 00000000..2c1d7e0d --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean06.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean07.xml b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean07.xml new file mode 100644 index 00000000..550c2789 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/bean07.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/jdbc.properties b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/jdbc.properties new file mode 100644 index 00000000..90b61e10 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/out/production/shangguigu03/jdbc.properties @@ -0,0 +1,4 @@ +prop.driverClass=com.mysql.jdbc.Driver +prop.url=jdbc:mysql://localhost:3306/user +prop.username=root +prop.password=123456 \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu05/out/production/shangguigu04/bean01.xml b/Spring/Spring5/code/shangguigu05/out/production/shangguigu04/bean01.xml new file mode 100644 index 00000000..6cb049f4 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/out/production/shangguigu04/bean01.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu05/out/production/shangguigu04/jdbc.properties b/Spring/Spring5/code/shangguigu05/out/production/shangguigu04/jdbc.properties new file mode 100644 index 00000000..90b61e10 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/out/production/shangguigu04/jdbc.properties @@ -0,0 +1,4 @@ +prop.driverClass=com.mysql.jdbc.Driver +prop.url=jdbc:mysql://localhost:3306/user +prop.username=root +prop.password=123456 \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu05/out/production/shangguigu05/bean01.xml b/Spring/Spring5/code/shangguigu05/out/production/shangguigu05/bean01.xml new file mode 100644 index 00000000..6cb049f4 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/out/production/shangguigu05/bean01.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu05/out/production/shangguigu05/bean02.xml b/Spring/Spring5/code/shangguigu05/out/production/shangguigu05/bean02.xml new file mode 100644 index 00000000..5e9fab43 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/out/production/shangguigu05/bean02.xml @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu05/out/production/shangguigu05/bean03.xml b/Spring/Spring5/code/shangguigu05/out/production/shangguigu05/bean03.xml new file mode 100644 index 00000000..73c58296 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/out/production/shangguigu05/bean03.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu05/out/production/shangguigu05/jdbc.properties b/Spring/Spring5/code/shangguigu05/out/production/shangguigu05/jdbc.properties new file mode 100644 index 00000000..90b61e10 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/out/production/shangguigu05/jdbc.properties @@ -0,0 +1,4 @@ +prop.driverClass=com.mysql.jdbc.Driver +prop.url=jdbc:mysql://localhost:3306/user +prop.username=root +prop.password=123456 \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu05/shangguigu05.iml b/Spring/Spring5/code/shangguigu05/shangguigu05.iml new file mode 100644 index 00000000..ec0f6558 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/shangguigu05.iml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu05/src/Main.java b/Spring/Spring5/code/shangguigu05/src/Main.java new file mode 100644 index 00000000..7cf1a648 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/Main.java @@ -0,0 +1,9 @@ +/** + * @author yinkanglong + * @version $Id: ${NAME}, v 0.1 ${YEAR}-${MONTH}-${DAY} ${TIME} yinkanglong Exp $ + */ +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu05/src/bean01.xml b/Spring/Spring5/code/shangguigu05/src/bean01.xml new file mode 100644 index 00000000..6cb049f4 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/bean01.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu05/src/bean02.xml b/Spring/Spring5/code/shangguigu05/src/bean02.xml new file mode 100644 index 00000000..5e9fab43 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/bean02.xml @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu05/src/bean03.xml b/Spring/Spring5/code/shangguigu05/src/bean03.xml new file mode 100644 index 00000000..73c58296 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/bean03.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu05/src/com/ykl/aopanno/PersonProxy.java b/Spring/Spring5/code/shangguigu05/src/com/ykl/aopanno/PersonProxy.java new file mode 100644 index 00000000..b155b501 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/com/ykl/aopanno/PersonProxy.java @@ -0,0 +1,33 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.aopanno; + +import org.aspectj.lang.annotation.After; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +/** + * @author yinkanglong + * @version : PersonProxy, v 0.1 2022-10-09 16:01 yinkanglong Exp $ + */ +@Component +@Aspect +@Order(1) +public class PersonProxy { + + + //前置通知 + @Before(value = "execution(* com.ykl.aopanno.User.add(..))") + public void before(){ + System.out.println("执行前..."); + } + + @After(value = "execution(* com.ykl.aopanno.User.add(..))") + public void after(){ + System.out.println("after..."); + } +} diff --git a/Spring/Spring5/code/shangguigu05/src/com/ykl/aopanno/User.java b/Spring/Spring5/code/shangguigu05/src/com/ykl/aopanno/User.java new file mode 100644 index 00000000..44c9d510 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/com/ykl/aopanno/User.java @@ -0,0 +1,18 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.aopanno; + +import org.springframework.stereotype.Component; + +/** + * @author yinkanglong + * @version : User, v 0.1 2022-10-09 15:16 yinkanglong Exp $ + */ +@Component +public class User { + public void add(){ + System.out.println("User add ..."); + } +} diff --git a/Spring/Spring5/code/shangguigu05/src/com/ykl/aopanno/UserProxy.java b/Spring/Spring5/code/shangguigu05/src/com/ykl/aopanno/UserProxy.java new file mode 100644 index 00000000..1aae84da --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/com/ykl/aopanno/UserProxy.java @@ -0,0 +1,49 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.aopanno; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.*; +import org.springframework.stereotype.Component; + +/** + * @author yinkanglong + * @version : UserProxy, v 0.1 2022-10-09 15:16 yinkanglong Exp $ + */ +@Component +@Aspect +public class UserProxy { + + //前置通知 + @Before(value = "execution(* com.ykl.aopanno.User.add(..))") + public void before(){ + System.out.println("执行前..."); + } + + @After(value = "execution(* com.ykl.aopanno.User.add(..))") + public void after(){ + System.out.println("after..."); + } + + @AfterReturning(value = "execution(* com.ykl.aopanno.User.add(..))") + public void afterReturn(){ + System.out.println("afterReturn..."); + } + + @AfterThrowing(value = "execution(* com.ykl.aopanno.User.add(..))") + public void afterThrow(){ + System.out.println("afterThrow..."); + } + + @Around(value = "execution(* com.ykl.aopanno.User.add(..))") + public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{ + System.out.println("环绕之前...."); + + proceedingJoinPoint.proceed(); + + System.out.println("环绕之后...."); + } + +} diff --git a/Spring/Spring5/code/shangguigu05/src/com/ykl/aopxml/Book.java b/Spring/Spring5/code/shangguigu05/src/com/ykl/aopxml/Book.java new file mode 100644 index 00000000..16e0e54a --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/com/ykl/aopxml/Book.java @@ -0,0 +1,15 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.aopxml; + +/** + * @author yinkanglong + * @version : Book, v 0.1 2022-10-09 16:06 yinkanglong Exp $ + */ +public class Book { + public void add(){ + System.out.println("Book add ..."); + } +} diff --git a/Spring/Spring5/code/shangguigu05/src/com/ykl/aopxml/BookProxy.java b/Spring/Spring5/code/shangguigu05/src/com/ykl/aopxml/BookProxy.java new file mode 100644 index 00000000..abe07570 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/com/ykl/aopxml/BookProxy.java @@ -0,0 +1,15 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.aopxml; + +/** + * @author yinkanglong + * @version : BookProxy, v 0.1 2022-10-09 16:06 yinkanglong Exp $ + */ +public class BookProxy { + public void before(){ + System.out.println("before ......"); + } +} diff --git a/Spring/Spring5/code/shangguigu05/src/com/ykl/dao/JDKProxy.java b/Spring/Spring5/code/shangguigu05/src/com/ykl/dao/JDKProxy.java new file mode 100644 index 00000000..d24d1f6f --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/com/ykl/dao/JDKProxy.java @@ -0,0 +1,48 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.dao; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +/** + * @author yinkanglong + * @version : JDKProxy, v 0.1 2022-10-09 14:31 yinkanglong Exp $ + */ +public class JDKProxy { + public static void main(String[] args) { + Class[] interfaces = {UserDo.class}; + +// Proxy.newProxyInstance(JDKProxy.class.getClassLoader(), interfaces, new InvocationHandler() { +// @Override +// public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { +// return null; +// } +// }); + + UserDoImpl userDo = new UserDoImpl(); + UserDo dao = (UserDo)Proxy.newProxyInstance(JDKProxy.class.getClassLoader(),interfaces,new UserDaoProxy(userDo)); + int result = dao.add(1,2); + System.out.println("结束"); + } +} +class UserDaoProxy implements InvocationHandler{ + Object object; + //把被代理的对象,传递进来。通过有参构造进行传递 + public UserDaoProxy(Object object){ + this.object=object; + } + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + System.out.println("方法之前的执行"+method.getName()); + + Object res = method.invoke(object,args); + + System.out.println("方法执行后"); + + return res; + } +} diff --git a/Spring/Spring5/code/shangguigu05/src/com/ykl/dao/UserDo.java b/Spring/Spring5/code/shangguigu05/src/com/ykl/dao/UserDo.java new file mode 100644 index 00000000..680bf22e --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/com/ykl/dao/UserDo.java @@ -0,0 +1,14 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.dao; + +/** + * @author yinkanglong + * @version : UserDo, v 0.1 2022-10-09 12:03 yinkanglong Exp $ + */ +public interface UserDo { + public int add(int a,int b); + public String update(String id); +} diff --git a/Spring/Spring5/code/shangguigu05/src/com/ykl/dao/UserDoImpl.java b/Spring/Spring5/code/shangguigu05/src/com/ykl/dao/UserDoImpl.java new file mode 100644 index 00000000..c4439cd2 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/com/ykl/dao/UserDoImpl.java @@ -0,0 +1,26 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.dao; + +import org.springframework.stereotype.Repository; + +/** + * @author yinkanglong + * @version : UserDoImpl, v 0.1 2022-10-09 12:04 yinkanglong Exp $ + */ +@Repository +public class UserDoImpl implements UserDo{ + + @Override + public int add(int a, int b) { + System.out.println("add 方法执行了"); + return a+b; + } + + @Override + public String update(String id) { + return id; + } +} diff --git a/Spring/Spring5/code/shangguigu05/src/com/ykl/test/Test01.java b/Spring/Spring5/code/shangguigu05/src/com/ykl/test/Test01.java new file mode 100644 index 00000000..c6e92f23 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/com/ykl/test/Test01.java @@ -0,0 +1,15 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +/** + * @author yinkanglong + * @version : Test01, v 0.1 2022-10-08 16:09 yinkanglong Exp $ + */ +public class Test01 { + + + +} diff --git a/Spring/Spring5/code/shangguigu05/src/com/ykl/test/Test02.java b/Spring/Spring5/code/shangguigu05/src/com/ykl/test/Test02.java new file mode 100644 index 00000000..8f0cde9c --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/com/ykl/test/Test02.java @@ -0,0 +1,32 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +import com.ykl.aopanno.User; +import com.ykl.aopxml.Book; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author yinkanglong + * @version : Test02, v 0.1 2022-10-09 15:28 yinkanglong Exp $ + */ +public class Test02 { + + @Test + public void testAop(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean02.xml"); + User user = context.getBean("user", User.class); + user.add(); + } + + @Test + public void testAopXml(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean03.xml"); + Book book = context.getBean("book", Book.class); + book.add(); + } +} diff --git a/Spring/Spring5/code/shangguigu05/src/jdbc.properties b/Spring/Spring5/code/shangguigu05/src/jdbc.properties new file mode 100644 index 00000000..90b61e10 --- /dev/null +++ b/Spring/Spring5/code/shangguigu05/src/jdbc.properties @@ -0,0 +1,4 @@ +prop.driverClass=com.mysql.jdbc.Driver +prop.url=jdbc:mysql://localhost:3306/user +prop.username=root +prop.password=123456 \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu06/.idea/.gitignore b/Spring/Spring5/code/shangguigu06/.idea/.gitignore new file mode 100644 index 00000000..0a8642fa --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Zeppelin ignored files +/ZeppelinRemoteNotebooks/ diff --git a/Spring/Spring5/code/shangguigu06/.idea/misc.xml b/Spring/Spring5/code/shangguigu06/.idea/misc.xml new file mode 100644 index 00000000..05483570 --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu06/.idea/modules.xml b/Spring/Spring5/code/shangguigu06/.idea/modules.xml new file mode 100644 index 00000000..1a1f9328 --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu06/.idea/uiDesigner.xml b/Spring/Spring5/code/shangguigu06/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu06/lib/aopalliance-1.0.jar b/Spring/Spring5/code/shangguigu06/lib/aopalliance-1.0.jar new file mode 100644 index 00000000..578b1a0c Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/aopalliance-1.0.jar differ diff --git a/Spring/Spring5/code/shangguigu06/lib/aspectjweaver-1.9.9.1.jar b/Spring/Spring5/code/shangguigu06/lib/aspectjweaver-1.9.9.1.jar new file mode 100644 index 00000000..4a1b98cc Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/aspectjweaver-1.9.9.1.jar differ diff --git a/Spring/Spring5/code/shangguigu06/lib/cglib-3.3.0.jar b/Spring/Spring5/code/shangguigu06/lib/cglib-3.3.0.jar new file mode 100644 index 00000000..ed830f40 Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/cglib-3.3.0.jar differ diff --git a/Spring/Spring5/code/shangguigu06/lib/commons-logging-1.2.jar b/Spring/Spring5/code/shangguigu06/lib/commons-logging-1.2.jar new file mode 100644 index 00000000..93a3b9f6 Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/commons-logging-1.2.jar differ diff --git a/Spring/Spring5/code/shangguigu06/lib/druid-1.2.13.jar b/Spring/Spring5/code/shangguigu06/lib/druid-1.2.13.jar new file mode 100644 index 00000000..9cc27d34 Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/druid-1.2.13.jar differ diff --git a/Spring/Spring5/code/shangguigu06/lib/mysql-connector-java-8.0.30.jar b/Spring/Spring5/code/shangguigu06/lib/mysql-connector-java-8.0.30.jar new file mode 100644 index 00000000..92ebe1b5 Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/mysql-connector-java-8.0.30.jar differ diff --git a/Spring/Spring5/code/shangguigu06/lib/spring-aop-5.3.23.jar b/Spring/Spring5/code/shangguigu06/lib/spring-aop-5.3.23.jar new file mode 100644 index 00000000..c7ee78de Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/spring-aop-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu06/lib/spring-aspects-5.3.23.jar b/Spring/Spring5/code/shangguigu06/lib/spring-aspects-5.3.23.jar new file mode 100644 index 00000000..3857b886 Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/spring-aspects-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu06/lib/spring-beans-5.3.23.jar b/Spring/Spring5/code/shangguigu06/lib/spring-beans-5.3.23.jar new file mode 100644 index 00000000..fcc7cfd6 Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/spring-beans-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu06/lib/spring-context-5.3.23.jar b/Spring/Spring5/code/shangguigu06/lib/spring-context-5.3.23.jar new file mode 100644 index 00000000..e80b5da4 Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/spring-context-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu06/lib/spring-core-5.3.23.jar b/Spring/Spring5/code/shangguigu06/lib/spring-core-5.3.23.jar new file mode 100644 index 00000000..78ff1cae Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/spring-core-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu06/lib/spring-expression-5.3.23.jar b/Spring/Spring5/code/shangguigu06/lib/spring-expression-5.3.23.jar new file mode 100644 index 00000000..3d10ecea Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/spring-expression-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu06/lib/spring-jdbc-5.3.23.jar b/Spring/Spring5/code/shangguigu06/lib/spring-jdbc-5.3.23.jar new file mode 100644 index 00000000..2322be71 Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/spring-jdbc-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu06/lib/spring-orm-5.3.23.jar b/Spring/Spring5/code/shangguigu06/lib/spring-orm-5.3.23.jar new file mode 100644 index 00000000..b4fed3ea Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/spring-orm-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu06/lib/spring-tx-5.3.23.jar b/Spring/Spring5/code/shangguigu06/lib/spring-tx-5.3.23.jar new file mode 100644 index 00000000..aad7465e Binary files /dev/null and b/Spring/Spring5/code/shangguigu06/lib/spring-tx-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu06/out/production/shangguigu06/bean01.xml b/Spring/Spring5/code/shangguigu06/out/production/shangguigu06/bean01.xml new file mode 100644 index 00000000..47172250 --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/out/production/shangguigu06/bean01.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu06/out/production/shangguigu06/jdbc.properties b/Spring/Spring5/code/shangguigu06/out/production/shangguigu06/jdbc.properties new file mode 100644 index 00000000..90b61e10 --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/out/production/shangguigu06/jdbc.properties @@ -0,0 +1,4 @@ +prop.driverClass=com.mysql.jdbc.Driver +prop.url=jdbc:mysql://localhost:3306/user +prop.username=root +prop.password=123456 \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu06/shangguigu06.iml b/Spring/Spring5/code/shangguigu06/shangguigu06.iml new file mode 100644 index 00000000..d7273c0e --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/shangguigu06.iml @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu06/src/Main.java b/Spring/Spring5/code/shangguigu06/src/Main.java new file mode 100644 index 00000000..7cf1a648 --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/src/Main.java @@ -0,0 +1,9 @@ +/** + * @author yinkanglong + * @version $Id: ${NAME}, v 0.1 ${YEAR}-${MONTH}-${DAY} ${TIME} yinkanglong Exp $ + */ +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu06/src/bean01.xml b/Spring/Spring5/code/shangguigu06/src/bean01.xml new file mode 100644 index 00000000..47172250 --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/src/bean01.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu06/src/com/ykl/dao/UserDao.java b/Spring/Spring5/code/shangguigu06/src/com/ykl/dao/UserDao.java new file mode 100644 index 00000000..9542c662 --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/src/com/ykl/dao/UserDao.java @@ -0,0 +1,30 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.dao; + +import com.ykl.entity.User; + +import java.awt.print.Book; +import java.util.List; + +/** + * @author yinkanglong + * @version : UserDo, v 0.1 2022-10-09 12:03 yinkanglong Exp $ + */ +public interface UserDao { + public int addUser(User user); + + public void updateUser(User user); + + public void delete(String id); + + int selectCount(); + + User findUserInfo(String id); + + List findAll(); + + void batchAdd(List batchArgs); +} diff --git a/Spring/Spring5/code/shangguigu06/src/com/ykl/dao/UserDaoImpl.java b/Spring/Spring5/code/shangguigu06/src/com/ykl/dao/UserDaoImpl.java new file mode 100644 index 00000000..dcbfa4ac --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/src/com/ykl/dao/UserDaoImpl.java @@ -0,0 +1,96 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.dao; + +import com.mysql.cj.result.Row; +import com.ykl.entity.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; + +import java.util.Arrays; +import java.util.List; + +/** + * @author yinkanglong + * @version : UserDoImpl, v 0.1 2022-10-09 12:04 yinkanglong Exp $ + */ +@Repository +public class UserDaoImpl implements UserDao { + + @Autowired + private JdbcTemplate jdbcTemplate; + + @Override + public int addUser(User user) { + String sql = "insert into user values(?,?,?)"; + Object[] args = {user.getUserId(),user.getUsername(),user.getUserStatus()}; + + int update = jdbcTemplate.update(sql,args); + System.out.println(update); + return update; + } + + @Override + public void updateUser(User user) { + String sql = "update user set username=?,userstatus=? where userid=?"; + Object[] args = {user.getUsername(),user.getUserStatus(),user.getUserId()}; + + int update = jdbcTemplate.update(sql,args); + System.out.println(update); + return ; + } + + @Override + public void delete(String id) { + String sql = "delete from user where userid=?"; + Object[] args = {id,}; + + int update = jdbcTemplate.update(sql,args); + System.out.println(update); + return ; + } + + + /** + * 查询返回整数 + * @return + */ + @Override + public int selectCount(){ + String sql = "select count(*) from user"; + Integer count = jdbcTemplate.queryForObject(sql,Integer.class); + return count; + } + + /** + * 查询返回单个记录 + * @param id + * @return + */ + @Override + public User findUserInfo(String id){ + String sql = "select * from user where userid=?"; + User user = jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper(User.class),id); + return user; + } + + @Override + public List findAll() { + String sql = "select * from user"; + List users = jdbcTemplate.query(sql, new BeanPropertyRowMapper(User.class)); + return users; + } + + @Override + public void batchAdd(List batchArgs) { + String sql = "insert into user values(?,?,?)"; + int [] ints = jdbcTemplate.batchUpdate(sql,batchArgs); + System.out.println(Arrays.toString(ints)); + } + + +} diff --git a/Spring/Spring5/code/shangguigu06/src/com/ykl/entity/User.java b/Spring/Spring5/code/shangguigu06/src/com/ykl/entity/User.java new file mode 100644 index 00000000..9aa4bdf2 --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/src/com/ykl/entity/User.java @@ -0,0 +1,78 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.entity; + +/** + * @author yinkanglong + * @version : User, v 0.1 2022-10-10 09:14 yinkanglong Exp $ + */ +public class User { + private String userId; + private String username; + private String userStatus; + + /** + * Getter method for property userId. + * + * @return property value of userId + */ + public String getUserId() { + return userId; + } + + /** + * Setter method for property counterType. + * + * @param userId value to be assigned to property userId + */ + public void setUserId(String userId) { + this.userId = userId; + } + + /** + * Getter method for property username. + * + * @return property value of username + */ + public String getUsername() { + return username; + } + + /** + * Setter method for property counterType. + * + * @param username value to be assigned to property username + */ + public void setUsername(String username) { + this.username = username; + } + + /** + * Getter method for property userStatus. + * + * @return property value of userStatus + */ + public String getUserStatus() { + return userStatus; + } + + /** + * Setter method for property counterType. + * + * @param userStatus value to be assigned to property userStatus + */ + public void setUserStatus(String userStatus) { + this.userStatus = userStatus; + } + + @Override + public String toString() { + return "User{" + + "userId='" + userId + '\'' + + ", username='" + username + '\'' + + ", userStatus='" + userStatus + '\'' + + '}'; + } +} diff --git a/Spring/Spring5/code/shangguigu06/src/com/ykl/service/UserService.java b/Spring/Spring5/code/shangguigu06/src/com/ykl/service/UserService.java new file mode 100644 index 00000000..a14498d6 --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/src/com/ykl/service/UserService.java @@ -0,0 +1,52 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.service; + +import com.ykl.dao.UserDao; +import com.ykl.entity.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.awt.print.Book; +import java.util.List; + +/** + * @author yinkanglong + * @version : UserService, v 0.1 2022-10-10 09:05 yinkanglong Exp $ + */ +@Service +public class UserService { + @Autowired + private UserDao userDao; + + public void addUser(User user){ + userDao.addUser(user); + } + + public void updateUser(User user){ + userDao.updateUser(user); + } + + public void deleteUser(String id){ + userDao.delete(id); + } + + public int findCount(){ + int number = userDao.selectCount(); + return number; + } + public User findOne(String id){ + return userDao.findUserInfo(id); + } + + public List findAll(){ + return userDao.findAll(); + } + + + public void batchAdd(List batchArgs){ + userDao.batchAdd(batchArgs); + } +} diff --git a/Spring/Spring5/code/shangguigu06/src/com/ykl/test/Test01.java b/Spring/Spring5/code/shangguigu06/src/com/ykl/test/Test01.java new file mode 100644 index 00000000..909ae7a4 --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/src/com/ykl/test/Test01.java @@ -0,0 +1,105 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +import com.ykl.entity.User; +import com.ykl.service.UserService; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import sun.security.util.ArrayUtil; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author yinkanglong + * @version : Test01, v 0.1 2022-10-08 16:09 yinkanglong Exp $ + */ +public class Test01 { + + + @Test + public void testAdd(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml"); + UserService userService = context.getBean("userService",UserService.class); + User user = new User(); + user.setUserId("123"); + user.setUsername("yinkanglong"); + user.setUserStatus("up"); + userService.addUser(user); + } + + @Test + public void testUpdate(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml"); + UserService userService = context.getBean("userService",UserService.class); + User user = new User(); + user.setUserId("1"); + user.setUsername("ykl1"); + user.setUserStatus("up1"); + userService.addUser(user); + + user.setUserStatus("down1"); + userService.updateUser(user); + + } + + @Test + public void testDelete(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml"); + UserService userService = context.getBean("userService",UserService.class); + User user = new User(); + user.setUserId("2"); + user.setUsername("ykl2"); + user.setUserStatus("up2"); + userService.addUser(user); + + userService.deleteUser(user.getUserId()); + } + + + @Test + public void testFindCount(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml"); + UserService userService = context.getBean("userService",UserService.class); + int num = userService.findCount(); + System.out.println(num); + } + + @Test + public void testFindOne(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml"); + UserService userService = context.getBean("userService",UserService.class); + User user = userService.findOne("123"); + System.out.println(user); + } + + @Test + public void testFindAll(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml"); + UserService userService = context.getBean("userService",UserService.class); + List users = userService.findAll(); + System.out.println(users); + } + + @Test + public void testBatchAdd(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml"); + UserService userService = context.getBean("userService",UserService.class); + + + List batchArgs = new ArrayList<>(); + + Object[] o1 = {"111","java","a"}; + Object[] o2 = {"222","c++","b"}; + Object[] o3 = {"333","mysql","c"}; + batchArgs.add(o1); + batchArgs.add(o2); + batchArgs.add(o3); + + userService.batchAdd(batchArgs); + } +} diff --git a/Spring/Spring5/code/shangguigu06/src/jdbc.properties b/Spring/Spring5/code/shangguigu06/src/jdbc.properties new file mode 100644 index 00000000..90b61e10 --- /dev/null +++ b/Spring/Spring5/code/shangguigu06/src/jdbc.properties @@ -0,0 +1,4 @@ +prop.driverClass=com.mysql.jdbc.Driver +prop.url=jdbc:mysql://localhost:3306/user +prop.username=root +prop.password=123456 \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu07/.idea/.gitignore b/Spring/Spring5/code/shangguigu07/.idea/.gitignore new file mode 100644 index 00000000..0a8642fa --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Zeppelin ignored files +/ZeppelinRemoteNotebooks/ diff --git a/Spring/Spring5/code/shangguigu07/.idea/misc.xml b/Spring/Spring5/code/shangguigu07/.idea/misc.xml new file mode 100644 index 00000000..05483570 --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu07/.idea/modules.xml b/Spring/Spring5/code/shangguigu07/.idea/modules.xml new file mode 100644 index 00000000..2f10bd9a --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu07/.idea/uiDesigner.xml b/Spring/Spring5/code/shangguigu07/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu07/lib/aopalliance-1.0.jar b/Spring/Spring5/code/shangguigu07/lib/aopalliance-1.0.jar new file mode 100644 index 00000000..578b1a0c Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/aopalliance-1.0.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/aspectjweaver-1.9.9.1.jar b/Spring/Spring5/code/shangguigu07/lib/aspectjweaver-1.9.9.1.jar new file mode 100644 index 00000000..4a1b98cc Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/aspectjweaver-1.9.9.1.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/cglib-3.3.0.jar b/Spring/Spring5/code/shangguigu07/lib/cglib-3.3.0.jar new file mode 100644 index 00000000..ed830f40 Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/cglib-3.3.0.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/commons-logging-1.2.jar b/Spring/Spring5/code/shangguigu07/lib/commons-logging-1.2.jar new file mode 100644 index 00000000..93a3b9f6 Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/commons-logging-1.2.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/druid-1.2.13.jar b/Spring/Spring5/code/shangguigu07/lib/druid-1.2.13.jar new file mode 100644 index 00000000..9cc27d34 Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/druid-1.2.13.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/log4j-api-2.11.2.jar b/Spring/Spring5/code/shangguigu07/lib/log4j-api-2.11.2.jar new file mode 100644 index 00000000..809773c0 Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/log4j-api-2.11.2.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/log4j-core-2.11.2.jar b/Spring/Spring5/code/shangguigu07/lib/log4j-core-2.11.2.jar new file mode 100644 index 00000000..dcb652cb Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/log4j-core-2.11.2.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/log4j-slf4j-impl-2.11.2.jar b/Spring/Spring5/code/shangguigu07/lib/log4j-slf4j-impl-2.11.2.jar new file mode 100644 index 00000000..ce8acdaa Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/log4j-slf4j-impl-2.11.2.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/mysql-connector-java-8.0.30.jar b/Spring/Spring5/code/shangguigu07/lib/mysql-connector-java-8.0.30.jar new file mode 100644 index 00000000..92ebe1b5 Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/mysql-connector-java-8.0.30.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/slf4j-api-1.7.30.jar b/Spring/Spring5/code/shangguigu07/lib/slf4j-api-1.7.30.jar new file mode 100644 index 00000000..29ac26fb Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/slf4j-api-1.7.30.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/spring-aop-5.3.23.jar b/Spring/Spring5/code/shangguigu07/lib/spring-aop-5.3.23.jar new file mode 100644 index 00000000..c7ee78de Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/spring-aop-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/spring-aspects-5.3.23.jar b/Spring/Spring5/code/shangguigu07/lib/spring-aspects-5.3.23.jar new file mode 100644 index 00000000..3857b886 Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/spring-aspects-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/spring-beans-5.3.23.jar b/Spring/Spring5/code/shangguigu07/lib/spring-beans-5.3.23.jar new file mode 100644 index 00000000..fcc7cfd6 Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/spring-beans-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/spring-context-5.3.23.jar b/Spring/Spring5/code/shangguigu07/lib/spring-context-5.3.23.jar new file mode 100644 index 00000000..e80b5da4 Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/spring-context-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/spring-core-5.3.23.jar b/Spring/Spring5/code/shangguigu07/lib/spring-core-5.3.23.jar new file mode 100644 index 00000000..78ff1cae Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/spring-core-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/spring-expression-5.3.23.jar b/Spring/Spring5/code/shangguigu07/lib/spring-expression-5.3.23.jar new file mode 100644 index 00000000..3d10ecea Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/spring-expression-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/spring-jdbc-5.3.23.jar b/Spring/Spring5/code/shangguigu07/lib/spring-jdbc-5.3.23.jar new file mode 100644 index 00000000..2322be71 Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/spring-jdbc-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/spring-orm-5.3.23.jar b/Spring/Spring5/code/shangguigu07/lib/spring-orm-5.3.23.jar new file mode 100644 index 00000000..b4fed3ea Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/spring-orm-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/spring-test-5.3.23.jar b/Spring/Spring5/code/shangguigu07/lib/spring-test-5.3.23.jar new file mode 100644 index 00000000..3bdc3d79 Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/spring-test-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu07/lib/spring-tx-5.3.23.jar b/Spring/Spring5/code/shangguigu07/lib/spring-tx-5.3.23.jar new file mode 100644 index 00000000..aad7465e Binary files /dev/null and b/Spring/Spring5/code/shangguigu07/lib/spring-tx-5.3.23.jar differ diff --git a/Spring/Spring5/code/shangguigu07/out/production/shangguigu07/bean01.xml b/Spring/Spring5/code/shangguigu07/out/production/shangguigu07/bean01.xml new file mode 100644 index 00000000..c5c88790 --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/out/production/shangguigu07/bean01.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu07/out/production/shangguigu07/bean02.xml b/Spring/Spring5/code/shangguigu07/out/production/shangguigu07/bean02.xml new file mode 100644 index 00000000..36e5749d --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/out/production/shangguigu07/bean02.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu07/out/production/shangguigu07/jdbc.properties b/Spring/Spring5/code/shangguigu07/out/production/shangguigu07/jdbc.properties new file mode 100644 index 00000000..90b61e10 --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/out/production/shangguigu07/jdbc.properties @@ -0,0 +1,4 @@ +prop.driverClass=com.mysql.jdbc.Driver +prop.url=jdbc:mysql://localhost:3306/user +prop.username=root +prop.password=123456 \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu07/out/production/shangguigu07/log4j2.xml b/Spring/Spring5/code/shangguigu07/out/production/shangguigu07/log4j2.xml new file mode 100644 index 00000000..bf20500e --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/out/production/shangguigu07/log4j2.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu07/shangguigu07.iml b/Spring/Spring5/code/shangguigu07/shangguigu07.iml new file mode 100644 index 00000000..6b6f74c6 --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/shangguigu07.iml @@ -0,0 +1,204 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu07/src/Main.java b/Spring/Spring5/code/shangguigu07/src/Main.java new file mode 100644 index 00000000..7cf1a648 --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/src/Main.java @@ -0,0 +1,9 @@ +/** + * @author yinkanglong + * @version $Id: ${NAME}, v 0.1 ${YEAR}-${MONTH}-${DAY} ${TIME} yinkanglong Exp $ + */ +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu07/src/bean01.xml b/Spring/Spring5/code/shangguigu07/src/bean01.xml new file mode 100644 index 00000000..c5c88790 --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/src/bean01.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu07/src/bean02.xml b/Spring/Spring5/code/shangguigu07/src/bean02.xml new file mode 100644 index 00000000..36e5749d --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/src/bean02.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Spring/Spring5/code/shangguigu07/src/com/ykl/config/TxConfig.java b/Spring/Spring5/code/shangguigu07/src/com/ykl/config/TxConfig.java new file mode 100644 index 00000000..140eee28 --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/src/com/ykl/config/TxConfig.java @@ -0,0 +1,55 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.config; + +import com.alibaba.druid.pool.DruidDataSource; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.activation.DataSource; + +/** + * @author yinkanglong + * @version : TxConfig, v 0.1 2022-10-11 21:52 yinkanglong Exp $ + */ +@Configuration //配置类 +@ComponentScan(basePackages = "com.ykl") //开启组件扫描 +@EnableTransactionManagement //开启事务管理 +public class TxConfig { + + + //创建数据库连接池 + @Bean + public DruidDataSource getDruidDataSource(){ + DruidDataSource druidDataSource = new DruidDataSource(); + druidDataSource.setDriverClassName("com.mysql.jdbc.Driver"); + druidDataSource.setUrl("jdbc:mysql://localhost:3310/user"); + druidDataSource.setUsername("root"); + druidDataSource.setPassword("123456"); + return druidDataSource; + } + + //创建jdbcTemplate。这个参数会根据类型在容器中找到指定的对象 + @Bean + public JdbcTemplate getJdbcTemplate(DruidDataSource dataSource){ + JdbcTemplate jdbcTemplate = new JdbcTemplate(); + jdbcTemplate.setDataSource(dataSource); + return jdbcTemplate; + } + + //创建事务管理器的对象 + @Bean + public DataSourceTransactionManager getDataSourceTransactionManager(DruidDataSource dataSource){ + DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(); + transactionManager.setDataSource(dataSource); + return transactionManager; + + } +} diff --git a/Spring/Spring5/code/shangguigu07/src/com/ykl/dao/AccountDao.java b/Spring/Spring5/code/shangguigu07/src/com/ykl/dao/AccountDao.java new file mode 100644 index 00000000..fda65973 --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/src/com/ykl/dao/AccountDao.java @@ -0,0 +1,16 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.dao; + +/** + * @author yinkanglong + * @version : AccountDao, v 0.1 2022-10-11 10:42 yinkanglong Exp $ + */ +public interface AccountDao { + + public void addMoney(); + + public void reduceMoney(); +} diff --git a/Spring/Spring5/code/shangguigu07/src/com/ykl/dao/AccountDaoImpl.java b/Spring/Spring5/code/shangguigu07/src/com/ykl/dao/AccountDaoImpl.java new file mode 100644 index 00000000..38bf9658 --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/src/com/ykl/dao/AccountDaoImpl.java @@ -0,0 +1,34 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.dao; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; + +/** + * @author yinkanglong + * @version : AccountDaoImpl, v 0.1 2022-10-11 10:42 yinkanglong Exp $ + */ +@Repository +public class AccountDaoImpl implements AccountDao{ + + @Autowired + private JdbcTemplate jdbcTemplate; + + @Override + public void addMoney() { + String sql = "update account set money=money+? where username=?"; + jdbcTemplate.update(sql,100,"mary"); + System.out.println("addmoney"); + } + + @Override + public void reduceMoney() { + String sql = "update account set money=money-? where username=?"; + jdbcTemplate.update(sql,100,"lucy"); + System.out.println("reducemoney"); + } +} diff --git a/Spring/Spring5/code/shangguigu07/src/com/ykl/entity/Account.java b/Spring/Spring5/code/shangguigu07/src/com/ykl/entity/Account.java new file mode 100644 index 00000000..c4379ea5 --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/src/com/ykl/entity/Account.java @@ -0,0 +1,72 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.entity; + +/** + * @author yinkanglong + * @version : Account, v 0.1 2022-10-11 10:42 yinkanglong Exp $ + */ +public class Account { + + private String id; + + private String username; + + private Integer money; + + /** + * Getter method for property id. + * + * @return property value of id + */ + public String getId() { + return id; + } + + /** + * Setter method for property counterType. + * + * @param id value to be assigned to property id + */ + public void setId(String id) { + this.id = id; + } + + /** + * Getter method for property username. + * + * @return property value of username + */ + public String getUsername() { + return username; + } + + /** + * Setter method for property counterType. + * + * @param username value to be assigned to property username + */ + public void setUsername(String username) { + this.username = username; + } + + /** + * Getter method for property money. + * + * @return property value of money + */ + public Integer getMoney() { + return money; + } + + /** + * Setter method for property counterType. + * + * @param money value to be assigned to property money + */ + public void setMoney(Integer money) { + this.money = money; + } +} diff --git a/Spring/Spring5/code/shangguigu07/src/com/ykl/service/AccountService.java b/Spring/Spring5/code/shangguigu07/src/com/ykl/service/AccountService.java new file mode 100644 index 00000000..0a5488ca --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/src/com/ykl/service/AccountService.java @@ -0,0 +1,30 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.service; + +import com.ykl.dao.AccountDao; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.Transactional; + +/** + * @author yinkanglong + * @version : AccountService, v 0.1 2022-10-11 10:42 yinkanglong Exp $ + */ +@Service +@Transactional +public class AccountService { + + @Autowired + private AccountDao accountDao; + + public void pay(){ + + accountDao.reduceMoney(); +// int i= 1/0; + accountDao.addMoney(); + } +} diff --git a/Spring/Spring5/code/shangguigu07/src/com/ykl/test/JTest4.java b/Spring/Spring5/code/shangguigu07/src/com/ykl/test/JTest4.java new file mode 100644 index 00000000..85467fcc --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/src/com/ykl/test/JTest4.java @@ -0,0 +1,29 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +import com.ykl.service.AccountService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author yinkanglong + * @version : JTest4, v 0.1 2022-10-12 11:30 yinkanglong Exp $ + */ + +//@ExtendWith(SpingExtension.class) +@ContextConfiguration("classpath:bean01.xml") +public class JTest4 { + @Autowired + private AccountService accountService; + + @Test + public void test01(){ + accountService.pay(); + } +} diff --git a/Spring/Spring5/code/shangguigu07/src/com/ykl/test/JTest5.java b/Spring/Spring5/code/shangguigu07/src/com/ykl/test/JTest5.java new file mode 100644 index 00000000..243af51b --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/src/com/ykl/test/JTest5.java @@ -0,0 +1,28 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +import com.ykl.service.AccountService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author yinkanglong + * @version : JTest4, v 0.1 2022-10-12 11:30 yinkanglong Exp $ + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("classpath:bean01.xml") +public class JTest5 { + @Autowired + private AccountService accountService; + + @Test + public void test01(){ + accountService.pay(); + } +} diff --git a/Spring/Spring5/code/shangguigu07/src/com/ykl/test/Test01.java b/Spring/Spring5/code/shangguigu07/src/com/ykl/test/Test01.java new file mode 100644 index 00000000..443fd791 --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/src/com/ykl/test/Test01.java @@ -0,0 +1,60 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +import com.ykl.config.TxConfig; +import com.ykl.entity.Account; +import com.ykl.service.AccountService; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.context.support.GenericApplicationContext; +import sun.net.www.content.text.Generic; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author yinkanglong + * @version : Test01, v 0.1 2022-10-08 16:09 yinkanglong Exp $ + */ +public class Test01 { + + + @Test + public void testBatchAdd(){ + ApplicationContext context = new ClassPathXmlApplicationContext("bean01.xml"); + AccountService accountService = context.getBean("accountService",AccountService.class); + accountService.pay(); + } + + @Test + public void testBatchAdd3(){ + ApplicationContext context = new AnnotationConfigApplicationContext(TxConfig.class); + AccountService accountService = context.getBean("accountService",AccountService.class); + System.out.println("start"); + accountService.pay(); + System.out.println("end"); + } + + //函数式风格创建对象,交给对象进行管理 + @Test + public void testGenericApplicationContext(){ + GenericApplicationContext context = new GenericApplicationContext(); + + context.refresh(); + context.registerBean("user1",Account.class,()->new Account()); + + //根据类型获取bean(跟@Autowire一样,都是根据类型手动装载) + Account account = context.getBean("com.ykl.entity.Account",Account.class); + System.out.println(account); + + //根据名称获取bean(跟@Qualified一样,根据对象的id进行装配) + Account account2 = context.getBean("user1",Account.class); + System.out.println(account); + } + +} diff --git a/Spring/Spring5/code/shangguigu07/src/com/ykl/test/UserLog.java b/Spring/Spring5/code/shangguigu07/src/com/ykl/test/UserLog.java new file mode 100644 index 00000000..5eb894d1 --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/src/com/ykl/test/UserLog.java @@ -0,0 +1,21 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.test; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author yinkanglong + * @version : UserLog, v 0.1 2022-10-12 10:59 yinkanglong Exp $ + */ +public class UserLog { + private static final Logger log = LoggerFactory.getLogger(UserLog.class); + + public static void main(String[] args) { + log.info("hello world"); + log.warn("hello log4j"); + } +} diff --git a/Spring/Spring5/code/shangguigu07/src/jdbc.properties b/Spring/Spring5/code/shangguigu07/src/jdbc.properties new file mode 100644 index 00000000..90b61e10 --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/src/jdbc.properties @@ -0,0 +1,4 @@ +prop.driverClass=com.mysql.jdbc.Driver +prop.url=jdbc:mysql://localhost:3306/user +prop.username=root +prop.password=123456 \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu07/src/log4j2.xml b/Spring/Spring5/code/shangguigu07/src/log4j2.xml new file mode 100644 index 00000000..bf20500e --- /dev/null +++ b/Spring/Spring5/code/shangguigu07/src/log4j2.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Spring/Spring5/code/shangguigu08/.gitignore b/Spring/Spring5/code/shangguigu08/.gitignore new file mode 100644 index 00000000..549e00a2 --- /dev/null +++ b/Spring/Spring5/code/shangguigu08/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/Spring/Spring5/code/shangguigu08/.mvn/wrapper/maven-wrapper.jar b/Spring/Spring5/code/shangguigu08/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 00000000..c1dd12f1 Binary files /dev/null and b/Spring/Spring5/code/shangguigu08/.mvn/wrapper/maven-wrapper.jar differ diff --git a/Spring/Spring5/code/shangguigu08/.mvn/wrapper/maven-wrapper.properties b/Spring/Spring5/code/shangguigu08/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..b74bf7fc --- /dev/null +++ b/Spring/Spring5/code/shangguigu08/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar diff --git a/Spring/Spring5/code/shangguigu08/mvnw b/Spring/Spring5/code/shangguigu08/mvnw new file mode 100755 index 00000000..8a8fb228 --- /dev/null +++ b/Spring/Spring5/code/shangguigu08/mvnw @@ -0,0 +1,316 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/Spring/Spring5/code/shangguigu08/mvnw.cmd b/Spring/Spring5/code/shangguigu08/mvnw.cmd new file mode 100644 index 00000000..1d8ab018 --- /dev/null +++ b/Spring/Spring5/code/shangguigu08/mvnw.cmd @@ -0,0 +1,188 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/Spring/Spring5/code/shangguigu08/pom.xml b/Spring/Spring5/code/shangguigu08/pom.xml new file mode 100644 index 00000000..f444218c --- /dev/null +++ b/Spring/Spring5/code/shangguigu08/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.6.12 + + + com.ykl + shangguigu08 + 0.0.1-SNAPSHOT + shangguigu08 + shangguigu08 + + 1.8 + + + + io.projectreactor + reactor-core + 3.1.5.RELEASE + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/Spring/Spring5/code/shangguigu08/src/main/java/com/ykl/shangguigu08/Shangguigu08Application.java b/Spring/Spring5/code/shangguigu08/src/main/java/com/ykl/shangguigu08/Shangguigu08Application.java new file mode 100644 index 00000000..159b2582 --- /dev/null +++ b/Spring/Spring5/code/shangguigu08/src/main/java/com/ykl/shangguigu08/Shangguigu08Application.java @@ -0,0 +1,13 @@ +package com.ykl.shangguigu08; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Shangguigu08Application { + + public static void main(String[] args) { + SpringApplication.run(Shangguigu08Application.class, args); + } + +} diff --git a/Spring/Spring5/code/shangguigu08/src/main/java/com/ykl/shangguigu08/reactor/ObserverDemo.java b/Spring/Spring5/code/shangguigu08/src/main/java/com/ykl/shangguigu08/reactor/ObserverDemo.java new file mode 100644 index 00000000..73924bef --- /dev/null +++ b/Spring/Spring5/code/shangguigu08/src/main/java/com/ykl/shangguigu08/reactor/ObserverDemo.java @@ -0,0 +1,34 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.shangguigu08.reactor; + +import java.util.Observable; + +/** + * @author yinkanglong + * @version : ObserverDemo, v 0.1 2022-10-12 19:47 yinkanglong Exp $ + */ +public class ObserverDemo extends Observable { + + /** + * 通过Java8中的类实现响应式编程。 + * 简单来说,就是观察值模式。 + * @param args + */ + public static void main(String[] args) { + ObserverDemo observerDemo = new ObserverDemo(); + + observerDemo.addObserver((o,arg)->{ + System.out.println("发生变化"); + }); + + observerDemo.addObserver((o,arg)->{ + System.out.println("准备改变"); + }); + + observerDemo.setChanged(); + observerDemo.notifyObservers(); + } +} diff --git a/Spring/Spring5/code/shangguigu08/src/main/java/com/ykl/shangguigu08/reactor/TestReactor.java b/Spring/Spring5/code/shangguigu08/src/main/java/com/ykl/shangguigu08/reactor/TestReactor.java new file mode 100644 index 00000000..f9f14541 --- /dev/null +++ b/Spring/Spring5/code/shangguigu08/src/main/java/com/ykl/shangguigu08/reactor/TestReactor.java @@ -0,0 +1,36 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.ykl.shangguigu08.reactor; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +/** + * @author yinkanglong + * @version : TestReactor, v 0.1 2022-10-13 10:25 yinkanglong Exp $ + */ +public class TestReactor { + + public static void main(String[] args) { + //reactor中的核心语法 + Flux.just(1,2,3,4).subscribe(System.out::print); + Mono.just(1).subscribe(System.out::print); + + //其他方法 +// Integer[] array = {1,2,3,4}; +// Flux.fromArray(array); +// +// List list = Arrays.asList(array); +// Flux.fromIterable(list); +// +// Stream stream = list.stream(); +// Flux.fromStream(stream); + } +} diff --git a/Spring/Spring5/code/shangguigu08/src/main/resources/application.properties b/Spring/Spring5/code/shangguigu08/src/main/resources/application.properties new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Spring/Spring5/code/shangguigu08/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/Spring/Spring5/code/shangguigu08/src/test/java/com/ykl/shangguigu08/Shangguigu08ApplicationTests.java b/Spring/Spring5/code/shangguigu08/src/test/java/com/ykl/shangguigu08/Shangguigu08ApplicationTests.java new file mode 100644 index 00000000..cf5c88c1 --- /dev/null +++ b/Spring/Spring5/code/shangguigu08/src/test/java/com/ykl/shangguigu08/Shangguigu08ApplicationTests.java @@ -0,0 +1,13 @@ +package com.ykl.shangguigu08; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Shangguigu08ApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/Spring/Spring5/code/shangguigu09/.gitignore b/Spring/Spring5/code/shangguigu09/.gitignore new file mode 100644 index 00000000..549e00a2 --- /dev/null +++ b/Spring/Spring5/code/shangguigu09/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/Spring/Spring5/code/shangguigu09/.mvn/wrapper/maven-wrapper.jar b/Spring/Spring5/code/shangguigu09/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 00000000..c1dd12f1 Binary files /dev/null and b/Spring/Spring5/code/shangguigu09/.mvn/wrapper/maven-wrapper.jar differ diff --git a/Spring/Spring5/code/shangguigu09/.mvn/wrapper/maven-wrapper.properties b/Spring/Spring5/code/shangguigu09/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..b74bf7fc --- /dev/null +++ b/Spring/Spring5/code/shangguigu09/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar diff --git a/Spring/Spring5/code/shangguigu09/mvnw b/Spring/Spring5/code/shangguigu09/mvnw new file mode 100755 index 00000000..8a8fb228 --- /dev/null +++ b/Spring/Spring5/code/shangguigu09/mvnw @@ -0,0 +1,316 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/Spring/Spring5/code/shangguigu09/mvnw.cmd b/Spring/Spring5/code/shangguigu09/mvnw.cmd new file mode 100644 index 00000000..1d8ab018 --- /dev/null +++ b/Spring/Spring5/code/shangguigu09/mvnw.cmd @@ -0,0 +1,188 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/Spring/Spring5/code/shangguigu09/pom.xml b/Spring/Spring5/code/shangguigu09/pom.xml new file mode 100644 index 00000000..b75f4d6e --- /dev/null +++ b/Spring/Spring5/code/shangguigu09/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.2.1.RELEASE + + + com.example + shangguigu09 + 0.0.1-SNAPSHOT + shangguigu09 + shangguigu09 + + 1.8 + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/Shangguigu09Application.java b/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/Shangguigu09Application.java new file mode 100644 index 00000000..fd22c84f --- /dev/null +++ b/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/Shangguigu09Application.java @@ -0,0 +1,13 @@ +package com.example.shangguigu09; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Shangguigu09Application { + + public static void main(String[] args) { + SpringApplication.run(Shangguigu09Application.class, args); + } + +} diff --git a/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/controller/UserController.java b/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/controller/UserController.java new file mode 100644 index 00000000..2d7c2cf3 --- /dev/null +++ b/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/controller/UserController.java @@ -0,0 +1,43 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.example.shangguigu09.controller; + +import com.example.shangguigu09.entity.User; +import com.example.shangguigu09.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * @author yinkanglong + * @version : UserController, v 0.1 2022-10-13 19:14 yinkanglong Exp $ + */ +@RestController +public class UserController { + @Autowired + private UserService userService; + + //id + @GetMapping("/user/{id}") + public Mono getUserById(@PathVariable int id){ + return userService.getUserById(id); + } + + //all + @GetMapping("/user") + public Flux getAllUser(){ + return userService.getAllUser(); + } + //tianjian + @GetMapping("/saveuser") + public Mono saveUser(@RequestBody User user){ + Mono userMono = Mono.just(user); + return userService.savaUserInfo(userMono); + } +} diff --git a/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/entity/User.java b/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/entity/User.java new file mode 100644 index 00000000..f63e9df2 --- /dev/null +++ b/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/entity/User.java @@ -0,0 +1,78 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.example.shangguigu09.entity; + +/** + * @author yinkanglong + * @version : User, v 0.1 2022-10-13 19:01 yinkanglong Exp $ + */ +public class User { + private String name; + private String gender; + private Integer age; + + public User() { + } + + public User(String name, String gender, Integer age) { + this.name = name; + this.gender = gender; + this.age = age; + } + + /** + * Getter method for property name. + * + * @return property value of name + */ + public String getName() { + return name; + } + + /** + * Setter method for property counterType. + * + * @param name value to be assigned to property name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Getter method for property gender. + * + * @return property value of gender + */ + public String getGender() { + return gender; + } + + /** + * Setter method for property counterType. + * + * @param gender value to be assigned to property gender + */ + public void setGender(String gender) { + this.gender = gender; + } + + /** + * Getter method for property age. + * + * @return property value of age + */ + public Integer getAge() { + return age; + } + + /** + * Setter method for property counterType. + * + * @param age value to be assigned to property age + */ + public void setAge(Integer age) { + this.age = age; + } +} diff --git a/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/service/UserService.java b/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/service/UserService.java new file mode 100644 index 00000000..ade49b26 --- /dev/null +++ b/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/service/UserService.java @@ -0,0 +1,24 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.example.shangguigu09.service; + +import com.example.shangguigu09.entity.User; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * @author yinkanglong + * @version : UserService, v 0.1 2022-10-13 19:02 yinkanglong Exp $ + */ +public interface UserService { + //id查询用户 + Mono getUserById(int id); + + //查询所有的用户 + Flux getAllUser(); + + //添加用户 + Mono savaUserInfo(Mono user); +} diff --git a/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/service/impl/UserServiceImpl.java b/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/service/impl/UserServiceImpl.java new file mode 100644 index 00000000..f526d01a --- /dev/null +++ b/Spring/Spring5/code/shangguigu09/src/main/java/com/example/shangguigu09/service/impl/UserServiceImpl.java @@ -0,0 +1,49 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.example.shangguigu09.service.impl; + +import com.example.shangguigu09.entity.User; +import com.example.shangguigu09.service.UserService; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author yinkanglong + * @version : UserServiceImpl, v 0.1 2022-10-13 19:02 yinkanglong Exp $ + */ +@Service +public class UserServiceImpl implements UserService { + private final Map users = new HashMap<>(); + + public UserServiceImpl() { + + this.users.put(1,new User("lucy","nan",10)); + this.users.put(2,new User("mary","nv",38)); + this.users.put(3,new User("jack","nv",32)); + + } + + @Override + public Mono getUserById(int id) { + return Mono.justOrEmpty(this.users.get(id)); + } + + @Override + public Flux getAllUser() { + return Flux.fromIterable(this.users.values()); + } + + @Override + public Mono savaUserInfo(Mono userMono) { + return userMono.doOnNext(person->{ + int id = users.size() + 1; + users.put(id,person); + }).thenEmpty(Mono.empty()); + } +} diff --git a/Spring/Spring5/code/shangguigu09/src/main/resources/application.properties b/Spring/Spring5/code/shangguigu09/src/main/resources/application.properties new file mode 100644 index 00000000..164f752a --- /dev/null +++ b/Spring/Spring5/code/shangguigu09/src/main/resources/application.properties @@ -0,0 +1,2 @@ + +server.port=8085 diff --git a/Spring/Spring5/code/shangguigu09/src/test/java/com/example/shangguigu09/Shangguigu09ApplicationTests.java b/Spring/Spring5/code/shangguigu09/src/test/java/com/example/shangguigu09/Shangguigu09ApplicationTests.java new file mode 100644 index 00000000..0440655b --- /dev/null +++ b/Spring/Spring5/code/shangguigu09/src/test/java/com/example/shangguigu09/Shangguigu09ApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.shangguigu09; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Shangguigu09ApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/Spring/Spring5/code/shangguigu10/.gitignore b/Spring/Spring5/code/shangguigu10/.gitignore new file mode 100644 index 00000000..549e00a2 --- /dev/null +++ b/Spring/Spring5/code/shangguigu10/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/Spring/Spring5/code/shangguigu10/.mvn/wrapper/maven-wrapper.jar b/Spring/Spring5/code/shangguigu10/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 00000000..c1dd12f1 Binary files /dev/null and b/Spring/Spring5/code/shangguigu10/.mvn/wrapper/maven-wrapper.jar differ diff --git a/Spring/Spring5/code/shangguigu10/.mvn/wrapper/maven-wrapper.properties b/Spring/Spring5/code/shangguigu10/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..b74bf7fc --- /dev/null +++ b/Spring/Spring5/code/shangguigu10/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar diff --git a/Spring/Spring5/code/shangguigu10/mvnw b/Spring/Spring5/code/shangguigu10/mvnw new file mode 100755 index 00000000..8a8fb228 --- /dev/null +++ b/Spring/Spring5/code/shangguigu10/mvnw @@ -0,0 +1,316 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/Spring/Spring5/code/shangguigu10/mvnw.cmd b/Spring/Spring5/code/shangguigu10/mvnw.cmd new file mode 100644 index 00000000..1d8ab018 --- /dev/null +++ b/Spring/Spring5/code/shangguigu10/mvnw.cmd @@ -0,0 +1,188 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/Spring/Spring5/code/shangguigu10/pom.xml b/Spring/Spring5/code/shangguigu10/pom.xml new file mode 100644 index 00000000..b75f4d6e --- /dev/null +++ b/Spring/Spring5/code/shangguigu10/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.2.1.RELEASE + + + com.example + shangguigu09 + 0.0.1-SNAPSHOT + shangguigu09 + shangguigu09 + + 1.8 + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/Client.java b/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/Client.java new file mode 100644 index 00000000..2680ff8e --- /dev/null +++ b/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/Client.java @@ -0,0 +1,23 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.example.shangguigu09; + +import com.example.shangguigu09.entity.User; +import org.springframework.http.MediaType; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +/** + * @author yinkanglong + * @version : Client, v 0.1 2022-10-14 09:53 yinkanglong Exp $ + */ +public class Client { + + public static void main(String[] args) { + WebClient webClient = WebClient.create("http://127.0.0.1:62418"); + User userMono = webClient.get().uri("/users/{id}", "1").accept(MediaType.APPLICATION_JSON).retrieve().bodyToMono(User.class).block(); + System.out.println(userMono.getName()); + } +} diff --git a/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/Server.java b/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/Server.java new file mode 100644 index 00000000..3d0e1549 --- /dev/null +++ b/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/Server.java @@ -0,0 +1,55 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.example.shangguigu09; + +import com.example.shangguigu09.handler.UserHandler; +import com.example.shangguigu09.service.UserService; +import com.example.shangguigu09.service.impl.UserServiceImpl; +import org.springframework.http.MediaType; +import org.springframework.http.server.reactive.HttpHandler; +import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.netty.http.server.HttpServer; + + +import static org.springframework.web.reactive.function.server.RequestPredicates.GET; +import static org.springframework.web.reactive.function.server.RequestPredicates.accept; +import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler; + +/** + * @author yinkanglong + * @version : Server, v 0.1 2022-10-14 07:59 yinkanglong Exp $ + */ +public class Server { + //创建路由 + public RouterFunction route(){ + UserService userService = new UserServiceImpl(); + UserHandler handler = new UserHandler(userService); + + return RouterFunctions.route(GET("/users/{id}").and(accept(MediaType.APPLICATION_JSON)),handler::getUserById); +// .andRoute(GET("users").and(accept(MediaType.APPLICATION_JSON)),handler::getAllUsers) +// .andRoute(GET("saveuser").and(accept(MediaType.APPLICATION_JSON)),handler::saveUser); + + } + + public void createReactorServer(){ + RouterFunction route = route(); + HttpHandler httpHandler = toHttpHandler(route); + + ReactorHttpHandlerAdapter reactorHttpHandlerAdapter = new ReactorHttpHandlerAdapter(httpHandler); + + HttpServer httpServer = HttpServer.create(); + httpServer.handle(reactorHttpHandlerAdapter).bindNow(); + } + + public static void main(String[] args) throws Exception{ + Server server = new Server(); + server.createReactorServer(); + System.out.println("enter to exit"); + System.in.read(); + } +} diff --git a/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/Shangguigu09Application.java b/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/Shangguigu09Application.java new file mode 100644 index 00000000..fd22c84f --- /dev/null +++ b/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/Shangguigu09Application.java @@ -0,0 +1,13 @@ +package com.example.shangguigu09; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Shangguigu09Application { + + public static void main(String[] args) { + SpringApplication.run(Shangguigu09Application.class, args); + } + +} diff --git a/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/entity/User.java b/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/entity/User.java new file mode 100644 index 00000000..f63e9df2 --- /dev/null +++ b/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/entity/User.java @@ -0,0 +1,78 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.example.shangguigu09.entity; + +/** + * @author yinkanglong + * @version : User, v 0.1 2022-10-13 19:01 yinkanglong Exp $ + */ +public class User { + private String name; + private String gender; + private Integer age; + + public User() { + } + + public User(String name, String gender, Integer age) { + this.name = name; + this.gender = gender; + this.age = age; + } + + /** + * Getter method for property name. + * + * @return property value of name + */ + public String getName() { + return name; + } + + /** + * Setter method for property counterType. + * + * @param name value to be assigned to property name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Getter method for property gender. + * + * @return property value of gender + */ + public String getGender() { + return gender; + } + + /** + * Setter method for property counterType. + * + * @param gender value to be assigned to property gender + */ + public void setGender(String gender) { + this.gender = gender; + } + + /** + * Getter method for property age. + * + * @return property value of age + */ + public Integer getAge() { + return age; + } + + /** + * Setter method for property counterType. + * + * @param age value to be assigned to property age + */ + public void setAge(Integer age) { + this.age = age; + } +} diff --git a/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/handler/UserHandler.java b/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/handler/UserHandler.java new file mode 100644 index 00000000..237a33e1 --- /dev/null +++ b/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/handler/UserHandler.java @@ -0,0 +1,56 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.example.shangguigu09.handler; + +import com.example.shangguigu09.entity.User; +import com.example.shangguigu09.service.UserService; +import org.springframework.http.MediaType; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import static org.springframework.web.reactive.function.BodyInserters.fromObject; + +/** + * @author yinkanglong + * @version : UserHandler, v 0.1 2022-10-13 22:47 yinkanglong Exp $ + */ +public class UserHandler { + + private final UserService userService; + public UserHandler(UserService userService){ + this.userService = userService; + } + + //根据id + public Mono getUserById(ServerRequest request){ + //获取id值 + int userid = Integer.valueOf( request.pathVariable("id")); + Mono notFound = ServerResponse.notFound().build(); + //调用service方法取得数据 + Mono userMono = this.userService.getUserById(userid); + + //UserMono进行转换返回。Reactor操作符 + return userMono.flatMap(person->ServerResponse.ok().contentType(MediaType.APPLICATION_JSON) + .body(fromObject(person))) + .switchIfEmpty(notFound); + + } + + //所有用户 + public Mono getAllUsers(){ + Flux users = this.userService.getAllUser(); + return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(users,User.class); + + } + + + //添加 + public Mono saveUser(ServerRequest request){ + Mono userMono = request.bodyToMono(User.class); + return ServerResponse.ok().build(this.userService.savaUserInfo(userMono)); + } +} diff --git a/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/service/UserService.java b/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/service/UserService.java new file mode 100644 index 00000000..ade49b26 --- /dev/null +++ b/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/service/UserService.java @@ -0,0 +1,24 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.example.shangguigu09.service; + +import com.example.shangguigu09.entity.User; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * @author yinkanglong + * @version : UserService, v 0.1 2022-10-13 19:02 yinkanglong Exp $ + */ +public interface UserService { + //id查询用户 + Mono getUserById(int id); + + //查询所有的用户 + Flux getAllUser(); + + //添加用户 + Mono savaUserInfo(Mono user); +} diff --git a/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/service/impl/UserServiceImpl.java b/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/service/impl/UserServiceImpl.java new file mode 100644 index 00000000..f526d01a --- /dev/null +++ b/Spring/Spring5/code/shangguigu10/src/main/java/com/example/shangguigu09/service/impl/UserServiceImpl.java @@ -0,0 +1,49 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2022 All Rights Reserved. + */ +package com.example.shangguigu09.service.impl; + +import com.example.shangguigu09.entity.User; +import com.example.shangguigu09.service.UserService; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author yinkanglong + * @version : UserServiceImpl, v 0.1 2022-10-13 19:02 yinkanglong Exp $ + */ +@Service +public class UserServiceImpl implements UserService { + private final Map users = new HashMap<>(); + + public UserServiceImpl() { + + this.users.put(1,new User("lucy","nan",10)); + this.users.put(2,new User("mary","nv",38)); + this.users.put(3,new User("jack","nv",32)); + + } + + @Override + public Mono getUserById(int id) { + return Mono.justOrEmpty(this.users.get(id)); + } + + @Override + public Flux getAllUser() { + return Flux.fromIterable(this.users.values()); + } + + @Override + public Mono savaUserInfo(Mono userMono) { + return userMono.doOnNext(person->{ + int id = users.size() + 1; + users.put(id,person); + }).thenEmpty(Mono.empty()); + } +} diff --git a/Spring/Spring5/code/shangguigu10/src/main/resources/application.properties b/Spring/Spring5/code/shangguigu10/src/main/resources/application.properties new file mode 100644 index 00000000..164f752a --- /dev/null +++ b/Spring/Spring5/code/shangguigu10/src/main/resources/application.properties @@ -0,0 +1,2 @@ + +server.port=8085 diff --git a/Spring/Spring5/code/shangguigu10/src/test/java/com/example/shangguigu09/Shangguigu09ApplicationTests.java b/Spring/Spring5/code/shangguigu10/src/test/java/com/example/shangguigu09/Shangguigu09ApplicationTests.java new file mode 100644 index 00000000..0440655b --- /dev/null +++ b/Spring/Spring5/code/shangguigu10/src/test/java/com/example/shangguigu09/Shangguigu09ApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.shangguigu09; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Shangguigu09ApplicationTests { + + @Test + void contextLoads() { + } + +}