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

phpcms建站教程河北沙河市建设局网站

phpcms建站教程,河北沙河市建设局网站,wordpress 耗时,网络营销成功的案例分析自定义映射resultMap 自定义映射resultMap 自定义映射resultMapresultMap处理字段和属性的映射关系字段名和属性名不一致的情况#xff0c;如何处理映射关系?1、为查询的字段设置别名#xff0c;和属性名保持一致2、核心配置文件(mybatis-config.xml)中设置一个全局配置3、使…自定义映射resultMap 自定义映射resultMap 自定义映射resultMapresultMap处理字段和属性的映射关系字段名和属性名不一致的情况如何处理映射关系?1、为查询的字段设置别名和属性名保持一致2、核心配置文件(mybatis-config.xml)中设置一个全局配置3、使用resultMap自定义映射处理1处理多对一的映射关系①级联方式处理②association③分步查询 2处理一对多的映射关系 resultMap处理字段和属性的映射关系 字段名和属性名不一致的情况如何处理映射关系? 属性名 字段名 1、为查询的字段设置别名和属性名保持一致 select idgetEmpByEmpId resultTypeEmpselect emp_id empId,emp_name empName,age,gender from t_emp where emp_id #{empId}/select2、核心配置文件(mybatis-config.xml)中设置一个全局配置 当字段符合MySQL的要求使用_而属性符合java的要求使用驼峰 此时可以在MyBatis的核心配置文件(mybatis-config.xml)中设置一个全局配置可以自动将下划线映射为驼峰 emp_id:empId,emp_name:empName settings!--将下划线映射为驼峰--setting namemapUnderscoreToCamelCase valuetrue/!--开启延迟加载--setting namelazyLoadingEnabled valuetrue/!--按需加载--setting nameaggressiveLazyLoading valuefalse//settings3、使用resultMap自定义映射处理 resultMap设置自定义映射 属性 id表示自定义映射的唯一标识 type查询的数据要映射的实体类的类型 子标签 id设置主键的映射关系 result设置普通字段的映射关系 association设置多对一的映射关系 collection设置一对多的映射关系 属性 property设置映射关系中实体类中的属性名 column设置映射关系中表中的字段名 resultMap iduserMap typeUser id propertyid columnid/id result propertyuserName columnuser_name/result result propertypassword columnpassword/result result propertyage columnage/result result 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},%) /select1处理多对一的映射关系 多个员工对应一个部门 ①级联方式处理 !-- 级联方式处理--resultMap idempAndDeptResultMapOne typeEmpid columnemp_id propertyempId/idresult columnemp_name propertyempName/resultresult columnage propertyage/resultresult columngender propertygender/resultresult columndept_id propertydept.deptId/resultresult columndept_name propertydept.deptName/result/resultMapselect idgetEmpAndDeptByEmpId resultMapempAndDeptResultMapOneselectt_emp.*,t_dept.*from t_empleft join t_depton t_emp.dept_id t_dept.dept_idwhere t_emp.emp_id #{empId}/select ②association !--association--resultMap idempAndDeptResultMap typeEmpid columnemp_id propertyempId/idresult columnemp_name propertyempName/resultresult columnage propertyage/resultresult columngender propertygender/result!--association处理多对一的映射关系处理实体类类型的属性property设置需要处理映射关系的属性的属性名javaType设置要处理的属性的类型--association propertydept javaTypeDeptid columndept_id propertydeptId/idresult columndept_name propertydeptName/result/association/resultMapselect idgetEmpAndDeptByEmpId resultMapempAndDeptResultMapselectt_emp.*,t_dept.*from t_empleft join t_depton t_emp.dept_id t_dept.dept_idwhere t_emp.emp_id #{empId}/select ③分步查询 DeptMapper.xml部门 select idgetEmpAndDeptByStepTwo resultTypeDeptselect * from t_dept where dept_id #{deptId}/select EmpMapper.xml员工 !--分步查询--resultMap idempAndDeptByStepResultMap typeEmpid columnemp_id propertyempId/idresult columnemp_name propertyempName/resultresult columnage propertyage/resultresult columngender propertygender/result!--property设置需要处理映射关系的属性的属性名select设置分步查询的sql的唯一标识column将查询出的某个字段作为分步查询的sql的条件fetchType在开启了延迟加载的环境中通过该属性设置当前的分步查询是否使用延迟加载fetchTypeeager(立即加载)|lazy(延迟加载)--association propertydept fetchTypeeagerselectcom.atguigu.mybatis.mapper.DeptMapper.getEmpAndDeptByStepTwocolumndept_id/association/resultMapselect idgetEmpAndDeptByStepOne resultMapempAndDeptByStepResultMapselect * from t_emp where emp_id #{empId}/select 2处理一对多的映射关系 一个部门对应多个员工 ①collection resultMap iddeptAndEmpResultMap typeDeptid columndept_id propertydeptId/idresult columndept_name propertydeptName/result!--ofType设置集合类型的属性中存储的数据的类型--collection propertyemps ofTypeEmpid columnemp_id propertyempId/idresult columnemp_name propertyempName/resultresult columnage propertyage/resultresult columngender propertygender/result/collection/resultMapselect idgetDeptAndEmpByDeptId resultMapdeptAndEmpResultMapSELECT *FROM t_deptLEFT JOIN t_empON t_dept.dept_id t_emp.dept_idWHERE t_dept.dept_id #{deptId}/select ②分步查询 DeptMapper.xml部门 resultMap iddeptAndEmpResultMapByStep typeDeptid columndept_id propertydeptId/idresult columndept_name propertydeptName/resultcollection propertyempsselectcom.atguigu.mybatis.mapper.EmpMapper.getDeptAndEmpByStepTwocolumndept_id/collection/resultMap!--Dept getDeptAndEmpByStepOne(Param(deptId) Integer deptId);--select idgetDeptAndEmpByStepOne resultMapdeptAndEmpResultMapByStepselect * from t_dept where dept_id #{deptId}/selectEmpMapper.xml员工 select idgetDeptAndEmpByStepTwo resultTypeEmpselect * from t_emp where dept_id #{deptId}/select
http://www.tj-hxxt.cn/news/143534.html

