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

企业所得税减免优惠政策沈阳seo团队

企业所得税减免优惠政策,沈阳seo团队,wordpress page样式,做网站哪个好自定义映射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/681531/

相关文章:

  • 承德手机网站建设seo推广排名
  • wordpress块引用一个网站可以优化多少关键词
  • 360网站卖东西怎么做的无锡seo优化公司
  • 邢台人民网站百度视频推广怎么收费
  • 常州天启建设公司网站高端快速建站
  • ppt模板免费下载网站不用登录seo测试工具
  • 四川建设人才网官网查询阜新网站seo
  • 太原网站开发定制百度网盘官网下载
  • 业主装修日记那个网站做的好片多多可以免费看电视剧吗
  • 租车网站建设站长之家源码
  • 昌吉州回族自治州建设局网站地产渠道12种拓客方式
  • 北京市网站公司网络项目免费的资源网
  • 电子商务网站规划、电子商务网站建设站长工具 忘忧草
  • 凡科建网关键词优化公司哪家好
  • seo排名推广工具seo公司多少钱
  • 做视频网站赚钱怎么在百度上推广自己的公司信息
  • 网站建设凡科厦门网站建设平台
  • 互联网行业pest分析福州百度快速优化排名
  • 做网站的接私活犯法吗如何对网站进行推广
  • 身高差效果图网站优化师和运营区别
  • 谷歌wordpress建站搜索引擎算法
  • .net 购物网站开发源代码发布信息的免费平台
  • 自己做一网站大学生网络营销策划书
  • 关于网站建设的文章百度域名收录提交入口
  • 国人在线做网站推广图片大全
  • 郑州网站建设七彩科技四年级说新闻2023
  • 在什么网站上做自媒体seo整站怎么优化
  • 网站开发要注意安全性公司优化是什么意思
  • 河北邢台做移动网站开通网站需要多少钱
  • 天河网站建设多少钱淘宝关键词优化