From 93abbf2170fef5a180fdbe6e6ed503e3c0af15c4 Mon Sep 17 00:00:00 2001 From: zw <18070097049@163.com> Date: Fri, 16 Aug 2024 23:10:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 8 ++ .idea/misc.xml | 6 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + .idea/zw_test01.iml | 9 ++ ZwDemoSpringBoot/.gitignore | 33 +++++ ZwDemoSpringBoot/pom.xml | 126 ++++++++++++++++++ .../ZwDemoSpringBootApplication.java | 14 ++ .../controller/BasicController.java | 68 ++++++++++ .../controller/PathVariableController.java | 44 ++++++ .../controller/StreamTest1.java | 24 ++++ .../controller/StreamTest2.java | 34 +++++ .../controller/UserController.java | 19 +++ .../controller/ZwTestController.java | 109 +++++++++++++++ .../com/zw/zwdemospringboot/entity/User.java | 43 ++++++ .../zw/zwdemospringboot/entity/ZwUser.java | 14 ++ .../zwdemospringboot/mapper/ZwUserMapper.java | 18 +++ .../zw/zwdemospringboot/service/Calcable.java | 5 + .../zw/zwdemospringboot/service/Method.java | 8 ++ .../zw/zwdemospringboot/service/Person.java | 40 ++++++ .../service/PersonBuilder.java | 5 + .../zwdemospringboot/service/Printable.java | 8 ++ .../service/ZwUserService.java | 22 +++ .../service/ZwUserServiceImpl.java | 56 ++++++++ .../service/father/Greetable.java | 5 + .../service/father/Human.java | 9 ++ .../zwdemospringboot/service/father/Man.java | 23 ++++ .../service/father/SuperMethodRe.java | 8 ++ .../zwdemospringboot/service/son/Husband.java | 17 +++ .../zwdemospringboot/service/son/MethBuy.java | 7 + .../zw/zwdemospringboot/service/son/Rich.java | 5 + .../src/main/resources/application.yml | 16 +++ .../main/resources/mapper/ZwUserMapper.xml | 33 +++++ .../src/main/resources/static/index.html | 6 + .../com/zw/zwdemospringboot/InstantTest.java | 63 +++++++++ .../zw/zwdemospringboot/OptionalTest1.java | 27 ++++ .../com/zw/zwdemospringboot/StreamTest1.java | 44 ++++++ .../ZwDemoSpringBootApplicationTests.java | 13 ++ test1.txt | 3 - 39 files changed, 1003 insertions(+), 3 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/zw_test01.iml create mode 100644 ZwDemoSpringBoot/.gitignore create mode 100644 ZwDemoSpringBoot/pom.xml create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/ZwDemoSpringBootApplication.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/BasicController.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/PathVariableController.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/StreamTest1.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/StreamTest2.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/UserController.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/ZwTestController.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/entity/User.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/entity/ZwUser.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/mapper/ZwUserMapper.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Calcable.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Method.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Person.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/PersonBuilder.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Printable.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/ZwUserService.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/ZwUserServiceImpl.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/Greetable.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/Human.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/Man.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/SuperMethodRe.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/son/Husband.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/son/MethBuy.java create mode 100644 ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/son/Rich.java create mode 100644 ZwDemoSpringBoot/src/main/resources/application.yml create mode 100644 ZwDemoSpringBoot/src/main/resources/mapper/ZwUserMapper.xml create mode 100644 ZwDemoSpringBoot/src/main/resources/static/index.html create mode 100644 ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/InstantTest.java create mode 100644 ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/OptionalTest1.java create mode 100644 ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/StreamTest1.java create mode 100644 ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/ZwDemoSpringBootApplicationTests.java delete mode 100644 test1.txt diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..184e44c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..185614f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/zw_test01.iml b/.idea/zw_test01.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/zw_test01.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/ZwDemoSpringBoot/.gitignore b/ZwDemoSpringBoot/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/ZwDemoSpringBoot/.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/ZwDemoSpringBoot/pom.xml b/ZwDemoSpringBoot/pom.xml new file mode 100644 index 0000000..c030de6 --- /dev/null +++ b/ZwDemoSpringBoot/pom.xml @@ -0,0 +1,126 @@ + + + 4.0.0 + com.zw + ZwDemoSpringBoot + 0.0.1-SNAPSHOT + ZwDemoSpringBoot + ZwDemoSpringBoot + + 1.8 + UTF-8 + UTF-8 + 2.6.13 + + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-starter-jdbc + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + com.mysql + mysql-connector-j + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.baomidou + mybatis-plus-boot-starter + 3.5.6 + + + com.baomidou + mybatis-plus + 3.5.6 + compile + + + org.mybatis + mybatis-spring + 2.1.2 + compile + + + com.baomidou + mybatis-plus-spring-boot-autoconfigure + 3.5.6 + compile + + + org.springframework.boot + spring-boot-autoconfigure + compile + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + UTF-8 + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + com.zw.zwdemospringboot.ZwDemoSpringBootApplication + true + + + + repackage + + repackage + + + + + + + + diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/ZwDemoSpringBootApplication.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/ZwDemoSpringBootApplication.java new file mode 100644 index 0000000..f2b70e4 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/ZwDemoSpringBootApplication.java @@ -0,0 +1,14 @@ +package com.zw.zwdemospringboot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +public class ZwDemoSpringBootApplication { + + public static void main(String[] args) { + SpringApplication.run(ZwDemoSpringBootApplication.class, args); + } + +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/BasicController.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/BasicController.java new file mode 100644 index 0000000..4cbc7b2 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/BasicController.java @@ -0,0 +1,68 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed 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. + */ + +package com.zw.zwdemospringboot.controller; + +import com.zw.zwdemospringboot.entity.User; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @author theonefx + */ +@Controller +public class BasicController { + + // http://127.0.0.1:8080/hello?name=lisi + @RequestMapping("/hello") + @ResponseBody + public String hello(@RequestParam(name = "name", defaultValue = "unknown user") String name) { + return "Hello " + name; + } + + // http://127.0.0.1:8080/user + @RequestMapping("/user") + @ResponseBody + public User user() { + User user = new User(); + user.setName("theonefx"); + user.setAge(666); + return user; + } + + // http://127.0.0.1:8080/save_user?name=newName&age=11 + @RequestMapping("/save_user") + @ResponseBody + public String saveUser(User u) { + return "user will save: name=" + u.getName() + ", age=" + u.getAge(); + } + + // http://127.0.0.1:8080/html + @RequestMapping("/html") + public String html(){ + return "index.html"; + } + + @ModelAttribute + public void parseUser(@RequestParam(name = "name", defaultValue = "unknown user") String name + , @RequestParam(name = "age", defaultValue = "12") Integer age, User user) { + user.setName("zhangsan"); + user.setAge(18); + } +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/PathVariableController.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/PathVariableController.java new file mode 100644 index 0000000..309f908 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/PathVariableController.java @@ -0,0 +1,44 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed 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. + */ + +package com.zw.zwdemospringboot.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @author theonefx + */ +@Controller +public class PathVariableController { + + // http://127.0.0.1:8080/user/123/roles/222 + @RequestMapping(value = "/user/{userId}/roles/{roleId}", method = RequestMethod.GET) + @ResponseBody + public String getLogin(@PathVariable("userId") String userId, @PathVariable("roleId") String roleId) { + return "User Id : " + userId + " Role Id : " + roleId; + } + + // http://127.0.0.1:8080/javabeat/somewords + @RequestMapping(value = "/javabeat/{regexp1:[a-z-]+}", method = RequestMethod.GET) + @ResponseBody + public String getRegExp(@PathVariable("regexp1") String regexp1) { + return "URI Part : " + regexp1; + } +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/StreamTest1.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/StreamTest1.java new file mode 100644 index 0000000..08bbadf --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/StreamTest1.java @@ -0,0 +1,24 @@ +package com.zw.zwdemospringboot.controller; + +import com.zw.zwdemospringboot.service.Person; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +public class StreamTest1 { + public static void main(String[] args) { + List list1 = Arrays.asList("aaa", "abc", "avvc", "adddd", "edw", "dswe", "sdf", "sd"); + List list2 = Arrays.asList("bdd", "sfdsf", "efv", "yttb", "gdf", "jmh", "cvb", "dfg"); + + Stream s1 = list1.stream().filter(s -> { + return s.length() == 3; + }).limit(3); + Stream s2 = list2.stream().filter(s -> s.startsWith("d")).skip(2); + + //Stream.concat(s1,s2).map(n -> new Person(n)).forEach(System.out::println); + //Stream.concat(s1,s2).map(Person::new).forEach(System.out::println); + + } +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/StreamTest2.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/StreamTest2.java new file mode 100644 index 0000000..a2d15fc --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/StreamTest2.java @@ -0,0 +1,34 @@ +package com.zw.zwdemospringboot.controller; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +public class StreamTest2 { + public static void main(String[] args) { +// List c1 = Stream.of("aa", "bb", "cc").collect(Collectors.toList()); +// System.out.println(c1); +// +// Set c2 = Stream.of("cc", "dd", "ee","cc").collect(Collectors.toSet()); +// System.out.println(c2); +// +// ArrayList c3 = Stream.of("cc", "dd", "ee", "cc") +// //.collect(Collectors.toCollection(() -> new ArrayList<>())); +// .collect(Collectors.toCollection(ArrayList::new)); +// System.out.println(c3); +// +// HashSet s4 = Stream.of("cc", "dd", "ee", "cc").collect(Collectors.toCollection(HashSet::new)); +// System.out.println(s4); + + Object[] s5 = Stream.of("cc", "dd", "ee", "cc") + .toArray(); + System.out.println(s5); + + + Stream.of("11", "22", "22", "33").mapToInt(Integer::parseInt).toArray(); + +// Integer[] array1 = Stream.of("11", "22", "22", "33").toArray(Integer[]::new); +// System.out.println(array1); + + } +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/UserController.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/UserController.java new file mode 100644 index 0000000..bbf46b8 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/UserController.java @@ -0,0 +1,19 @@ +package com.zw.zwdemospringboot.controller; + +import com.zw.zwdemospringboot.entity.ZwUser; +import com.zw.zwdemospringboot.service.ZwUserService; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +public class UserController { + @Autowired + private ZwUserService zwUserService; + + @GetMapping("/getId") + public ZwUser hello(@RequestParam(name = "id") Integer id) { + return zwUserService.getComboById(id); + } +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/ZwTestController.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/ZwTestController.java new file mode 100644 index 0000000..c4fe898 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/controller/ZwTestController.java @@ -0,0 +1,109 @@ +package com.zw.zwdemospringboot.controller; + +import com.zw.zwdemospringboot.service.*; + +import java.io.PrintStream; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class ZwTestController { + + public static void main(String arg[]){ + /*pringString(s-> System.out.println(s)); + + pringString(System.out::println); + + PrintStream out = System.out; + pringString(out::print);*/ + +// int n = method(-10, a -> Math.abs(a)); +// System.out.println(n); +// +// int num = method(-20, Math::abs); +// System.out.println(num); + //构造器引用 +// printName("aaa", name->new Person(name)); +// +// printName("bbb", Person::new); + + //普通方法引用 + /*pringString(s->{ + Method method = new Method(); + method.printUpp(s); + } ); + + Method method = new Method(); + pringString(method::printUpp);*/ + + +// Stream stream = Stream.of("1", "2", "3", "4"); +// stream.map(s -> Integer.parseInt(s)).forEach(System.out::println); +// +// ArrayList list = new ArrayList<>(); +// list.add("aaa"); +// list.add("avd"); +// list.add("addd"); +// list.add("fdsf"); +// list.add("fdsss"); +// +// List a = list.stream().filter(s -> s.startsWith("a")).collect(Collectors.toList()); +// System.out.println(a); +// +// HashSet hs = new HashSet<>(); +// hs.add(10); +// hs.add(20); +// hs.add(30); +// hs.add(40); +// hs.add(50); +// +// Stream integerStream = hs.stream().filter(age -> age > 25); +// Set ages = integerStream.collect(Collectors.toSet()); +// for (Integer i : ages) { +// System.out.println(i); +// } +// +// String[] strArray = {"aaa,30", "bbb,40", "ccc,50", "ddd,60"}; +// Stream stream1 = Stream.of(strArray) +// .filter(s -> Integer.parseInt(s.split(",")[1]) > 28); +// Map map = stream1.collect(Collectors.toMap( +// s -> s.split(",")[0], +// s -> Integer.parseInt(s.split(",")[1]) +// )); +// +// Set keySet = map.keySet(); +// for (String s:keySet){ +// System.out.println(s+","+map.get(s)); +// } + + + Integer[] arr ={1,2,3,4,5}; + Stream stream = Arrays.stream(arr); + List list = Arrays.asList(arr); + //Stream.of(arr).filter(s->s>0).forEach(System.out::println); + + Stream.of(arr).mapToInt(Integer::intValue).filter(i->i>3).forEach(System.out::println); + + Stream stream1 = Stream.of("a","b","c"); + Stream stream2 = Stream.of("x", "y", "z"); + Stream.concat(stream1, stream2).forEach(System.out::println); + + + } + + public static void pringString(Printable p) { + p.print("hihihi!"); + } + + public static int method(int number, Calcable c) { + return c.calsAbs(number); + } + + public static void printName(String name, PersonBuilder pb) { + Person person = pb.builder(name); + System.out.println(person.getName()); + } + +} + + diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/entity/User.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/entity/User.java new file mode 100644 index 0000000..b9a2fbb --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/entity/User.java @@ -0,0 +1,43 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed 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. + */ + +package com.zw.zwdemospringboot.entity; + +/** + * @author theonefx + */ +public class User { + + private String name; + + private Integer age; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/entity/ZwUser.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/entity/ZwUser.java new file mode 100644 index 0000000..f0863ce --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/entity/ZwUser.java @@ -0,0 +1,14 @@ +package com.zw.zwdemospringboot.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("zw_user") +public class ZwUser { + private Integer id; + + private String userName; + + private Integer age; +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/mapper/ZwUserMapper.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/mapper/ZwUserMapper.java new file mode 100644 index 0000000..ff5c48f --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/mapper/ZwUserMapper.java @@ -0,0 +1,18 @@ +package com.zw.zwdemospringboot.mapper; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.zw.zwdemospringboot.entity.ZwUser; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ZwUserMapper { + Boolean saveCombo(ZwUser dto); + + Boolean updateCombo(ZwUser dto); + + Page pageComboVo(ZwUser dto); + + ZwUser getComboById(Integer id); + + Boolean removeComboById(Integer id); +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Calcable.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Calcable.java new file mode 100644 index 0000000..47e251e --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Calcable.java @@ -0,0 +1,5 @@ +package com.zw.zwdemospringboot.service; + +public interface Calcable { + int calsAbs(int number); +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Method.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Method.java new file mode 100644 index 0000000..553a0c7 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Method.java @@ -0,0 +1,8 @@ +package com.zw.zwdemospringboot.service; + +public class Method { + public int printUpp(String str){ + System.out.println(str.toUpperCase()); + return 0; + } +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Person.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Person.java new file mode 100644 index 0000000..45ceff7 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Person.java @@ -0,0 +1,40 @@ +package com.zw.zwdemospringboot.service; + +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +public class Person { + private String name; + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + private Integer age; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Person(String name, Integer age) { + this.name = name; + this.age = age; + } + + @Override + public String toString() { + return "Person{" + + "name='" + name + '\'' + + ", age=" + age + + '}'; + } +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/PersonBuilder.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/PersonBuilder.java new file mode 100644 index 0000000..afc868e --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/PersonBuilder.java @@ -0,0 +1,5 @@ +package com.zw.zwdemospringboot.service; + +public interface PersonBuilder { + Person builder(String name); +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Printable.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Printable.java new file mode 100644 index 0000000..5b9dac1 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/Printable.java @@ -0,0 +1,8 @@ +package com.zw.zwdemospringboot.service; + + +public interface Printable { + void print(String s); +} + + diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/ZwUserService.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/ZwUserService.java new file mode 100644 index 0000000..ce6cbb2 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/ZwUserService.java @@ -0,0 +1,22 @@ +package com.zw.zwdemospringboot.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.zw.zwdemospringboot.entity.ZwUser; + +import java.util.List; +import java.util.Map; + +public interface ZwUserService { + + Boolean saveCombo(ZwUser dto); + + Boolean updateCombo(ZwUser dto); + + Page pageComboVo(ZwUser dto); + + ZwUser getComboById(Integer id); + + Boolean removeComboById(Integer id); + +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/ZwUserServiceImpl.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/ZwUserServiceImpl.java new file mode 100644 index 0000000..b7ce1c4 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/ZwUserServiceImpl.java @@ -0,0 +1,56 @@ +package com.zw.zwdemospringboot.service; + +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper; +import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; +import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper; +import com.baomidou.mybatisplus.extension.kotlin.KtQueryChainWrapper; +import com.baomidou.mybatisplus.extension.kotlin.KtUpdateChainWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.zw.zwdemospringboot.entity.ZwUser; +import com.zw.zwdemospringboot.mapper.ZwUserMapper; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.Serializable; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; + +@Service +public class ZwUserServiceImpl implements ZwUserService { + + @Autowired + private ZwUserMapper zwUserMapper; + @Override + public Boolean saveCombo(ZwUser dto) { + return null; + } + + @Override + public Boolean updateCombo(ZwUser dto) { + return null; + } + + @Override + public Page pageComboVo(ZwUser dto) { + return null; + } + + @Override + public ZwUser getComboById(Integer id) { + + return zwUserMapper.getComboById(id); + } + + @Override + public Boolean removeComboById(Integer id) { + return null; + } +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/Greetable.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/Greetable.java new file mode 100644 index 0000000..13b609a --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/Greetable.java @@ -0,0 +1,5 @@ +package com.zw.zwdemospringboot.service.father; + +public interface Greetable { + void greet(); +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/Human.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/Human.java new file mode 100644 index 0000000..b6b390d --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/Human.java @@ -0,0 +1,9 @@ +package com.zw.zwdemospringboot.service.father; + +public class Human { + public void say(){ + System.out.println("i am father!"); + } + + +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/Man.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/Man.java new file mode 100644 index 0000000..ff5e7b4 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/Man.java @@ -0,0 +1,23 @@ +package com.zw.zwdemospringboot.service.father; + +public class Man extends Human{ + public void say(){ + System.out.println("i am man!"); + } + + public void method(Greetable g){ + g.greet(); + } + + public void show(){ + method(()->{ + Human human = new Human(); + human.say(); + }); + + method(()->{super.say();}); + method(super::say); + } + + +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/SuperMethodRe.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/SuperMethodRe.java new file mode 100644 index 0000000..eb74212 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/father/SuperMethodRe.java @@ -0,0 +1,8 @@ +package com.zw.zwdemospringboot.service.father; + +public class SuperMethodRe { + public static void main(String[] args) { + Man man = new Man(); + man.show(); + } +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/son/Husband.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/son/Husband.java new file mode 100644 index 0000000..eacc2a6 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/son/Husband.java @@ -0,0 +1,17 @@ +package com.zw.zwdemospringboot.service.son; + +public class Husband { + public void buyHouse(){ + System.out.println("buy it!"); + } + + public void marry(Rich r){ + r.buy(); + } + + public void soHappy(){ + marry(()->this.buyHouse()); + + marry(this::buyHouse); + } +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/son/MethBuy.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/son/MethBuy.java new file mode 100644 index 0000000..52f88ee --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/son/MethBuy.java @@ -0,0 +1,7 @@ +package com.zw.zwdemospringboot.service.son; + +public class MethBuy { + public static void main(String[] args) { + new Husband().soHappy(); + } +} diff --git a/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/son/Rich.java b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/son/Rich.java new file mode 100644 index 0000000..a15d54e --- /dev/null +++ b/ZwDemoSpringBoot/src/main/java/com/zw/zwdemospringboot/service/son/Rich.java @@ -0,0 +1,5 @@ +package com.zw.zwdemospringboot.service.son; + +public interface Rich { + void buy(); +} diff --git a/ZwDemoSpringBoot/src/main/resources/application.yml b/ZwDemoSpringBoot/src/main/resources/application.yml new file mode 100644 index 0000000..0fec954 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/resources/application.yml @@ -0,0 +1,16 @@ +server: + port: 8081 +spring: + datasource: + type: com.zaxxer.hikari.HikariDataSource + url: jdbc:mysql://192.168.2.223:3306/zw_database?useUnicode=true&characterEncoding=utf-8&serverTimezone=America/New_York + username: mepsking + password: Meps@2099fpv + hikari: + minimum-idle: 3 + maximum-pool-size: 5 + auto-commit: true + idle-timeout: 30000 + pool-name: HikariCP_star + max-lifetime: 1800000 + connection-timeout: 30000 diff --git a/ZwDemoSpringBoot/src/main/resources/mapper/ZwUserMapper.xml b/ZwDemoSpringBoot/src/main/resources/mapper/ZwUserMapper.xml new file mode 100644 index 0000000..d6b5019 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/resources/mapper/ZwUserMapper.xml @@ -0,0 +1,33 @@ + + + + + + SELECT id, + user_name, + age + FROM zw_user + + + + + + + + + \ No newline at end of file diff --git a/ZwDemoSpringBoot/src/main/resources/static/index.html b/ZwDemoSpringBoot/src/main/resources/static/index.html new file mode 100644 index 0000000..e2d94a2 --- /dev/null +++ b/ZwDemoSpringBoot/src/main/resources/static/index.html @@ -0,0 +1,6 @@ + + +

hello word!!!

+

this is a html page

+ + \ No newline at end of file diff --git a/ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/InstantTest.java b/ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/InstantTest.java new file mode 100644 index 0000000..18ea3cd --- /dev/null +++ b/ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/InstantTest.java @@ -0,0 +1,63 @@ +package com.zw.zwdemospringboot; + +import com.zw.zwdemospringboot.service.Person; +import org.junit.jupiter.api.Test; + +import java.time.*; + +public class InstantTest { + @Test + public void test1(){ + + Instant now = Instant.now(); + Instant now1 = Instant.now(); + //System.out.println(nano); + try { + Thread.sleep(5); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + Instant now2 = Instant.now(); + System.out.println(now2.getNano() - now.getNano()); + + + } + + @Test + public void test2(){ + LocalTime now = LocalTime.now(); + LocalTime time = LocalTime.of(21, 12, 33); + + System.out.println(now); + System.out.println(time); + //时间差 + Duration duration = Duration.between(now, time); + System.out.println(duration.toDays()); + System.out.println(duration.toHours()); + System.out.println(duration.toMinutes()); + + //日期差 + LocalDate nowDate = LocalDate.now(); + LocalDate date = LocalDate.of(1997, 2, 5); + + Period period = Period.between(date,nowDate); + System.out.println(period.getYears()); + System.out.println(period.getMonths()); + System.out.println(period.getDays()); + + + } + + @Test + public void test3(){ + //ZoneId.getAvailableZoneIds().forEach(System.out::println); + LocalDateTime now = LocalDateTime.now(); + System.out.println("now = " + now); + + ZonedDateTime bz = ZonedDateTime.now(Clock.systemUTC()); + System.out.println("bz = " + bz); + + ZonedDateTime now1 = ZonedDateTime.now(); + System.out.println("now1 = " + now1); + } +} diff --git a/ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/OptionalTest1.java b/ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/OptionalTest1.java new file mode 100644 index 0000000..5d2feae --- /dev/null +++ b/ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/OptionalTest1.java @@ -0,0 +1,27 @@ +package com.zw.zwdemospringboot; + +import com.zw.zwdemospringboot.service.Person; +import org.junit.jupiter.api.Test; + +import java.util.Optional; + +public class OptionalTest1 { + @Test + public void test1(){ + Person tom = new Person("tom", 19); + Optional tom1 = Optional.of(tom); + String name = getNameForOp(tom1); + System.out.println(name); + } + + public String getNameForOp(Optional op){ + if (op.isPresent()){ + String msg = op.map(Person::getName) + //.map(n -> n.toUpperCase()) + .map(String::toUpperCase) + .orElse(null); + return msg; + } + return null; + } +} diff --git a/ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/StreamTest1.java b/ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/StreamTest1.java new file mode 100644 index 0000000..f5e9931 --- /dev/null +++ b/ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/StreamTest1.java @@ -0,0 +1,44 @@ +package com.zw.zwdemospringboot; + +import com.zw.zwdemospringboot.service.Person; +import org.junit.jupiter.api.Test; + +import java.util.IntSummaryStatistics; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class StreamTest1 { + @Test + public void test01(){ + Optional maxAge = Stream.of( + new Person("tom", 18), + new Person("jack", 19), + new Person("jim", 20), + new Person("tony", 21), + new Person("anny", 22)) + .collect(Collectors.maxBy((p1, p2) -> { + return p1.getAge() - p2.getAge(); + })); + System.out.println(maxAge.get()); + + IntSummaryStatistics sumAge = Stream.of( + new Person("tom", 18), + new Person("jack", 19), + new Person("jim", 20), + new Person("tony", 21), + new Person("anny", 22)) + .collect(Collectors.summarizingInt(s -> s.getAge())); + System.out.println(sumAge.getSum()); + + Double avg = Stream.of( + new Person("tom", 18), + new Person("jack", 19), + new Person("jim", 20), + new Person("tony", 21), + new Person("anny", 22)) + .collect(Collectors.averagingInt(Person::getAge)); + System.out.println(avg); + + } +} diff --git a/ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/ZwDemoSpringBootApplicationTests.java b/ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/ZwDemoSpringBootApplicationTests.java new file mode 100644 index 0000000..adf41f2 --- /dev/null +++ b/ZwDemoSpringBoot/src/test/java/com/zw/zwdemospringboot/ZwDemoSpringBootApplicationTests.java @@ -0,0 +1,13 @@ +package com.zw.zwdemospringboot; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ZwDemoSpringBootApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/test1.txt b/test1.txt deleted file mode 100644 index e5b6358..0000000 --- a/test1.txt +++ /dev/null @@ -1,3 +0,0 @@ -123 -3333 -add mytest