将查询的数据写到redis缓存中 |
您所在的位置:网站首页 › 特斯拉电动车报价多少钱 › 将查询的数据写到redis缓存中 |
maven/springboot
pom文件写依赖
json依赖 com.alibaba fastjson 1.2.13 org.codehaus.jackson jackson-core-asl 1.9.13 org.codehaus.jackson jackson-mapper-asl 1.9.13 redis依赖 org.springframework.boot spring-boot-starter-data-redis controller层从数据库查出放入缓存中 @RequestMapping("showAll") public String showAll(HttpServletRequest request){ Jedis jedis = new Jedis("虚拟机端口号", 6379); //先从缓存中查询 String str = jedis.get("selectShopping"); System.out.println(str); //如果缓存中没有,则查询数据库 List selectAll = null; if(str==null){ selectAll = service.SelectAll(); for (Goods goods : selectAll) { System.out.println(goods); } String jsonString = JSON.toJSONString(selectAll); jedis.set("selectShopping", jsonString); } else { people = JSON.parseArray(str,Person.class); } request.setAttribute("all", selectAll); return "showAll"; }先将数据放入缓存中,然后从缓存中查出来,在页面以下拉菜单的形式展示出来 @Resource private Jedis jedis = new Jedis("192.168.134.20",6379); @RequestMapping("toadd") public String toadd(){ jedis.set("type","电脑"); jedis.set("type1","手机"); jedis.set("type2","水果"); return "add"; } @RequestMapping("types") @ResponseBody public List types(){ List list = new ArrayList(); String type = jedis.get("type"); String type1 =jedis.get("type1"); String type2 =jedis.get("type2"); list.add(new String(type)); list.add(new String(type1)); list.add(new String(type2)); return list; } 页面 $(function(){ $.post("/goods/types",function (data){ $.each(data,function (index,obj) { $("select").append(""+obj+"") }) }); }); 类别 请选择 给下拉菜单添加ajax事件 $("#s").change(function(){ var s = $(this).val(); window.location.href="${pageContext.request.contextPath }/stu/show?cid="+s+""; }); (#s为select标签ID)
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |