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

建立网站就是制作网页吗百度平台电话

建立网站就是制作网页吗,百度平台电话,如何做网站内链,wordpress需要编程技术嘛自定义映射resultMap 自定义映射resultMap 自定义映射resultMapresultMap处理字段和属性的映射关系字段名和属性名不一致的情况,如何处理映射关系?1、为查询的字段设置别名,和属性名保持一致2、核心配置文件(mybatis-config.xml)中设置一个全局配置3、使…

自定义映射resultMap

自定义映射resultMap

  • 自定义映射resultMap
  • resultMap处理字段和属性的映射关系
    • 字段名和属性名不一致的情况,如何处理映射关系?
      • 1、为查询的字段设置别名,和属性名保持一致
      • 2、核心配置文件(mybatis-config.xml)中设置一个全局配置
      • 3、使用resultMap自定义映射处理
        • (1)处理多对一的映射关系:
          • ①级联方式处理
          • ②association
          • ③分步查询
        • (2)处理一对多的映射关系:


resultMap处理字段和属性的映射关系

字段名和属性名不一致的情况,如何处理映射关系?

属性名
在这里插入图片描述
字段名
在这里插入图片描述

1、为查询的字段设置别名,和属性名保持一致

在这里插入图片描述

    <select id="getEmpByEmpId" resultType="Emp">select emp_id empId,emp_name empName,age,gender from t_emp where emp_id = #{empId}</select>

2、核心配置文件(mybatis-config.xml)中设置一个全局配置

当字段符合MySQL的要求使用_,而属性符合java的要求使用驼峰
,此时可以在MyBatis的核心配置文件(mybatis-config.xml)中设置一个全局配置,可以自动将下划线映射为驼峰
emp_id:empId,emp_name:empName

    <settings><!--将下划线映射为驼峰--><setting name="mapUnderscoreToCamelCase" value="true"/><!--开启延迟加载--><setting name="lazyLoadingEnabled" value="true"/><!--按需加载--><setting name="aggressiveLazyLoading" value="false"/></settings>

3、使用resultMap自定义映射处理

resultMap:设置自定义映射

  • 属性:
    id:表示自定义映射的唯一标识
    type:查询的数据要映射的实体类的类型
    • 子标签:
      id:设置主键的映射关系
      result:设置普通字段的映射关系
      association:设置多对一的映射关系
      collection:设置一对多的映射关系
      • 属性:
        property:设置映射关系中实体类中的属性名
        column:设置映射关系中表中的字段名
<resultMap id="userMap" type="User">
<id property="id" column="id"></id>
<result property="userName" column="user_name"></result>
<result property="password" column="password"></result>
<result property="age" column="age"></result>
<result property="sex" column="sex"></result>
</resultMap>
<!--List<User> testMohu(@Param("mohu") String mohu);-->
<select id="testMohu" resultMap="userMap">
<!--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>
(1)处理多对一的映射关系:

多个员工对应一个部门

①级联方式处理
    <!--  级联方式处理--><resultMap id="empAndDeptResultMapOne" type="Emp"><id column="emp_id" property="empId"></id><result column="emp_name" property="empName"></result><result column="age" property="age"></result><result column="gender" property="gender"></result><result column="dept_id" property="dept.deptId"></result><result column="dept_name" property="dept.deptName"></result></resultMap><select id="getEmpAndDeptByEmpId" resultMap="empAndDeptResultMapOne">selectt_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 id="empAndDeptResultMap" type="Emp"><id column="emp_id" property="empId"></id><result column="emp_name" property="empName"></result><result column="age" property="age"></result><result column="gender" property="gender"></result><!--association:处理多对一的映射关系(处理实体类类型的属性)property:设置需要处理映射关系的属性的属性名javaType:设置要处理的属性的类型--><association property="dept" javaType="Dept"><id column="dept_id" property="deptId"></id><result column="dept_name" property="deptName"></result></association></resultMap><select id="getEmpAndDeptByEmpId" resultMap="empAndDeptResultMap">selectt_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 id="getEmpAndDeptByStepTwo" resultType="Dept">select * from t_dept where dept_id = #{deptId}</select>

EmpMapper.xml(员工):

<!--分步查询--><resultMap id="empAndDeptByStepResultMap" type="Emp"><id column="emp_id" property="empId"></id><result column="emp_name" property="empName"></result><result column="age" property="age"></result><result column="gender" property="gender"></result><!--property:设置需要处理映射关系的属性的属性名select:设置分步查询的sql的唯一标识column:将查询出的某个字段作为分步查询的sql的条件fetchType:在开启了延迟加载的环境中,通过该属性设置当前的分步查询是否使用延迟加载fetchType="eager(立即加载)|lazy(延迟加载)"--><association property="dept" fetchType="eager"select="com.atguigu.mybatis.mapper.DeptMapper.getEmpAndDeptByStepTwo"column="dept_id"></association></resultMap><select id="getEmpAndDeptByStepOne" resultMap="empAndDeptByStepResultMap">select * from t_emp where emp_id = #{empId}</select>
(2)处理一对多的映射关系:

一个部门对应多个员工
①collection

    <resultMap id="deptAndEmpResultMap" type="Dept"><id column="dept_id" property="deptId"></id><result column="dept_name" property="deptName"></result><!--ofType:设置集合类型的属性中存储的数据的类型--><collection property="emps" ofType="Emp"><id column="emp_id" property="empId"></id><result column="emp_name" property="empName"></result><result column="age" property="age"></result><result column="gender" property="gender"></result></collection></resultMap><select id="getDeptAndEmpByDeptId" resultMap="deptAndEmpResultMap">SELECT *FROM t_deptLEFT JOIN t_empON t_dept.dept_id = t_emp.dept_idWHERE t_dept.dept_id = #{deptId}</select>

②分步查询
DeptMapper.xml(部门):

    <resultMap id="deptAndEmpResultMapByStep" type="Dept"><id column="dept_id" property="deptId"></id><result column="dept_name" property="deptName"></result><collection property="emps"select="com.atguigu.mybatis.mapper.EmpMapper.getDeptAndEmpByStepTwo"column="dept_id"></collection></resultMap><!--Dept getDeptAndEmpByStepOne(@Param("deptId") Integer deptId);--><select id="getDeptAndEmpByStepOne" resultMap="deptAndEmpResultMapByStep">select * from t_dept where dept_id = #{deptId}</select>

EmpMapper.xml(员工):

    <select id="getDeptAndEmpByStepTwo" resultType="Emp">select * from t_emp where dept_id = #{deptId}</select>
http://www.hrbkazy.com/news/40478.html

相关文章:

  • 绵阳网站建设策划内容手机怎么做网站
  • 白云区做网站公司市场推广方案范文
  • 平湖公司做网站游戏推广平台哪个好
  • 泉州最专业手机网站建设定制开发定制软件公司
  • 做h5网站用什么网站关键词优化软件
  • js特效网站模板企业网站排名优化方案
  • 海外推广工作内容网站关键词优化价格
  • 网站建设工作流程seo零基础入门到精通200讲
  • 广东网站建设方便美国站外推广网站
  • wordpress分享后下载地址宁波seo
  • phpwind8.7和wordpress百度关键词优化和百度推广
  • 深圳做网站电话百度店铺
  • 学做网站的学校济南百度快照推广公司
  • 如何查公司网站谁家做的刚出来的新产品怎么推
  • 学做网站学java有用么苏州搜索引擎优化
  • 物联网管理平台登录seo每日一帖
  • 深圳微信分销网站公司中国互联网协会官网
  • 烟台市福山区住房和建设局网站兰州网络推广
  • 帮其他企业做网站属于外包公司吗手机优化是什么意思
  • 网站怎么百度收录成都seo优化排名推广
  • 有专门做检验的视频网站吗如何开发自己的小程序
  • 长锦船公司网站百度搜索引擎优化的养成良好心态
  • 做网站用lunx网络营销推广实训报告
  • wordpress猜你喜欢功能北京seo推广优化
  • 企业网站怎么做才好seo资讯
  • 班级网站建设的参考文献怎么做网络宣传推广
  • 建零售网站还是想做seo哪里有培训的
  • 修车店怎么做网站搜索引擎优化的步骤
  • 网站前端用什么做西安核心关键词排名
  • 什么网站可以在线做雅思搜狗搜索引擎入口