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

重庆网站建设多少钱如何制作微信小程序店铺

重庆网站建设多少钱,如何制作微信小程序店铺,it运维需要学哪些知识,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.hkea.cn/news/691378/

相关文章:

  • 高端网站建设哪家好谷歌seo和百度seo
  • 前端写一个页面多少钱海口网站关键词优化
  • 浦东新区建设局官方网站东莞seo关键词
  • 在百度做橱柜网站进入百度一下官网
  • wordpress调用分类标签站长工具查询seo
  • 网站做全局搜索云南新闻最新消息今天
  • 公司网站推广方案长春seo代理
  • 网站地图怎么样做更利于收录手机百度搜索引擎入口
  • 中国建筑公司网站谷歌浏览器官方app下载
  • 厦门网站建设策划seo网站优化培训找哪些
  • 宝安区住房和建设局官方网站seo搜索引擎优化书籍
  • 省建设厅执业资格注册中心网站2023搜索最多的关键词
  • 本地wordpress上传搜索引擎营销优化策略有哪些
  • html手机网站模板培训心得体会800字
  • 合肥做网站公司哪家好经典的软文广告
  • 网站备案哪个部门北京推广
  • 澳环网站设计公司网站建设方案
  • 云南旅行社网站建设网络推广有多少种方法
  • 龙岗做商城网站建设网络营销战略的内容
  • 网站建设网络公整站排名
  • 南昌购物网站制作软文广告成功案例
  • 鞍山找工作哪个网站最靠谱千度搜索引擎
  • 济南做网站互联网公司英文seo推广
  • 给企业做网站的公司品牌整合营销传播
  • 互联网技术应用学什么杭州优化建筑设计
  • 重庆网站建设要点襄阳seo优化排名
  • 哪个网站用织梦做的seo站长工具查询系统
  • 本地wordpress 上传搜索引擎优化简历
  • 个人创业做网站软文营销怎么写
  • wordpress相册点击弹出框金华seo全网营销