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

做企业网站设计与实现大型网络游戏排行榜前十

做企业网站设计与实现,大型网络游戏排行榜前十,网站建设人员培训纲要,wordpress 文章显示在Mybatis实现数据处理过程中#xff0c;字段名符合数据库的规则#xff0c;属性一般为驼峰规则#xff0c;因此字段名和属性名通常不一致#xff0c;此时可以通过以下两种方式对数据库字段进行映射处理#xff1a; 为字段起别名#xff0c;保证和实体类中的属性名一致在…在Mybatis实现数据处理过程中字段名符合数据库的规则属性一般为驼峰规则因此字段名和属性名通常不一致此时可以通过以下两种方式对数据库字段进行映射处理 为字段起别名保证和实体类中的属性名一致在满足驼峰转换规则时 在MyBatis的核心配置文件中设置一个全局配置信息mapUnderscoreToCamelCase可以在查询表中数据时自动将数据库字段名转换为驼峰通过resultMap进行字段映射处理 1 利用字段别名映射 ListEmp listEmp();!--通过字段别名解决字段名和属性名的映射问题--select idlistEmp resultTypeEmpselect id, user_name as userName, pass_word as passWord, sex, dept_id as deptId from t_emp/select2 利用驼峰转换规则映射 在Mybatis核心配置文件中设置全局的驼峰转换此时框架会根据驼峰规则自动将数据库字段和实体属性进行映射。 核心配置 settings!-- 将表中的下划线字段自动映射为驼峰命名的属性字段 --setting namemapUnderscoreToCamelCase valuetrue/ /settings数据查询 !--通过驼峰配置此时Mybatis框架会自动将字段和属性进行映射如user_name映射到userName属性上。-- select idlistEmp resultTypeEmpselect id, user_name, pass_word, sex, dept_id from t_emp /select此处resultType直接使用实体类别名因为存在如下的配置 typeAliases!--typeAlias设置某个具体的类型的别名属性type需要设置别名的类型的全类名alias设置此类型的别名若不设置此属性该类型拥有默认的别名即类名且不区分大小写; 若设置此属性此时该类型的别名只能使用alias所设置的值--!--typeAlias typecom.giser.mybatis.bean.User/typeAlias--!--typeAlias typecom.giser.mybatis.bean.User aliasabc/typeAlias--!--以包为单位设置改包下所有的类型都拥有默认的别名即类名且不区分大小写--package namecom.giser.pojo/ /typeAliases3 利用resultMap映射 !--resultMap设置自定义映射关系id: 自定义映射的唯一标识type: 映射的实体类类型子标签id: 设置主键的映射关系result设置普通字段的映射关系属性property: 设置映射关系中实体类的属性column: 设置映射关系中表字段--resultMap idempMap typeEmpid propertyid columnid /result propertyuserName columnuser_name /result propertypassWord columnpass_word /result propertysex columnsex /result propertydeptId columndept_id //resultMap!--使用ResultMap解决字段名和属性名的映射问题--select idlistEmp resultMapempMapselect * from t_emp/select3.1 多对一映射 3.1.1 级联映射 存在如下实体 public class Dept {private Integer id;private String deptName;private String deptNo;// getter setter }public class EmpDept {private Integer id;private String userName;private String passWord;private String sex;private Integer deptId;private Dept dept;// getter setter }ListEmpDept listEmpDeptById(Param(eid)Integer eid);select idlistEmpDeptById resultMapempDeptMapselect * from t_emp left join t_dept on t_emp.dept_id t_dept.id where t_emp.id #{eid} /select此时需要级联映射如下 !--通过级联属性赋值 -- resultMap idempDeptMap typeEmpDeptid propertyid columnid /result propertyuserName columnuser_name /result propertypassWord columnpass_word /result propertysex columnsex /result propertydeptId columndept_id /result propertydept.id columnid /result propertydept.deptName columndept_name /result propertydept.deptNo columndept_no / /resultMap3.1.2 使用association实现多对一映射 如员工和部门的关系就是多对一多个员工可能在同一个部门。此时可以通过上述的级联属性赋值方式进行映射还可以通过association处理映射关系。 !--通过association处理多对一映射关系 -- resultMap idempDeptMapTwo typeEmpDeptid propertyid columnid /result propertyuserName columnuser_name /result propertypassWord columnpass_word /result propertysex columnsex /result propertydeptId columndept_id /!--association处理多对一的映射关系property: 需要处理多对一映射关系的实体属性名javaType: 实体属性的类型--association propertydept javaTypeDeptid propertyid columnid /result propertydeptName columndept_name /result propertydeptNo columndept_no //association /resultMapselect idlistEmpDeptById resultMapempDeptMapTwoselect * from t_emp left join t_dept on t_emp.dept_id t_dept.id where t_emp.id #{eid} /select3.1.3 使用association分步查询实现多对一映射 ListEmpDept listEmpDeptByStep(Param(eid) Integer eid);!--多对一映射关系处理方式二通过分步查询 -- resultMap idempDeptMapStep typeEmpDeptid propertyid columnid /result propertyuserName columnuser_name /result propertypassWord columnpass_word /result propertysex columnsex /result propertydeptId columndept_id /!--select 设置分步查询的Sql的唯一标识namespace.SQLId或mapper接口的全类名.方法名column 设置分步查询的条件--association propertydept selectcom.giser.mapper.DeptMapper.selectEmpAndDeptByStepTwocolumndept_id/association /resultMapselect idlistEmpDeptByStep resultMapempDeptMapStepselect * from t_emp left join t_dept on t_emp.dept_id t_dept.id where t_emp.id #{eid} /select/*** 分步查询第二步* param deptId* return*/ Dept selectEmpAndDeptByStepTwo(Param(deptId)Integer deptId);select idselectEmpAndDeptByStepTwo resultTypeDeptselect * from t_dept where id #{deptId} /select延迟加载 分步查询的优点可以实现延迟加载但是必须在核心配置文件中设置全局配置信息 lazyLoadingEnabled延迟加载的全局开关。当开启时所有关联对象都会延迟加载 aggressiveLazyLoading当开启时任何方法的调用都会加载该对象的所有属性。 否则每个属性会按需加载 此时就可以实现按需加载获取的数据是什么就只会执行相应的sql。此时可通过association和collection中的fetchType属性设置当前的分步查询是否使用延迟加载fetchType“lazy(延迟加载)|eager(立即加载)”。 在mybatis-config.xml中开启懒加载配置 settings!-- 开启延迟加载 --setting namelazyLoadingEnabled valuetrue //settings在映射关联属性时设置fetchType“lazy” !--多对一映射关系处理方式二通过分步查询--resultMap idempDeptMapStep typeEmpDeptid propertyid columnid /result propertyuserName columnuser_name /result propertypassWord columnpass_word /result propertysex columnsex /result propertydeptId columndept_id /!--select 设置分布查询的Sql的唯一标识namespace.SQLId或mapper接口的全类名.方法名column 设置分布查询的条件fetchType: 延迟加载 只有当全局配置lazyLoadingEnabled设置为true时fetchTypelazy才会延迟加载否则都是立即加载fetchTypeeager|lazy eager:立即加载 lazy:延迟加载 且此处设置的优先级高于全局配置--association propertydeptselectcom.giser.mapper.DeptMapper.selectEmpAndDeptByStepTwocolumndept_idfetchTypelazy/association/resultMap3.2 一对多映射 3.2.1 使用collection实现一对多映射 存在如下实体: public class DeptEmp {private Integer id;private String deptName;private String deptNo;private ListEmp emps;// getter setter } public class Emp {private Integer id;private String userName;private String passWord;private String sex;private Integer deptId;// getter setter }/*** 一对多关系查询* param deptId* return*/ DeptEmp selectDeptAndEmpByDeptId(Param(deptId)Integer deptId);resultMap iddeptAndEmpResultMap typeDeptEmpid propertyid columnid /result propertydeptName columndept_name /result propertydeptNo columndept_no /!--collection : 处理一对多关系映射property: 集合属性字段名称ofType : 表示该集合中存储的数据类型--collection propertyemps ofTypeEmpid propertyid columnid /result propertyuserName columnuser_name /result propertypassWord columnpass_word /result propertysex columnsex //collection /resultMapselect idselectDeptAndEmpByDeptId resultMapdeptAndEmpResultMapselect * from t_dept left join t_emp on t_dept.id t_emp.dept_id where t_dept.id #{deptId} /select3.2.2 使用分步查询实现一对多映射 DeptEmp selectDeptAndEmpByStepOne(Param(deptId)Integer deptId);resultMap idselectDeptAndEmpByStepResultMap typeDeptEmpid propertyid columnid /result propertydeptName columndept_name /result propertydeptNo columndept_no /collection propertyemps selectcom.giser.mapper.EmpMapper.selectDeptAndEmpByStepTwocolumnid/collection /resultMapselect idselectDeptAndEmpByStepOne resultMapselectDeptAndEmpByStepResultMapselect * from t_dept where id #{deptId} /selectEmp selectDeptAndEmpByStepTwo(Param(deptId)Integer deptId);select idselectDeptAndEmpByStepTwo resultTypeEmpselect * from t_emp where dept_id #{deptId} /select
http://www.yutouwan.com/news/125472/

