- demo 项目,增加 redis 库
This commit is contained in:
@@ -0,0 +1 @@
|
||||
package cn.iocoder.mall.demo.business.cacheobject;
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.iocoder.mall.demo.business.cacheobject.user;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 用户缓存对象
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DemoUserCacheObject {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
private Integer gender;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.iocoder.mall.demo.business.convert;
|
||||
|
||||
import cn.iocoder.mall.demo.business.bo.user.DemoUserBO;
|
||||
import cn.iocoder.mall.demo.business.cacheobject.user.DemoUserCacheObject;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface DemoUserConvert {
|
||||
|
||||
DemoUserConvert INSTANCE = Mappers.getMapper(DemoUserConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
DemoUserBO convert(DemoUserCacheObject object);
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.mall.demo.business.dao;
|
||||
package cn.iocoder.mall.demo.business.dao.mysql;
|
||||
|
||||
import cn.iocoder.mall.demo.business.dataobject.order.DemoOrderDO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.mall.demo.business.dao;
|
||||
package cn.iocoder.mall.demo.business.dao.mysql;
|
||||
|
||||
import cn.iocoder.mall.demo.business.dataobject.product.DemoProductDO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
@@ -0,0 +1,31 @@
|
||||
package cn.iocoder.mall.demo.business.dao.redis;
|
||||
|
||||
import cn.iocoder.mall.demo.business.cacheobject.user.DemoUserCacheObject;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Repository
|
||||
public class DemoUserCacheDao {
|
||||
|
||||
private static final String KEY_PREFIX = "user_";
|
||||
|
||||
@Resource(name = "redisTemplate")
|
||||
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
|
||||
private ValueOperations<String, String> operations;
|
||||
|
||||
private static String buildKey(Integer id) {
|
||||
return KEY_PREFIX + id;
|
||||
}
|
||||
|
||||
public DemoUserCacheObject get(Integer id) {
|
||||
return JSON.parseObject(operations.get(buildKey(id)), DemoUserCacheObject.class);
|
||||
}
|
||||
|
||||
public void set(Integer id, DemoUserCacheObject value) {
|
||||
operations.set(buildKey(id), JSON.toJSONString(value));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import cn.iocoder.mall.demo.business.bo.product.DemoProductBO;
|
||||
import cn.iocoder.mall.demo.business.bo.product.DemoProductQuantityReduceBO;
|
||||
import cn.iocoder.mall.demo.business.constant.OrderStatusEnum;
|
||||
import cn.iocoder.mall.demo.business.convert.DemoOrderConvert;
|
||||
import cn.iocoder.mall.demo.business.dao.DemoOrderMapper;
|
||||
import cn.iocoder.mall.demo.business.dao.mysql.DemoOrderMapper;
|
||||
import cn.iocoder.mall.demo.business.dataobject.order.DemoOrderDO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -5,7 +5,7 @@ import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.demo.business.api.DemoProductService;
|
||||
import cn.iocoder.mall.demo.business.bo.product.*;
|
||||
import cn.iocoder.mall.demo.business.convert.DemoProductConvert;
|
||||
import cn.iocoder.mall.demo.business.dao.DemoProductMapper;
|
||||
import cn.iocoder.mall.demo.business.dao.mysql.DemoProductMapper;
|
||||
import cn.iocoder.mall.demo.business.dataobject.product.DemoProductDO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.iocoder.mall.demo.business.service;
|
||||
|
||||
import cn.iocoder.mall.demo.business.api.DemoUserService;
|
||||
import cn.iocoder.mall.demo.business.bo.user.DemoUserBO;
|
||||
import cn.iocoder.mall.demo.business.cacheobject.user.DemoUserCacheObject;
|
||||
import cn.iocoder.mall.demo.business.convert.DemoUserConvert;
|
||||
import cn.iocoder.mall.demo.business.dao.redis.DemoUserCacheDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class DemoUserServiceImpl implements DemoUserService {
|
||||
|
||||
@Autowired
|
||||
private DemoUserCacheDao userCacheDao;
|
||||
|
||||
@Override
|
||||
public DemoUserBO get(Integer id) {
|
||||
DemoUserCacheObject userCacheObject = userCacheDao.get(id);
|
||||
if (userCacheObject == null) { // TODO 芋艿,临时
|
||||
userCacheDao.set(id, new DemoUserCacheObject().setId(id)
|
||||
.setName("芋艿").setGender(1));
|
||||
}
|
||||
return DemoUserConvert.INSTANCE.convert(userCacheObject);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,8 @@ spring:
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: testb5f4
|
||||
password: F4df4db0ed86@11
|
||||
# redis
|
||||
redis:
|
||||
|
||||
# mybatis-plus
|
||||
mybatis-plus:
|
||||
@@ -17,3 +19,4 @@ mybatis-plus:
|
||||
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
|
||||
mapperLocations: classpath*:mapper/*.xml
|
||||
typeAliasesPackage: cn.iocoder.mall.demo.business.dataobject
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.mall.demo.business.dao.DemoProductMapper">
|
||||
<mapper namespace="cn.iocoder.mall.demo.business.dao.mysql.DemoProductMapper">
|
||||
|
||||
<update id="updateQuantityReduce">
|
||||
UPDATE product
|
||||
|
||||
Reference in New Issue
Block a user