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

传媒网站建设游戏网页设计作品欣赏

传媒网站建设,游戏网页设计作品欣赏,网站开发要服务器吗,私人订制软件平台8.1、resultMap处理字段和属性的映射关系 若字段名和实体类中的属性名不一致#xff0c;则可以通过resultMap设置自定义映射 !--resultMap#xff1a;设置自定义映射属性#xff1a;id#xff1a;表示自定义映射的唯一标识type#xff1a;查询的数据要映射的实体类的…8.1、resultMap处理字段和属性的映射关系 若字段名和实体类中的属性名不一致则可以通过resultMap设置自定义映射 !--resultMap设置自定义映射属性id表示自定义映射的唯一标识type查询的数据要映射的实体类的类型子标签id设置主键的映射关系result设置普通字段的映射关系association设置多对一的映射关系collection设置一对多的映射关系属性property设置映射关系中实体类中的属性名column设置映射关系中表中的字段名 -- resultMap iduserMap typeUserid propertyid columnid/idresult propertyuserName columnuser_name/resultresult propertypassword columnpassword/resultresult propertyage columnage/resultresult propertysex columnsex/result /resultMap !--ListUser testMohu(Param(mohu) String mohu);-- select idtestMohu resultMapuserMap!--select * from t_user where username like %${mohu}%--select id,user_name,password,age,sex from t_user where user_name like concat(%,#{mohu},%) /select若字段名和实体类中的属性名不一致但是字段名符合数据库的规则使用_实体类中的属性名符合Java的规则使用驼峰 此时也可通过以下两种方式处理字段名和实体类中的属性的映射关系 可以通过为字段起别名的方式保证和实体类中的属性名保持一致可以在MyBatis的核心配置文件中设置一个全局配置信息mapUnderscoreToCamelCase可以在查询表中数据时自动将_类型的字段名转换为驼峰 settingssetting namemapUnderscoreToCamelCase valuetrue/ /settings例如字段名user_name设置了mapUnderscoreToCamelCase此时字段名就会转换为userName ListUser getAllUser();select idgetAllUser resultTypeUserselect * from t_user /select查询结果 [User(id4, userNameadmin, password123456, age18, gender男, email), User(id5, userNameadmin, password123456, age18, gender男, email)]8.2、多对一映射处理 场景模拟 查询员工信息以及员工所对应的部门信息 8.2.1、级联方式处理映射关系 resultMap idempDeptMap typeEmp id columneid propertyeid/idresult columnename propertyename/resultresult columnage propertyage/resultresult columnsex propertysex/resultresult columndid propertydept.did/resultresult columndname propertydept.dname/result /resultMap !--Emp getEmpAndDeptByEid(Param(eid) int eid);-- select idgetEmpAndDeptByEid resultMapempDeptMapselect emp.*,dept.* from t_emp emp left join t_dept dept on emp.did dept.did where emp.eid #{eid} /select8.2.2、使用association处理映射关系 resultMap idempDeptMap typeEmp id columneid propertyeid/idresult columnename propertyename/resultresult columnage propertyage/resultresult columnsex propertysex/resultassociation propertydept javaTypeDeptid columndid propertydid/idresult columndname propertydname/result/association /resultMap !--Emp getEmpAndDeptByEid(Param(eid) int eid);-- select idgetEmpAndDeptByEid resultMapempDeptMapselect emp.*,dept.* from t_emp emp left join t_dept dept on emp.did dept.did where emp.eid #{eid} /select8.2.3、分步查询 1、查询员工信息 /** * 通过分步查询查询员工信息 * param eid * return */ Emp getEmpByStep(Param(eid) int eid);resultMap idempDeptStepMap typeEmpid columneid propertyeid/idresult columnename propertyename/resultresult columnage propertyage/resultresult columnsex propertysex/result!--select设置分步查询查询某个属性的值的sql的标识namespace.sqlIdcolumn将sql以及查询结果中的某个字段设置为分步查询的条件--association propertydept selectcom.atguigu.MyBatis.mapper.DeptMapper.getEmpDeptByStep columndid/association /resultMap!--Emp getEmpByStep(Param(eid) int eid);-- select idgetEmpByStep resultMapempDeptStepMapselect * from t_emp where eid #{eid} /select2、根据员工所对应的部门id查询部门信息 /** * 分步查询的第二步 根据员工所对应的did查询部门信息 * param did * return */ Dept getEmpDeptByStep(Param(did) int did);!--Dept getEmpDeptByStep(Param(did) int did);-- select idgetEmpDeptByStep resultTypeDeptselect * from t_dept where did #{did} /select8.3、一对多映射处理 8.3.1、collection /** * 根据部门id查新部门以及部门中的员工信息 * param did * return */ Dept getDeptEmpByDid(Param(did) int did);resultMap iddeptEmpMap typeDeptid propertydid columndid/idresult propertydname columndname/result!--ofType设置collection标签所处理的集合属性中存储数据的类型--collection propertyemps ofTypeEmpid propertyeid columneid/idresult propertyename columnename/resultresult propertyage columnage/resultresult propertysex columnsex/result/collection /resultMap!--Dept getDeptEmpByDid(Param(did) int did);-- select idgetDeptEmpByDid resultMapdeptEmpMapselect dept.*,emp.* from t_dept dept left join t_emp emp on dept.did emp.did where dept.did #{did} /select8.3.2、分步查询 1、查询部门信息 /** * 分步查询部门和部门中的员工 * param did * return */ Dept getDeptByStep(Param(did) int did);resultMap iddeptEmpStep typeDeptid propertydid columndid/idresult propertydname columndname/resultcollection propertyemps fetchTypeeager selectcom.atguigu.MyBatis.mapper.EmpMapper.getEmpListByDid columndid/collection /resultMap!--Dept getDeptByStep(Param(did) int did);-- select idgetDeptByStep resultMapdeptEmpStepselect * from t_dept where did #{did} /select备注javaType和ofType都是用来指定对象类型的但是javaType是用来指定pojo中属性的类型而ofType指定的是映射到list集合属性中pojo的类型。 2、根据部门id查询部门中的所有员工 /** * 根据部门id查询员工信息 * param did * return */ ListEmp getEmpListByDid(Param(did) int did);!--ListEmp getEmpListByDid(Param(did) int did);-- select idgetEmpListByDid resultTypeEmpselect * from t_emp where did #{did} /select分步查询的优点可以实现延迟加载 但是必须在核心配置文件中设置全局配置信息 lazyLoadingEnabled延迟加载的全局开关。当开启时所有关联对象都会延迟加载 aggressiveLazyLoading当开启时任何方法的调用都会加载该对象的所有属性。否则每个属性会按需加载 也可以通过association和collection中的fetchType属性设置当前的分步查询是否使用延迟加载 fetchType“lazy(延迟加载)|eager(立即加载)” 更多关于延迟加载的资料可以参考https://www.cnblogs.com/zbh355376/p/14986307.html 本文章参考B站 【尚硅谷】SSM框架全套教程MyBatisSpringSpringMVCSSM整合一套通关仅供个人学习使用部分内容为本人自己见解与尚硅谷无关。
http://www.hkea.cn/news/14373534/

