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

注册网站的信息网站个人网站设计要求

注册网站的信息网站,个人网站设计要求,网站服务器人多怎么挤进去,网站开发什么语言文章目录 环境搭建#xff0c;数据配置多对一的映射的思路逻辑级联属性映射association分布查询 一对多的映射的思路逻辑collection分布 环境搭建#xff0c;数据配置 t_class表 t_stu表 多对一的映射的思路逻辑 多对一#xff1a;多个学生对应一个班级 多的一方是st… 文章目录 环境搭建数据配置多对一的映射的思路逻辑级联属性映射association分布查询 一对多的映射的思路逻辑collection分布 环境搭建数据配置 t_class表 t_stu表 多对一的映射的思路逻辑 多对一多个学生对应一个班级 多的一方是student 一的一方是class 怎么分主表和副表 谁在前谁是主表 多对一和一对多其实都是一样的“叫法”就是主宾之间的顺序这里的区分是对于设计需求逻辑的区分 多对一多在前那么多就是主表 一对多一在前那么一就是主表 现在选取多对一那么多的一方是学生那么学生就是主表班级就是副表 所以映射到JVM虚拟机中的主对象就是学生对象 为什么映射过去的是学生对象因为学生是主表映射过去的是主表对象 讨论内存结构 在Student对象中通过sid可以查询到学生的属性再通过学生对象的cid可以查询到他的班级那么就应该在Student类中加上private Class class通过在Student类中加上对Class的引用从而完成对Class的关联 mybatis实现映射 多种方式常见的包括三种 第一种方式一条SQL语句级联属性映射第二种方式一条SQL语句association第三种方式两条SQL语句分布查询。这种方式常用优点一是可复用优点二十支持懒加载。 级联属性映射 //StudnetMapper.java Student selectById(Integer id);!-- StudentMapper.xml --resultMap idstudentResultMap typeStudentid propertysid columnsid/result propertysname columnsname/result propertyclazz.cid columncid/result propertyclazz.cname columncname//resultMapselect idselectById resultMapstudentResultMapselects.sid,s.sname,c.cid,c.cnamefromt_stu s left join t_class c on s.cid c.cidwheresid #{sid}/select//test文件Testpublic void testSelectById(){SqlSession sqlSession SqlSessionUtil.openSession();StudentMapper mapper sqlSession.getMapper(StudentMapper.class);Student student1 mapper.selectById(2);System.out.println(student1);sqlSession.close();}association association译为关联一个Student对象关联一个Class对象 Student selectByIdByAssociation(Integer id);resultMap idstudentResultMapByAssociation typeStudentid propertysid columnsid/result propertysname columnsname/association propertyclazz javaTypeClazzid propertycid columncid/result propertycname columncname//association/resultMapselect idselectByIdByAssociation resultMapstudentResultMapByAssociationselects.sid,s.sname,c.cid,c.cnamefromt_stu s left join t_class c on s.cid c.cidwheresid #{sid}/selectTestpublic void testSelectByIdByAssociation(){SqlSession sqlSession SqlSessionUtil.openSession();StudentMapper mapper sqlSession.getMapper(StudentMapper.class);Student student mapper.selectByIdByAssociation(6);System.out.println(student);sqlSession.close();}SQL语句都是一样的不同的就是对于class这个“外面来的类”不同的处理方式如何去访问到其中的数据 分布查询 显而易见的方式不用动脑子都能想到的方法先去查student再利用student获取的cid去查询cname 其中最大的问题就是关于sql语句如何将cid的值赋上 并且如何再从其中拿出来再进行查询 //StudentMapper.java Student selectByIdStep1(Integer id);//ClassMapper.java Clazz selectByIdStep2(Integer cid);!--StudentMapper.xml --resultMap idstudentResultMapByStep typeStudentid propertysid columnsid/result propertysname columnsname/association propertyclazzselectorg.powernode.mapper.ClassMapper.selectByIdStep2columncid//resultMapselect idselectByIdOnlyStudent resultMapstudentResultMapByStepselectsid,sname,cidfromt_stuwheresid #{sid}/select!--ClassMapper.xml --select idselectByIdStep2 resultTypeClazzselectcid,cnamefromt_classwherecid #{cid}/select//testTestpublic void TestAll2(){SqlSession sqlSession SqlSessionUtil.openSession();StudentMapper mapper sqlSession.getMapper(StudentMapper.class);Student student mapper.selectByIdOnlyStudent(6);System.out.println(student);sqlSession.close();}about 优点 第一点复用性增强可以重复利用。大步拆成N多个小碎步每一个小碎步更加可以重复利用第二点采用这种分布查询可以充分利用他们的延迟加载/懒加载机制。 什么是延迟加载懒加载有什么用 延迟加载的核心原理就是用的时候再执行查询语句不用的时候不查询 作用提供性能。 在mybatis中如何开启延迟加载 association标签中添加fetchType“lazy” 注意默认情况下是没有开启延迟加载的需要设置fetchType“lazy” 这种在Association标签中配置fetchType“lazy”的是局部设置只对当前的Association关联的sql语句起作用 在实际开发中大部分都是需要使用延迟加载的所以建议开启全部的延迟加载机制 可以在mybatis-config中配置setting settings !-- 延迟加载的全局开关默认值false不开启 --!-- 什么意思所有只要但凡带有分布的都采用延迟加载 --setting namelazyLoadingEnabled valuetrue/ /settings如果在开启全局之后有部分地方在这里插入代码片不想要开启懒加载可以在association的fetchType中设置为eager 一对多的映射的思路逻辑 一对多一在前那么一就是主表t_class就是主表那就是在class类中加入对student的引用ListStudent stus 一对多的实现通常包括两种实现方式 第一种方式collection第二种方式分布查询老伙计 collection //classMapper.javaClazz selectById(Integer id); //classMapper.xmlresultMap idclazzResultMap typeClazzid propertycid columncid/result propertycname columncname/collection propertystus ofTypeStudentid propertysid columnsid/result propertysname columnsname//collection/resultMapselect idselectById resultMapclazzResultMapselectc.cid,c.cname,s.sid,s.snamefromt_class c left join t_stu s on c.cid s.cidwherec.cid #{cid}/select//testTestpublic void testSelectById(){SqlSession sqlSession SqlSessionUtil.openSession();ClassMapper mapper sqlSession.getMapper(ClassMapper.class);Clazz clazz mapper.selectById(1001);System.out.println(clazz);sqlSession.close();}分布 //ClassMapper.java Clazz selectByStep(Integer cid);//StudentMapper.java ListStudent selectByIdByStep(Integer cid);!-- ClassMapper.xml --resultMap idclazzResultMapStep typeClazzid propertycid columncid/result propertycname columncname/collection propertystusselectorg.powernode.mapper.StudentMapper.selectByIdByStepcolumncid//resultMapselect idselectByStep resultMapclazzResultMapStepselectcid,cnamefromt_classwherecid #{cid}/select!-- StudentMapper.xml --select idselectByIdByStep resultTypeStudentselect*fromt_stuwherecid #{cid}/select//testTestpublic void testByStep(){SqlSession sqlSession SqlSessionUtil.openSession();ClassMapper mapper sqlSession.getMapper(ClassMapper.class);Clazz clazz mapper.selectByStep(1001);System.out.println(clazz);sqlSession.close();}
http://www.w-s-a.com/news/876778/

