当前位置: 首页 > 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://wiki.neutronadmin.com/news/125472/

相关文章:

  • php网站后台地址wordpress 截取
  • 网站空间怎么回事html5经管网站模板
  • 网站主服务器ip地址高端网站制作怎么样
  • 自建营销型网站模板网站开发网站建设
  • 添加网站图标个人如何做微信小程序
  • 小型网站制作深圳NET网站开发工程师网站招聘
  • 租房网站开发移动互联网开发实训报告
  • 互联网网站建设收费网站制作的公
  • 做网站公司找哪家公司建立网站团队
  • 青海微信网站建设aws 建网站
  • 网站界面设计的原则广告设计公司文案
  • 建网站英语怎么说o2o平台排名
  • 南通网站快速收录仙桃做网站的个人
  • 国内做焊接机器人平台网站推广游戏网站怎么做
  • 网站备案能查到什么手机优化好还是不优化好
  • 平台型网站建设方案给网站开发APP
  • 百度网站提交入口百度wordpress写文章出现排版乱
  • wordpress 制作手机站沪深300指数是什么意思
  • 室内装修效果图网站有哪些怎样查询自己购房网签成功
  • ppt 如何做网站交互式产品单页设计图片
  • 做风控的网站重庆建站多少钱一年
  • 宁波网站建设公司立找亿企邦创客oa管理系统
  • 品牌网站建设教程自适应网站可以做伪静态页面吗
  • 织梦cms手机网站源码广州专业的网站推广工具
  • 网站设计的优点和缺点wordpress发布十万篇文章
  • 网站的栏目和版块设计的原则江西东乡网站建设
  • 两学一做专题网站素材网站推广公司哪
  • android 网站模板中国价格网
  • 网站设计建设案例贸易公司取什么名字
  • 网站开发 法律海门网站建设制作