From a76d4d728b6452c683d721f6c5873e8e1ba062a9 Mon Sep 17 00:00:00 2001 From: bseayin Date: Sun, 15 Sep 2019 21:33:38 +0800 Subject: [PATCH] authorization --- .../src/main/java/com/zz/Application.java | 15 ++ .../main/java/com/zz/config/RedisConfig.java | 83 ++++++++++ .../com/zz/controller/ComputerController.java | 40 +++++ .../src/main/java/com/zz/entity/Computer.java | 35 ++++ .../src/main/java/com/zz/entity/User.java | 103 ++++++++++++ .../java/com/zz/mapper/ComputerMapper.java | 19 +++ .../main/java/com/zz/mapper/UserMapper.java | 17 ++ .../java/com/zz/service/ComputerService.java | 119 ++++++++++++++ .../com/zz/service/RedisTemplateService.java | 83 ++++++++++ .../zz/service/impl/ComputerServiceImpl.java | 52 ++++++ .../src/main/resources/application.properties | 27 ++++ .../main/resources/mapping/ComputerMapper.xml | 71 ++++++++ .../src/main/resources/mapping/UserMapper.xml | 152 ++++++++++++++++++ 13 files changed, 816 insertions(+) create mode 100644 SpringBootMybatisRedisCache/src/main/java/com/zz/Application.java create mode 100644 SpringBootMybatisRedisCache/src/main/java/com/zz/config/RedisConfig.java create mode 100644 SpringBootMybatisRedisCache/src/main/java/com/zz/controller/ComputerController.java create mode 100644 SpringBootMybatisRedisCache/src/main/java/com/zz/entity/Computer.java create mode 100644 SpringBootMybatisRedisCache/src/main/java/com/zz/entity/User.java create mode 100644 SpringBootMybatisRedisCache/src/main/java/com/zz/mapper/ComputerMapper.java create mode 100644 SpringBootMybatisRedisCache/src/main/java/com/zz/mapper/UserMapper.java create mode 100644 SpringBootMybatisRedisCache/src/main/java/com/zz/service/ComputerService.java create mode 100644 SpringBootMybatisRedisCache/src/main/java/com/zz/service/RedisTemplateService.java create mode 100644 SpringBootMybatisRedisCache/src/main/java/com/zz/service/impl/ComputerServiceImpl.java create mode 100644 SpringBootMybatisRedisCache/src/main/resources/application.properties create mode 100644 SpringBootMybatisRedisCache/src/main/resources/mapping/ComputerMapper.xml create mode 100644 SpringBootMybatisRedisCache/src/main/resources/mapping/UserMapper.xml diff --git a/SpringBootMybatisRedisCache/src/main/java/com/zz/Application.java b/SpringBootMybatisRedisCache/src/main/java/com/zz/Application.java new file mode 100644 index 0000000..27153a5 --- /dev/null +++ b/SpringBootMybatisRedisCache/src/main/java/com/zz/Application.java @@ -0,0 +1,15 @@ +package com.zz; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; + +@SpringBootApplication +@EnableCaching +@MapperScan("com.zz.mapper") +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class); + } +} diff --git a/SpringBootMybatisRedisCache/src/main/java/com/zz/config/RedisConfig.java b/SpringBootMybatisRedisCache/src/main/java/com/zz/config/RedisConfig.java new file mode 100644 index 0000000..b991511 --- /dev/null +++ b/SpringBootMybatisRedisCache/src/main/java/com/zz/config/RedisConfig.java @@ -0,0 +1,83 @@ +package com.zz.config; + +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.cache.RedisCacheWriter; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +import java.time.Duration; + +@Configuration +public class RedisConfig extends CachingConfigurerSupport { + + // 自定义缓存key生成策略 + @Bean + public KeyGenerator keyGenerator() { + return new KeyGenerator() { + @Override + public Object generate(Object target, java.lang.reflect.Method method, Object... params) { + StringBuffer sb = new StringBuffer(); + sb.append(target.getClass().getName()); + sb.append(method.getName()); + for (Object obj : params) { + sb.append(obj.toString()); + } + return sb.toString(); + } + }; + } + + // 缓存管理器 + @Bean + public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) { + RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig() + .entryTtl(Duration.ofHours(1)); // 设置缓存有效期一小时 + return RedisCacheManager + .builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory)) + .cacheDefaults(redisCacheConfiguration).build(); + } + + @Bean + @SuppressWarnings({"rawtypes", "unchecked"}) + public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory){ + RedisTemplate redisTemplate=new RedisTemplate<>(); + redisTemplate.setConnectionFactory(connectionFactory); + //使用Jackson2JsonRedisSerializer替换默认的序列化规则 + Jackson2JsonRedisSerializer jackson2JsonRedisSerializer=new Jackson2JsonRedisSerializer(Object.class); + ObjectMapper objectMapper=new ObjectMapper(); + objectMapper.setVisibility(PropertyAccessor.ALL,JsonAutoDetect.Visibility.ANY); + objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); + jackson2JsonRedisSerializer.setObjectMapper(objectMapper); + + + //设置value的序列化规则 + redisTemplate.setValueSerializer(jackson2JsonRedisSerializer); + //设置key的序列化规则 + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.afterPropertiesSet(); + return redisTemplate; + } + +// private void setSerializer(StringRedisTemplate template) { +// @SuppressWarnings({ "rawtypes", "unchecked" }) +// Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); +// ObjectMapper om = new ObjectMapper(); +// om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); +// om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); +// jackson2JsonRedisSerializer.setObjectMapper(om); +// template.setValueSerializer(jackson2JsonRedisSerializer); +// } +} diff --git a/SpringBootMybatisRedisCache/src/main/java/com/zz/controller/ComputerController.java b/SpringBootMybatisRedisCache/src/main/java/com/zz/controller/ComputerController.java new file mode 100644 index 0000000..f5d20c9 --- /dev/null +++ b/SpringBootMybatisRedisCache/src/main/java/com/zz/controller/ComputerController.java @@ -0,0 +1,40 @@ +package com.zz.controller; + +import com.zz.entity.Computer; +import com.zz.service.ComputerService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; + +@RestController +public class ComputerController { + @Resource + ComputerService computerService; + + @GetMapping("/get/{id}") + public Computer getComputer(@PathVariable("id") Long id) { + System.out.println("*******getComputer***" + id); + return computerService.selectByPrimaryKey(id); + } + @GetMapping("/del/{id}") + public int delComputer(@PathVariable("id") Long id) { + System.out.println("*******delComputer***" + id); + return computerService.deleteByPrimaryKey(id); + } + + @GetMapping("/update/{id}/{name}") + public Computer updateComputer(@PathVariable("id") Long id, @PathVariable("name") String name) { + System.out.println("*******getComputer***" + id); + Computer computer = new Computer(); + computer.setId(id); + computer.setName(name); + return computerService.updateByPrimaryKeySelective(computer); + } + @PostMapping("/updatecomputer") + public Computer updateComputer2(Computer computer) { + System.out.println("*******getComputer***" + computer.getName()); + return computerService.updateByPrimaryKeySelective(computer); + } +} diff --git a/SpringBootMybatisRedisCache/src/main/java/com/zz/entity/Computer.java b/SpringBootMybatisRedisCache/src/main/java/com/zz/entity/Computer.java new file mode 100644 index 0000000..0e3266e --- /dev/null +++ b/SpringBootMybatisRedisCache/src/main/java/com/zz/entity/Computer.java @@ -0,0 +1,35 @@ +package com.zz.entity; + +import java.io.Serializable; + +public class Computer implements Serializable { + private Long id; + + private String name; + + private Double price; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name == null ? null : name.trim(); + } + + public Double getPrice() { + return price; + } + + public void setPrice(Double price) { + this.price = price; + } +} \ No newline at end of file diff --git a/SpringBootMybatisRedisCache/src/main/java/com/zz/entity/User.java b/SpringBootMybatisRedisCache/src/main/java/com/zz/entity/User.java new file mode 100644 index 0000000..1c8c8cd --- /dev/null +++ b/SpringBootMybatisRedisCache/src/main/java/com/zz/entity/User.java @@ -0,0 +1,103 @@ +package com.zz.entity; + +public class User { + private Integer id; + + private String name; + + private String pwd; + + private Integer age; + + private String sex; + + private String email; + + private String mobile; + + private Long productId; + + private String password; + + private String username; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name == null ? null : name.trim(); + } + + public String getPwd() { + return pwd; + } + + public void setPwd(String pwd) { + this.pwd = pwd == null ? null : pwd.trim(); + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex == null ? null : sex.trim(); + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email == null ? null : email.trim(); + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile == null ? null : mobile.trim(); + } + + public Long getProductId() { + return productId; + } + + public void setProductId(Long productId) { + this.productId = productId; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password == null ? null : password.trim(); + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username == null ? null : username.trim(); + } +} \ No newline at end of file diff --git a/SpringBootMybatisRedisCache/src/main/java/com/zz/mapper/ComputerMapper.java b/SpringBootMybatisRedisCache/src/main/java/com/zz/mapper/ComputerMapper.java new file mode 100644 index 0000000..7fc50a1 --- /dev/null +++ b/SpringBootMybatisRedisCache/src/main/java/com/zz/mapper/ComputerMapper.java @@ -0,0 +1,19 @@ +package com.zz.mapper; + +import com.zz.entity.Computer; +import org.springframework.cache.annotation.CacheConfig; + +@CacheConfig(cacheNames = "computer") +public interface ComputerMapper { + int deleteByPrimaryKey(Long id); + + int insert(Computer record); + + int insertSelective(Computer record); + + Computer selectByPrimaryKey(Long id); + + int updateByPrimaryKeySelective(Computer record); + + int updateByPrimaryKey(Computer record); +} \ No newline at end of file diff --git a/SpringBootMybatisRedisCache/src/main/java/com/zz/mapper/UserMapper.java b/SpringBootMybatisRedisCache/src/main/java/com/zz/mapper/UserMapper.java new file mode 100644 index 0000000..13023ce --- /dev/null +++ b/SpringBootMybatisRedisCache/src/main/java/com/zz/mapper/UserMapper.java @@ -0,0 +1,17 @@ +package com.zz.mapper; + +import com.zz.entity.User; + +public interface UserMapper { + int deleteByPrimaryKey(Integer id); + + int insert(User record); + + int insertSelective(User record); + + User selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(User record); + + int updateByPrimaryKey(User record); +} \ No newline at end of file diff --git a/SpringBootMybatisRedisCache/src/main/java/com/zz/service/ComputerService.java b/SpringBootMybatisRedisCache/src/main/java/com/zz/service/ComputerService.java new file mode 100644 index 0000000..a1179a0 --- /dev/null +++ b/SpringBootMybatisRedisCache/src/main/java/com/zz/service/ComputerService.java @@ -0,0 +1,119 @@ +package com.zz.service; + +import com.zz.entity.Computer; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.CachePut; +import org.springframework.cache.annotation.Cacheable; + +//@CacheConfig(cacheNames = "computer") +public interface ComputerService { +// @CacheEvict(key = "#p0", allEntries = true) + int deleteByPrimaryKey(Long id); + + int insert(Computer record); + + int insertSelective(Computer record); +// @Cacheable(key = "#p0") + Computer selectByPrimaryKey(Long id); + @CachePut(key = "#p0.id") + Computer updateByPrimaryKeySelective(Computer record); + + int updateByPrimaryKey(Computer record); +} +/** + * + * 1 基于注解的支持 + * Spring为我们提供了几个注解来支持Spring Cache。其核心主要是@Cacheable和@CacheEvict。使用@Cacheable标记的方法在执行后Spring Cache将缓存其返回结果,而使用@CacheEvict标记的方法会在方法执行前或者执行后移除Spring Cache中的某些元素。下面我们将来详细介绍一下Spring基于注解对Cache的支持所提供的几个注解。 + * + * 1.1 @Cacheable + * @Cacheable可以标记在一个方法上,也可以标记在一个类上。当标记在一个方法上时表示该方法是支持缓存的,当标记在一个类上时则表示该类所有的方法都是支持缓存的。对于一个支持缓存的方法,Spring会在其被调用后将其返回值缓存起来,以保证下次利用同样的参数来执行该方法时可以直接从缓存中获取结果,而不需要再次执行该方法。Spring在缓存方法的返回值时是以键值对进行缓存的,值就是方法的返回结果,至于键的话,Spring又支持两种策略,默认策略和自定义策略,这个稍后会进行说明。需要注意的是当一个支持缓存的方法在对象内部被调用时是不会触发缓存功能的。@Cacheable可以指定三个属性,value、key和condition。 + * + * 1.1.1 value属性指定Cache名称 + * value属性是必须指定的,其表示当前方法的返回值是会被缓存在哪个Cache上的,对应Cache的名称。其可以是一个Cache也可以是多个Cache,当需要指定多个Cache时其是一个数组。 + * + * @Cacheable("cache1")//Cache是发生在cache1上的 + * + * public User find(Integer id) { + * + * returnnull; + * + * } + * + * + * + * @Cacheable({"cache1", "cache2"})//Cache是发生在cache1和cache2上的 + * + * public User find(Integer id) { + * + * returnnull; + * + * } + * + * + * + * 1.1.2 使用key属性自定义key + * key属性是用来指定Spring缓存方法的返回结果时对应的key的。该属性支持SpringEL表达式。当我们没有指定该属性时,Spring将使用默认策略生成key。我们这里先来看看自定义策略,至于默认策略会在后文单独介绍。 + * + * 自定义策略是指我们可以通过Spring的EL表达式来指定我们的key。这里的EL表达式可以使用方法参数及它们对应的属性。使用方法参数时我们可以直接使用“#参数名”或者“#p参数index”。下面是几个使用参数作为key的示例。 + * + * @Cacheable(value="users", key="#id") + * + * public User find(Integer id) { + * + * returnnull; + * + * } + * + * + * + * @Cacheable(value="users", key="#p0") + * + * public User find(Integer id) { + * + * returnnull; + * + * } + * + * + * + * @Cacheable(value="users", key="#user.id") + * + * public User find(User user) { + * + * returnnull; + * + * } + * 1.2 @CachePut + * 在支持Spring Cache的环境下,对于使用@Cacheable标注的方法,Spring在每次执行前都会检查Cache中是否存在相同key的缓存元素,如果存在就不再执行该方法,而是直接从缓存中获取结果进行返回,否则才会执行并将返回结果存入指定的缓存中。@CachePut也可以声明一个方法支持缓存功能。与@Cacheable不同的是使用@CachePut标注的方法在执行前不会去检查缓存中是否存在之前执行过的结果,而是每次都会执行该方法,并将执行结果以键值对的形式存入指定的缓存中。 + * + * @CachePut也可以标注在类上和方法上。使用@CachePut时我们可以指定的属性跟@Cacheable是一样的。 + * + * @CachePut("users")//每次都会执行方法,并将结果存入指定的缓存中 + * + * public User find(Integer id) { + * + * returnnull; + * + * } + * + * + * + * 1.3 @CacheEvict + * @CacheEvict是用来标注在需要清除缓存元素的方法或类上的。当标记在一个类上时表示其中所有的方法的执行都会触发缓存的清除操作。@CacheEvict可以指定的属性有value、key、condition、allEntries和beforeInvocation。其中value、key和condition的语义与@Cacheable对应的属性类似。即value表示清除操作是发生在哪些Cache上的(对应Cache的名称);key表示需要清除的是哪个key,如未指定则会使用默认策略生成的key;condition表示清除操作发生的条件。下面我们来介绍一下新出现的两个属性allEntries和beforeInvocation。 + * + * 1.3.1 allEntries属性 + * allEntries是boolean类型,表示是否需要清除缓存中的所有元素。默认为false,表示不需要。当指定了allEntries为true时,Spring Cache将忽略指定的key。有的时候我们需要Cache一下清除所有的元素,这比一个一个清除元素更有效率。 + * + * @CacheEvict(value="users", allEntries=true) + * + * public void delete(Integer id) { + * + * System.out.println("delete user by id: " + id); + * + * } + * + * + * + * + */ diff --git a/SpringBootMybatisRedisCache/src/main/java/com/zz/service/RedisTemplateService.java b/SpringBootMybatisRedisCache/src/main/java/com/zz/service/RedisTemplateService.java new file mode 100644 index 0000000..7726cdd --- /dev/null +++ b/SpringBootMybatisRedisCache/src/main/java/com/zz/service/RedisTemplateService.java @@ -0,0 +1,83 @@ +package com.zz.service; + +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/SpringBootMybatisRedisCache/src/main/java/com/zz/service/impl/ComputerServiceImpl.java b/SpringBootMybatisRedisCache/src/main/java/com/zz/service/impl/ComputerServiceImpl.java new file mode 100644 index 0000000..af7f80f --- /dev/null +++ b/SpringBootMybatisRedisCache/src/main/java/com/zz/service/impl/ComputerServiceImpl.java @@ -0,0 +1,52 @@ +package com.zz.service.impl; + +import com.zz.entity.Computer; +import com.zz.mapper.ComputerMapper; +import com.zz.service.ComputerService; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.CachePut; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +@Service +@CacheConfig(cacheNames = "computer") +public class ComputerServiceImpl implements ComputerService { + @Resource + ComputerMapper computerMapper; + @Override + @CacheEvict(key = "#p0.toString()", allEntries = true) + public int deleteByPrimaryKey(Long id) { + return 0; + } + + @Override + public int insert(Computer record) { + return 0; + } + + @Override + public int insertSelective(Computer record) { + return 0; + } + + @Override + @Cacheable(key = "#p0.toString()") + public Computer selectByPrimaryKey(Long id) { + return computerMapper.selectByPrimaryKey(id); + } + + @Override + @CachePut(key = "#p0.id.toString()") + public Computer updateByPrimaryKeySelective(Computer record) { + computerMapper.updateByPrimaryKeySelective(record); + return computerMapper.selectByPrimaryKey(record.getId()); + } + + @Override + public int updateByPrimaryKey(Computer record) { + return 0; + } +} diff --git a/SpringBootMybatisRedisCache/src/main/resources/application.properties b/SpringBootMybatisRedisCache/src/main/resources/application.properties new file mode 100644 index 0000000..e9b3ffe --- /dev/null +++ b/SpringBootMybatisRedisCache/src/main/resources/application.properties @@ -0,0 +1,27 @@ +#Redis +#spring.redis.host=127.0.0.1 +redis.host=127.0.0.1 +## Redis服务器连接端口 +redis.port=6379 +## 连接超时时间(毫秒) +redis.timeout=3 +## Redis服务器连接密码(默认为空) +#redis.password=135246 +## 连接池中的最大连接数 +redis.poolMaxTotal=10 +## 连接池中的最大空闲连接 +redis.poolMaxIdle=10 +## 连接池最大阻塞等待时间(使用负值表示没有限制) +redis.poolMaxWait=3 + +## Mybatis 配置 +spring.datasource.url = jdbc:mysql://localhost:3306/java10?useSSL=false&serverTimezone=Asia/Shanghai +spring.datasource.username = root +spring.datasource.password = Java20190713*yy +spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver + + +mybatis.typeAliasesPackage=org.spring.springboot.domain +#mybatis.mapperLocations=classpath:com/zz/mapping/*.xml,com/zz/EDGE/mapping/*.xml,com/zz/jwh/mapping/*.xml,com/zz/hc/mapping/*.xml,com/zz/simpleSpade/mapping/*.xml,com/zz/lsw/mapping/*.xml,com/zz/wsq/mapping/*.xml,com/zz/zcj/mapping/*.xml +mybatis.mapperLocations=classpath:mapping/*.xml +logging.level.com.zz.mapper=DEBUG diff --git a/SpringBootMybatisRedisCache/src/main/resources/mapping/ComputerMapper.xml b/SpringBootMybatisRedisCache/src/main/resources/mapping/ComputerMapper.xml new file mode 100644 index 0000000..776a30e --- /dev/null +++ b/SpringBootMybatisRedisCache/src/main/resources/mapping/ComputerMapper.xml @@ -0,0 +1,71 @@ + + + + + + + + + + id, name, price + + + + delete from computer + where id = #{id,jdbcType=BIGINT} + + + insert into computer (id, name, price + ) + values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{price,jdbcType=DOUBLE} + ) + + + insert into computer + + + id, + + + name, + + + price, + + + + + #{id,jdbcType=BIGINT}, + + + #{name,jdbcType=VARCHAR}, + + + #{price,jdbcType=DOUBLE}, + + + + + update computer + + + name = #{name,jdbcType=VARCHAR}, + + + price = #{price,jdbcType=DOUBLE}, + + + where id = #{id,jdbcType=BIGINT} + + + update computer + set name = #{name,jdbcType=VARCHAR}, + price = #{price,jdbcType=DOUBLE} + where id = #{id,jdbcType=BIGINT} + + \ No newline at end of file diff --git a/SpringBootMybatisRedisCache/src/main/resources/mapping/UserMapper.xml b/SpringBootMybatisRedisCache/src/main/resources/mapping/UserMapper.xml new file mode 100644 index 0000000..5a1fa29 --- /dev/null +++ b/SpringBootMybatisRedisCache/src/main/resources/mapping/UserMapper.xml @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + id, name, pwd, age, sex, email, mobile, product_id, password, username + + + + delete from user + where id = #{id,jdbcType=INTEGER} + + + insert into user (id, name, pwd, + age, sex, email, mobile, + product_id, password, username + ) + values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR}, + #{age,jdbcType=INTEGER}, #{sex,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, + #{productId,jdbcType=BIGINT}, #{password,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR} + ) + + + insert into user + + + id, + + + name, + + + pwd, + + + age, + + + sex, + + + email, + + + mobile, + + + product_id, + + + password, + + + username, + + + + + #{id,jdbcType=INTEGER}, + + + #{name,jdbcType=VARCHAR}, + + + #{pwd,jdbcType=VARCHAR}, + + + #{age,jdbcType=INTEGER}, + + + #{sex,jdbcType=VARCHAR}, + + + #{email,jdbcType=VARCHAR}, + + + #{mobile,jdbcType=VARCHAR}, + + + #{productId,jdbcType=BIGINT}, + + + #{password,jdbcType=VARCHAR}, + + + #{username,jdbcType=VARCHAR}, + + + + + update user + + + name = #{name,jdbcType=VARCHAR}, + + + pwd = #{pwd,jdbcType=VARCHAR}, + + + age = #{age,jdbcType=INTEGER}, + + + sex = #{sex,jdbcType=VARCHAR}, + + + email = #{email,jdbcType=VARCHAR}, + + + mobile = #{mobile,jdbcType=VARCHAR}, + + + product_id = #{productId,jdbcType=BIGINT}, + + + password = #{password,jdbcType=VARCHAR}, + + + username = #{username,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=INTEGER} + + + update user + set name = #{name,jdbcType=VARCHAR}, + pwd = #{pwd,jdbcType=VARCHAR}, + age = #{age,jdbcType=INTEGER}, + sex = #{sex,jdbcType=VARCHAR}, + email = #{email,jdbcType=VARCHAR}, + mobile = #{mobile,jdbcType=VARCHAR}, + product_id = #{productId,jdbcType=BIGINT}, + password = #{password,jdbcType=VARCHAR}, + username = #{username,jdbcType=VARCHAR} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file