From a027e42d05499a8f6005a0d0e85f9175a2dbcb12 Mon Sep 17 00:00:00 2001 From: xiaoyu Date: Fri, 3 Dec 2021 17:36:38 +0800 Subject: [PATCH] add files --- src/main/java/com/example/demo/bo/UserBo.java | 10 ++ .../demo/controller/BaseController.java | 4 - .../demo/controller/StringController.java | 109 ++++++++++++++++++ .../java/com/example/demo/tool/Gengric.java | 16 +++ target/classes/application.yml | 2 + 5 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/example/demo/bo/UserBo.java create mode 100644 src/main/java/com/example/demo/controller/StringController.java create mode 100644 src/main/java/com/example/demo/tool/Gengric.java create mode 100644 target/classes/application.yml diff --git a/src/main/java/com/example/demo/bo/UserBo.java b/src/main/java/com/example/demo/bo/UserBo.java new file mode 100644 index 0000000..00a3307 --- /dev/null +++ b/src/main/java/com/example/demo/bo/UserBo.java @@ -0,0 +1,10 @@ +package com.example.demo.bo; + +import lombok.Data; + + +@Data +public class UserBo { + private int id; + private String name; +} diff --git a/src/main/java/com/example/demo/controller/BaseController.java b/src/main/java/com/example/demo/controller/BaseController.java index 5912c34..169fa39 100644 --- a/src/main/java/com/example/demo/controller/BaseController.java +++ b/src/main/java/com/example/demo/controller/BaseController.java @@ -6,10 +6,6 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; -/** - * @author lixiaoyu - * @since 2:16 下午 - */ @RestController @RequestMapping("/") public class BaseController { diff --git a/src/main/java/com/example/demo/controller/StringController.java b/src/main/java/com/example/demo/controller/StringController.java new file mode 100644 index 0000000..b07ed45 --- /dev/null +++ b/src/main/java/com/example/demo/controller/StringController.java @@ -0,0 +1,109 @@ +package com.example.demo.controller; + +import com.example.demo.bo.UserBo; +import com.example.demo.tool.Gengric; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.*; + + +@RestController +@RequestMapping("/") +public class StringController { + + @GetMapping("/string") + public void stringDemo(){ + //字符 + char charDemo1 = 'x'; + Character charDemo2 = new Character('x'); + + //字符串 + String stringDemo1 = "test"; + String stringDemo2 = new String("test"); + + stringDemo2.length(); //获取长度 + stringDemo2.concat(" user"); //拼接字符串 + stringDemo2.toLowerCase(); //转小写 + stringDemo2.compareTo(stringDemo1); //对比 + stringDemo2.substring(1,3); //截取 + + //字符串缓冲区 + StringBuffer stringDemo3 = new StringBuffer("test"); + stringDemo3.append(" user"); //追加 + stringDemo3.insert(2,"u"); //插入 + stringDemo3.delete(2,3); //删除 + stringDemo3.length(); //获取长度 + stringDemo3.substring(0,2); //截取 + + } + + @GetMapping("/array") + public void arrayDemo(){ + //数组,必须指定大小 + String[] arrDemo1 = new String[3]; + arrDemo1[0] = "str1"; + arrDemo1[1] = "str1"; //值可以重复 + arrDemo1[2] = "str1"; + + String[] arrDemo2 = arrDemo1.clone(); //复制 克隆 + Arrays.fill(arrDemo2,"test2"); //Array类的使用 + + UserBo[] arrDemo3 = new UserBo[5]; //对象数组,不是只能用基本类型 + } + + @GetMapping("/arraylist") + public void arraylistDemo(){ + //泛型可以接收任何参数 + Gengric aDemo1 =new Gengric<>(); + aDemo1.setDemo1("string"); + //不只是基本数据类型 + Gengric aDemo2 =new Gengric<>(); + UserBo userBo = new UserBo(); + aDemo2.setDemo1(userBo); + + //单向链表 + LinkedList aDemo3 = new LinkedList<>(); + aDemo3.add("str1"); //插入 + aDemo3.get(0); //获取 + aDemo3.addFirst("str2"); //头部添加 + aDemo3.addLast("str3"); //尾部添加 + aDemo3.size(); //长度 + + //动态数组 + ArrayList aDemo4 = new ArrayList<>(); + aDemo4.add(userBo); + aDemo4.add("str5"); + aDemo4.add(100); //可以加入不同数据类型 + + //HashSet + HashSet aDemo5 = new HashSet<>(); + aDemo5.add(1); + aDemo5.add(2); + + //TreeSet + TreeSet aDemo6 = new TreeSet<>(); + aDemo6.add(20); + aDemo6.add(10); + aDemo6.add(50); + + //HashMap + HashMap aDemo7 = new HashMap<>(); + aDemo7.put(5,"str8"); + aDemo7.put(1,"str9"); + aDemo7.put(3,"str10"); + + + //TreeMap + TreeMap aDemo8 = new TreeMap<>(); + aDemo8.put(5,"str8"); + aDemo8.put(1,"str9"); + aDemo8.put(3,"str10"); + + + + } + + +} diff --git a/src/main/java/com/example/demo/tool/Gengric.java b/src/main/java/com/example/demo/tool/Gengric.java new file mode 100644 index 0000000..379f15c --- /dev/null +++ b/src/main/java/com/example/demo/tool/Gengric.java @@ -0,0 +1,16 @@ +package com.example.demo.tool; + +/** + * 泛型的类 + * @param + */ +public class Gengric { + private T demo1; + public void setDemo1(T demo1){ + this.demo1 = demo1; + } + + public T getDemo1(){ + return this.demo1; + } +} diff --git a/target/classes/application.yml b/target/classes/application.yml new file mode 100644 index 0000000..127205d --- /dev/null +++ b/target/classes/application.yml @@ -0,0 +1,2 @@ +server: + port: 8099 -- GitLab