# zsRedis商城 **Repository Path**: YunweiZheng/zsredis ## Basic Information - **Project Name**: zsRedis商城 - **Description**: springmvc ,spring,mybatis dubbo redis做商城的数据库 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2017-07-20 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 已完成的功能 后台权限管理 用户 角色 菜单 商城 前台页面 后台管理 此项目主要是学习redis使用,生产不建议这样用 ,应该结合数据库一起使用 此项目的后台权限管理采用ssm 通用mapper 做成,商城管理去掉了mybatis 全部采用redis做存储和增删该查 如 商品数据结构 1. - /** 1. - * 用户基本信息 1. - * zscat:goods:{id}:{pcid}:{ptid} 1. - * hash 1. - * { 1. - * id: '100144', //ID 1. - * title: '1', //标题 1. - * tag: '0', //标签 1. - * img: '1', //图片 1. - * remark: '1,2', //内容 1. - * summry: '0', //摘书 1. - * } 1. - */ 1. - public static final String GOODS = "zscat:goods:%s:%s:%s"; ![输入图片说明](https://git.oschina.net/uploads/images/2017/0419/142316_c92a57a7_134431.png "在这里输入图片标题") 文章数据的redis 增删改查 public class ArticleRedis { static RedisUtils RedisUtils = new RedisUtils(1); /** * 文章列表 * * @param count * @return * @throws Exception */ public static List
toArticle(int count) throws Exception { Set set = RedisUtils.keys(String.format( RandomChatRedisKey.Article, "*")); Iterator it = set.iterator(); List
l = new ArrayList<>(); int j = 0; while (it.hasNext() && j < count) { j++; String key = it.next(); Map map = RedisUtils.hgetall(key); l.add((Article) BeanUtil.transMap2Bean(map, Article.class)); } return l; } /** * 保存或者修改文章 * * @param count * @return * @throws Exception */ public static void saveArticleRedisDB(Article profile) { String key = String.format(RandomChatRedisKey.Article, profile.getId()); Map map = BeanUtil.transBean2Map(profile, true); Map tempMap = new HashMap<>(); for (Map.Entry entry : map.entrySet()) { tempMap.put(entry.getKey(), entry.getValue().toString()); } RedisUtils.hmset(key, tempMap); } /** * 删除文章 * * @param count * @return * @throws Exception */ public static Long deleteArticleRedisDB(Article profile) { String key = String.format(RandomChatRedisKey.Article, profile.getId()); return RedisUtils.del(key); } /** * 获取文章文章 * * @param count * @return * @throws Exception */ public static Article getArticleRedisDB(Long id) { String key = String.format(RandomChatRedisKey.Article, id, "*"); Map map = RedisUtils.hgetall(key); return BeanUtil.transMap2Bean(map, Article.class); } } 创建数据库,启动redis 然后用tomcat启动项目 访问http://localhost:8081/zsRedis ![输入图片说明](https://git.oschina.net/uploads/images/2017/0419/142759_b91b3b0c_134431.png "在这里输入图片标题")