相关文章:

  • 房天下网站建设女生说wap是什么意思
  • 网站开发安全机制北京做网站多少钱合理
  • 扁平化 公司网站建设大型视频网站需要的资金量
  • 免费建各种网站淄博网站建设yx718
  • 凡科网建站入门教程运城市网站建设
  • 黄浦区未成年人思想道德建设网站oa系统是什么
  • 微信里的网站怎么做电子商务网站开发平台
  • 易企秀网站怎么做轮播图网站建设张世勇
  • 网站备案幕布尺寸建立网页的几个步骤
  • pc网站页面找出网站所有死链接
  • 专业做seo的网站网站内连接
  • 阿里云网站开发服务器想开网站建设公司
  • 网站开发不足之处茶叶seo网站推广与优化方案
  • 响应式网站建设系统网站优化怎么做 有什么技巧
  • 班级网站做哪些方面wordpress标签 扩展
  • 如何在电商上购物网站Wordpress 域名授权插件
  • 网站建设后台怎么弄昆明如何做好关键词推广
  • 自己怎么做个网站优酷视频网站开发
  • 2015做网站前景电子商务营销的发展现状
  • 官方网站建设情况说明电子商务网站开发的形式有
  • 网站建设玖金手指排名11专业建站公司建站系统
  • 全球排名前十网站百度网站官网网址
  • 商家在携程旅游网站怎样做宣传做网站公司苏州
  • 芜湖做网站都有哪些广州音乐制作公司
  • 青岛好的网站制作推广注册公司流程步骤
  • 怎么制作营销网站模板wordpress苗木模板
  • 手机网站样例wordpress 排序
  • 济南网站建设手机网站开发人员需要去做原型吗
  • 动易网站模板下载微信支付 wordpress
  • 学校建设外文网站情况阿里云 建设网站怎么样