相关文章:

  • 如何建设网站并与数据库相连django网站开发实例源码
  • 深圳市做网站的企业购物网站建设价格一览表
  • wordpress网站go.php跳转二级备案域名购买
  • 网站开发维护计入什么费用成都个人学做网站
  • 网站建设app销售好做吗wordpress php慢
  • 怎么做快三彩票网站南宁本地网站设计
  • 建设音乐网站手游推广平台
  • 打开一张图片后点击跳转到网站怎么做的做视频网站用哪个软件好
  • 三里河网站建设公司软件开发平台哪家好
  • 苏州企业建站程序小程序开发怎么做
  • 惠州网站营销推广中文域名指向同一个网站
  • 网站推广网络营销方案海口企业网站开发
  • 网站被屏蔽怎么访问安阳市设计
  • 网站建设销售话术900句wordpress 客户端使用
  • 网站怎么做微信支付中国空间站天和核心舱
  • 天河区网站建设flash里面如何做网站链接
  • 成都企业网站模板建设手机端怎么刷排名
  • php网站模板怎么修改青岛网站建设培训
  • 做网站哪里最好云网站系统
  • 17.zwd一起做网站池尾站长春制作网站哪家好
  • 景区网站建设策划方案优化设计六年级下册数学答案
  • 广州高端网站制作公司市场代理招商信息
  • 济南好的网站建设公司排名静态html怎么部署到服务器
  • 流浪动物网站开发天迈装饰网站建设项目
  • 备案 网站名称 修改深圳关键词推广排名
  • 网站建设及安全管理文档广州越秀区风险等级
  • 在深圳市住房和建设局网站wordpress 微博链接地址
  • 吉林电商网站建设报价网站改版方案策划书
  • 手机怎么做微电影网站html商城网站源码
  • 网站建设策划怎么沟通交互动效库 网站