相关文章:

  • 网站群建设 中标嵌入式软件开发是什么专业
  • 网站建设捌金手指花总二六查找公司信息的网站
  • 丹东 建设集团 招聘信息网站企业官方网站地址
  • 做博客网站赚钱中国物联网企业排名
  • 网站域名实名认证吗高性能网站建设进阶指南pdf
  • 做网站会员推广哪个好网页建站专业公司
  • 怎么做网络销售的网站讷河市铁道北建设高架桥
  • 安装wordpress主题放哪里网站优化吧
  • 汽车专业网站wordpress怎么写php
  • wordpress游戏站网站文字模板
  • 青岛seo建站北京注册公司麻烦吗
  • 南京哪家网站做的好asp网站 换模板
  • 档案信息网站建设的意义如何免费创建企业网站
  • 上传网站程序后又怎么做网站建设金
  • 贵阳经开区建设管理局网站南京网站设计建设
  • 做网站路径手机模板网站下载
  • 做网站后端的全部步骤asp代码如何修改asp网站网页域名名称
  • 网站开发工具评价视频网站用户增长怎么做
  • 企业网站改版的好处怎么做网站设
  • 大型企业的微网站谁做wordpress 右侧边栏
  • 网站维护简单吗公司地址变更
  • 台州市城市建设投资公司网站本溪网站建设
  • 空间网网站seo优化培训
  • 致力于邯郸网站建设制作服务_使众多客户将网站转化为网络市场营销.中国建设工程造价管理协会网站简称
  • 信阳企业网站建设建站快车来电
  • 手机上网网站建设建筑导航网站
  • 搜网站首页不见了seo安卓开发软件手机版
  • 服装网站模板山西网站设计
  • 海外社交网站开发在与客户谈网页广告时如何让客户相信网站流量
  • 北京pc端网站开发什邡建设局网站