当前位置: 首页 > 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.sadfv.cn/news/125472/

相关文章:

  • 广告型网站微信营销的优缺点
  • 有没有帮人做数学题的网站珠海建设信息网站
  • 微商需要做网站吗企业网站备案审核需要多长时间
  • 生鲜网站建设规划书范文谷歌seo优化是什么
  • 网站建设排名政务佛山seo优化排名推广
  • 深圳龙岗区住房和建设局网站官网最好看的免费观看视频
  • 做平面设计什么素材网站好使做网站建设公司怎么样
  • 投票网站制作无忧传媒在短视频领域的成就
  • 网络公司给我做网站我有没有源代码版权吗?头像制作logo免费生成器在线
  • 上传网站到二级域名wap织梦手机网站
  • 免费网站建站手机论坛网站开发文档
  • 大学招生网站建设网站的标签修改
  • 做黄金的人喜欢逛那些网站应聘网站优化的简历怎么做
  • 淄博网站推广那家好做网站找
  • 免费1级做爰片免费网站东莞手机网站建设公司
  • 电影资源分享网站怎么做的semir是什么牌子衣服
  • 望谟网站建设电子商务网站建设的准备工作有哪些
  • 增城网站怎么做seo产地证哪个网站做
  • 销售网站建设的短文制作网页一般需要兼容哪些软件
  • 做网站前台开发学习微信营销和微博营销的区别
  • 网站添加地图导航伯爵手表网站
  • 自己网站的关键词怎么改wordpress 加密连接
  • 天津网站优化多少钱什么网站会更有浏览量
  • 做网站数据库怎么整东西湖网站建设公司
  • 做网站的前景上海新闻综合频道直播
  • 贸易网站怎么做现在宁波做网站
  • 网站制作时间表免费建站软件哪个最好
  • 网站上线多少钱工作汇报总结怎么写
  • 中国铁建华南建设有限公司网站核桃编程加盟费多少钱
  • 一般做网站的在哪里找wordpress分类页面的地址