diff --git a/SpringBootMybatisRedisCache/SpringBootMybatisRedisCache.iml b/SpringBootMybatisRedisCache/SpringBootMybatisRedisCache.iml new file mode 100644 index 0000000..e6b1dac --- /dev/null +++ b/SpringBootMybatisRedisCache/SpringBootMybatisRedisCache.iml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SpringBootMybatisRedisCache/pom.xml b/SpringBootMybatisRedisCache/pom.xml new file mode 100644 index 0000000..1a280b5 --- /dev/null +++ b/SpringBootMybatisRedisCache/pom.xml @@ -0,0 +1,75 @@ + + + + SpringBoot2 + zz + 0.0.1-SNAPSHOT + + 4.0.0 + + SpringBootMybatisRedisCache + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-starter-web + + + com.alibaba + fastjson + 1.2.38 + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 1.3.1 + + + mysql + mysql-connector-java + 8.0.15 + + + org.projectlombok + lombok + true + + + + + + alimaven + aliyun maven + http://maven.aliyun.com/nexus/content/groups/public/ + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/SpringBootMybatisRedisCache/src/main/resources/dump-java10-201909152127.sql b/SpringBootMybatisRedisCache/src/main/resources/dump-java10-201909152127.sql new file mode 100644 index 0000000..8b1af1e --- /dev/null +++ b/SpringBootMybatisRedisCache/src/main/resources/dump-java10-201909152127.sql @@ -0,0 +1,52 @@ +-- MySQL dump 10.13 Distrib 8.0.12, for Win64 (x86_64) +-- +-- Host: localhost Database: java10 +-- ------------------------------------------------------ +-- Server version 8.0.12 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; + SET NAMES utf8mb4 ; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `computer` +-- + +DROP TABLE IF EXISTS `computer`; +/*!40101 SET @saved_cs_client = @@character_set_client */; + SET character_set_client = utf8mb4 ; +CREATE TABLE `computer` ( + `id` int(11) NOT NULL, + `name` varchar(100) DEFAULT NULL, + `price` double DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `computer` +-- + +LOCK TABLES `computer` WRITE; +/*!40000 ALTER TABLE `computer` DISABLE KEYS */; +INSERT INTO `computer` VALUES (1,'神州',6000),(2,'联想',7000),(3,'apple',9000); +/*!40000 ALTER TABLE `computer` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2019-09-15 21:27:09 diff --git a/SpringBootRedis/SpringBootRedis.iml b/SpringBootRedis/SpringBootRedis.iml new file mode 100644 index 0000000..a53c59b --- /dev/null +++ b/SpringBootRedis/SpringBootRedis.iml @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SpringBootRedis/pom.xml b/SpringBootRedis/pom.xml new file mode 100644 index 0000000..8f5ed6d --- /dev/null +++ b/SpringBootRedis/pom.xml @@ -0,0 +1,67 @@ + + + + SpringBoot2 + zz + 0.0.1-SNAPSHOT + + 4.0.0 + + SpringBootRedis + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-devtools + true + + + + + mysql + mysql-connector-java + 8.0.15 + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + org.springframework.boot + spring-boot-starter-test + test + + + com.alibaba + fastjson + 1.2.38 + + + + + + alimaven + aliyun maven + http://maven.aliyun.com/nexus/content/groups/public/ + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/SpringBootRedis/src/main/java/com/zz/service/RedisTemplateService.java b/SpringBootRedis/src/main/java/com/zz/service/RedisTemplateService.java new file mode 100644 index 0000000..f5be482 --- /dev/null +++ b/SpringBootRedis/src/main/java/com/zz/service/RedisTemplateService.java @@ -0,0 +1,89 @@ +package com.zz.service; + +/** + * @Description: java类作用描述 + * @Author: Bsea + * @CreateDate: 2019/9/15$ 20:28$ + */ +import com.alibaba.fastjson.JSON; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; + +@Service +public class RedisTemplateService { + + @Autowired + StringRedisTemplate stringRedisTemplate; + + public boolean set(String key ,T value){ + + try { + + //任意类型转换成String + String val = beanToString(value); + + if(val==null||val.length()<=0){ + return false; + } + + stringRedisTemplate.opsForValue().set(key,val); + return true; + }catch (Exception e){ + return false; + } + } + public T get(String key,Class clazz){ + try { + String value = stringRedisTemplate.opsForValue().get(key); + + return stringToBean(value,clazz); + }catch (Exception e){ + return null ; + } + } + + @SuppressWarnings("unchecked") + private T stringToBean(String value, Class clazz) { + if(value==null||value.length()<=0||clazz==null){ + return null; + } + + if(clazz ==int.class ||clazz==Integer.class){ + return (T)Integer.valueOf(value); + } + else if(clazz==long.class||clazz==Long.class){ + return (T)Long.valueOf(value); + } + else if(clazz==String.class){ + return (T)value; + }else { + return JSON.toJavaObject(JSON.parseObject(value),clazz); + } + } + + /** + * + * @return String + */ + private String beanToString(T value) { + + if(value==null){ + return null; + } + Class clazz = value.getClass(); + if(clazz==int.class||clazz==Integer.class){ + return ""+value; + } + else if(clazz==long.class||clazz==Long.class){ + return ""+value; + } + else if(clazz==String.class){ + return (String)value; + }else { + return JSON.toJSONString(value); + } + } + +} + diff --git a/SpringBootRedis/src/test/java/com/zz/RedisTest.java b/SpringBootRedis/src/test/java/com/zz/RedisTest.java new file mode 100644 index 0000000..9b9113d --- /dev/null +++ b/SpringBootRedis/src/test/java/com/zz/RedisTest.java @@ -0,0 +1,53 @@ +package com.zz; + +/** + * @Description: java类作用描述 + * @Author: Bsea + * @CreateDate: 2019/9/15$ 20:25$ + */ +import com.zz.App; +import com.zz.entity.User; +import com.zz.service.RedisTemplateService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = App.class) +public class RedisTest { + + @Autowired + StringRedisTemplate stringRedisTemplate; + + @Autowired + RedisTemplateService redisTemplateService; + @Test + public void test() { + // 保存字符串 + stringRedisTemplate.opsForValue().set("aaa", "111"); + } + + @Test + public void test1() { + // 取字符串 + String val=stringRedisTemplate.opsForValue().get("aaa"); + System.out.println(val); + } + @Test + public void redisTestObject(){ + + User user = new User(); + user.setName("张三"); + user.setAge(21); + user.setId("1"); + redisTemplateService.set("key1",user); + + User us = redisTemplateService.get("key1",User.class); + System.out.println(us.getName()+": "+us.getAge()); + } +} + + diff --git a/corejava/corejava.iml b/corejava/corejava.iml new file mode 100644 index 0000000..c035f0b --- /dev/null +++ b/corejava/corejava.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/corejava/pom.xml b/corejava/pom.xml new file mode 100644 index 0000000..142eb9e --- /dev/null +++ b/corejava/pom.xml @@ -0,0 +1,15 @@ + + + + SpringBoot2 + zz + 0.0.1-SNAPSHOT + + 4.0.0 + + corejava + + + \ No newline at end of file diff --git a/corejava/src/main/java/com/zz/ChildA.java b/corejava/src/main/java/com/zz/ChildA.java new file mode 100644 index 0000000..2cb4fd1 --- /dev/null +++ b/corejava/src/main/java/com/zz/ChildA.java @@ -0,0 +1,12 @@ +package com.zz; + +/** + * @Description: java类作用描述 + * @Author: Bsea + * @CreateDate: 2019/9/15$ 16:27$ + */ +public class ChildA extends Parent{ + public void printPrice(){ + System.out.println("这是ChildA方法"); + } +} diff --git a/corejava/src/main/java/com/zz/ChildB.java b/corejava/src/main/java/com/zz/ChildB.java new file mode 100644 index 0000000..4e43dfc --- /dev/null +++ b/corejava/src/main/java/com/zz/ChildB.java @@ -0,0 +1,12 @@ +package com.zz; + +/** + * @Description: java类作用描述 + * @Author: Bsea + * @CreateDate: 2019/9/15$ 16:27$ + */ +public class ChildB extends Parent{ + public void printPrice(){ + System.out.println("这是ChildB方法"); + } +} diff --git a/corejava/src/main/java/com/zz/Parent.java b/corejava/src/main/java/com/zz/Parent.java new file mode 100644 index 0000000..59b3a11 --- /dev/null +++ b/corejava/src/main/java/com/zz/Parent.java @@ -0,0 +1,14 @@ +package com.zz; + +/** + * @Description: java类作用描述 + * @Author: Bsea + * @CreateDate: 2019/9/15$ 16:25$ + */ +public class Parent { + + + public void printPrice(){ + System.out.println("这是父类方法"); + } +} diff --git a/corejava/src/main/java/com/zz/Test.java b/corejava/src/main/java/com/zz/Test.java new file mode 100644 index 0000000..9ef7865 --- /dev/null +++ b/corejava/src/main/java/com/zz/Test.java @@ -0,0 +1,19 @@ +package com.zz; + +/** + * @Description: java类作用描述 + * @Author: Bsea + * @CreateDate: 2019/9/15$ 16:28$ + */ +public class Test { + public static void main(String[] args) { + Parent a=new ChildA(); + Parent b=new ChildB(); + printName(b); + } + + + static void printName(Parent p){ + p.printPrice(); + } +} diff --git a/pom.xml b/pom.xml index df5cefd..f4f3a81 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,9 @@ SpringBootMybatis SpringBootShiroJWT SpringBootAngularjs + corejava + SpringBootRedis + SpringBootMybatisRedisCache