相关文章:

  • 可信赖的做网站适合个人外贸平台
  • 好的 做网站的软件公司电商网站开发难点
  • 福州市工程建设质量管理协会网站桐庐县住房和城乡建设局网站
  • 门户网站建设和检务公开整改荆门刚刚发布的
  • 爬虫网站开发公司在东莞建设网登记要多少钱
  • 成都建设网站那家好适合网站开发工程师的公司
  • 手机影视网站制作免备案建网站
  • 上海网站seo公司企业网站模块
  • 做 爱 网站视频短片三合一网站开发架构
  • 怎么给做的网站做百度搜索wordpress建站 百度网盘
  • 杭州网站建设索q479185700如何建设商城网站
  • 建设一个网站的硬件要求客户管理软件免费
  • 重庆网站建设培训机构学费网建类公司
  • 金华网站制作费用动态手机网站怎么做
  • 怎么在搜狐快站上做网站网站建设的规划方案
  • 网站开发及服务器总共多少钱湛江网站建设团队
  • 设计网页心得体会廊坊seo网络推广
  • 软件开发和网站建设那个好企业网站的建立
  • 佛山狮山网站建设黑龙江省
  • 哪个公司做农村产权交易网站ps制作网页
  • 制作一个网站平台需要多少钱五百丁简历官网
  • 广州建设网站制作东莞感染人数最新消息
  • 北京市基础建设质量监督局网站海淀网站建设龙岩
  • 湖南省住房城乡建设网站网站建设方案书 腾讯
  • html5 中文网站模板做有趣的网站
  • 怎样自己搭建一个做影视的网站行业软件定制开发
  • 视频网站开发研究背景公司官网首页设计
  • 深圳找网站建设深圳抖音seo
  • 徐州手机网站建设公司哪家好南宁世尊商贸网站建设
  • 宜昌商城网站建设wordpress wp酷