当前位置: 首页 > news >正文

网站规划与设计论文时钟插件+wordpress

网站规划与设计论文,时钟插件+wordpress,头皮痒 脱发严重怎么办,永州网站建设哪里有介绍 缓存#xff0c;就是将经常访问的数据#xff0c;放到内存中#xff0c;减少对数据库的访问#xff0c;提高查询速度。Mybatis中也有缓存的概念#xff0c;分为一级缓存和二级缓存。 一级缓存 一级缓存是Mybatis中SqlSession对象的缓存。当我们执行查询以后#x…介绍 缓存就是将经常访问的数据放到内存中减少对数据库的访问提高查询速度。Mybatis中也有缓存的概念分为一级缓存和二级缓存。 一级缓存 一级缓存是Mybatis中SqlSession对象的缓存。当我们执行查询以后结果会存入到SqlSession为我们提供的一块区域中该区域的结构是一个Map当我们再次查询同样的数据mybatis会先去Sqlsession中查询是否有有的话直接拿出来用没有再去查询数据库。 示例   Mysql中建好表对应的实体类也建好 import java.util.Date;public class Student {private int id;private int age;private String name;private Date birthday;private int score;//get和set方法省略...}Dao层的接口 import java.io.Serializable;public interface StudentMapper {Student getById(Serializable id);}Dao层的xml mapper namespacecom.gs.spring_boot_demo.mybatis.mapper.StudentMapperselect idgetById resultTypecom.gs.spring_boot_demo.mybatis.entity.Studentselect * from student where id #{id}/select/mapper测试类 import com.gs.spring_boot_demo.mybatis.entity.Student; import com.gs.spring_boot_demo.mybatis.mapper.StudentMapper; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;SpringBootTest public class MybatisTest {Autowiredprivate StudentMapper mapper;Autowiredprivate SqlSessionFactory factory;Testpublic void test() {// 不能用这种方式这种方式不会有一级缓存的//Student student mapper.getById(1);//Student student1 mapper.getById(1);//System.out.println(student student1);SqlSession sqlSession factory.openSession();StudentMapper mapper sqlSession.getMapper(StudentMapper.class);Student student mapper.getById(1);Student student1 mapper.getById(1);System.out.println(student student1);}}看到控制台的输出 查了2次id为1的数据但只有1条发送sql的日志并且2次查询的结果是同一个对象。说明一级缓存生效了。   清除一级缓存的方法也有很多调用SqlSession对象的commit()、close()、clearCache()、增加、修改、删除时就会删除一级缓存。 Testpublic void test() {SqlSession sqlSession factory.openSession();StudentMapper mapper sqlSession.getMapper(StudentMapper.class);Student student mapper.getById(1);//commit()也能清除//sqlSession.commit();sqlSession.clearCache();Student student1 mapper.getById(1);System.out.println(student student1);}再次查看控制台的日志 可以看到因为删除了一级缓存所以第二次的查询去发送sql查数据库了2个查询结果也自然不是同一个对象。 二级缓存 一级缓存的前提条件是同一SqlSession对象而二级缓存是跨SqlSession对象的即多个SqlSession对象共享这一份缓存。当一级缓存关闭或提交后一级缓存会转入到二级缓存并且缓存的是数据而不是对象。 示例   二级缓存默认未开启首先开启它 Dao层的xml中添加 cache/xml的select标签设置属性useCache mapper namespacecom.gs.spring_boot_demo.mybatis.mapper.StudentMappercache/select idgetById resultTypecom.gs.spring_boot_demo.mybatis.entity.Student useCachetrueselect * from student where id #{id}/select/mapper开启二级缓存后实体类Student要实现Serializable接口 import java.io.Serializable; import java.util.Date;public class Student implements Serializable {private int id;private int age;private String name;private Date birthday;private int score;//get和set方法省略...}测试类 Test public void test() {SqlSession sqlSession factory.openSession();StudentMapper mapper sqlSession.getMapper(StudentMapper.class);Student student mapper.getById(1);//把一级缓存转入到二级缓存同时清空一级缓存sqlSession.commit();//相同的SqlSession对象Student student1 mapper.getById(1);System.out.println(student student1);//不同的SqlSession对象SqlSession sqlSession1 factory.openSession();StudentMapper mapper1 sqlSession1.getMapper(StudentMapper.class);Student student2 mapper1.getById(1);System.out.println(student student2); }看到控制台的日志 getById(Serializable id)调用了3次但是只有1条sql日志后面的2次调用都是查的二级缓存但对象不是同一个所以说缓存的是数据而不是对象。
http://www.w-s-a.com/news/107235/

相关文章:

  • 网站被模仿十堰网站制作公司
  • 怎么样做免费网站个人网站备案幕布
  • 做ppt的动图下载哪些网站制作一个网站需要多少时间
  • 公司网站开发制作备案中的网站
  • 怎么看网站的收录网站开发先前台和后台
  • 合肥市做网站多少钱wordpress网站布置视频
  • 中国建设人才网信息网站软件外包公司好不好
  • 网站建设与管理 市场分析上海网站建设公司排名
  • 怎么将公司网站设成首页网址关键词查询网站
  • 怎么用ps做网站ui邱县专业做网站
  • 国开行网站毕业申请怎么做大连旅顺口旅游攻略
  • 鲜花店网站源码成都专做婚介网站的公司
  • 合肥企业网站建设工哈尔滨公告
  • 华强北 做网站互联网服务平台入口
  • vi设计案例网站微信导航网站 dedecms
  • 青浦区做网站设计图片手绘图片
  • 做网站的基本功制作网站公司推荐
  • 阿里云快速建站教程个人网站 费用
  • 广东购物网站建设微信公众号制作模板免费
  • 阿里国际站韩语网站怎么做让移动网站
  • 北京外包做网站如何报价中国几大网络推广公司
  • 中国建设部网站关于资质wordpress 建app
  • 程序员找工作的网站哈尔滨建设信息网站
  • 公司 网站 方案高考写作网站
  • 网站后台如何登陆网站开发需求逻辑图
  • 市级档案网站建设情况分析server2008做DNS与网站
  • 公积金门户网站建设方案网站建设代理平台怎么做
  • 网站建设知识论文抖音开放平台是干什么的
  • 网站建设期末试卷大气简洁网站
  • 电子商务网站建设报告范文单位做网站怎么做