mybatis多表关联查询

1.结果集用实体类来接收,一个实体类中有另一个实体类字段,否则可直接用

resultType="java.util.Map"

2.多个表需要有关联

<resultMap id="BaseResultMap" type="com.datanew.model.User">
  <id column="ID" jdbcType="INTEGER" property="id" />
  <result column="name" jdbcType="VARCHAR" property="name" />
  <result column="CODE" jdbcType="VARCHAR" property="code" />
  <result column="PASSWORD" jdbcType="VARCHAR" property="password" />
  <result column="ADDRESS" jdbcType="VARCHAR" property="address" />
  <result column="PHONENO" jdbcType="VARCHAR" property="phoneno" />
  <result column="MOBIPHONE" jdbcType="VARCHAR" property="mobiphone" />
  <result column="REGICODE" jdbcType="VARCHAR" property="regicode" />
  <result column="FAVREGION" jdbcType="VARCHAR" property="favregion" />
  <result column="AUTHROLE" jdbcType="VARCHAR" property="authrole" />
  <result column="LINKAGENCY" jdbcType="VARCHAR" property="linkagency" />
  <result column="LINKBANK" jdbcType="VARCHAR" property="linkbank" />
  <result column="CATEGORY" jdbcType="CHAR" property="category" />
  <result column="ENTENAME" jdbcType="VARCHAR" property="entename" />
  <result column="bank_branch_ID" jdbcType="INTEGER" property="bankBranchId" />
  <result column="orgcoding" jdbcType="VARCHAR" property="orgcoding" />
  <result column="extendorgcoding" jdbcType="VARCHAR" property="extendorgcoding" />
  <result column="username" jdbcType="VARCHAR" property="username" />
  <result column="loginname" jdbcType="VARCHAR" property="loginname" />
  <result column="encryptiontype" jdbcType="VARCHAR" property="encryptiontype" />
  <result column="loginpwd" jdbcType="VARCHAR" property="loginpwd" />
  <result column="email" jdbcType="VARCHAR" property="email" />
  <result column="mobile" jdbcType="VARCHAR" property="mobile" />
  <result column="mobile2" jdbcType="VARCHAR" property="mobile2" />
  <result column="telephone" jdbcType="VARCHAR" property="telephone" />
  <result column="telephone2" jdbcType="VARCHAR" property="telephone2" />
  <result column="virtualnum" jdbcType="VARCHAR" property="virtualnum" />
  <result column="userposition" jdbcType="VARCHAR" property="userposition" />
  <result column="usertitle" jdbcType="VARCHAR" property="usertitle" />
  <result column="postcode" jdbcType="VARCHAR" property="postcode" />
  <result column="cakey" jdbcType="VARCHAR" property="cakey" />
  <result column="sex" jdbcType="CHAR" property="sex" />
  <result column="birthday" jdbcType="VARCHAR" property="birthday" />
  <result column="country" jdbcType="VARCHAR" property="country" />
  <result column="province" jdbcType="VARCHAR" property="province" />
  <result column="city" jdbcType="VARCHAR" property="city" />
  <result column="officeaddress" jdbcType="VARCHAR" property="officeaddress" />
  <result column="officephone" jdbcType="VARCHAR" property="officephone" />
  <result column="officefax" jdbcType="VARCHAR" property="officefax" />
  <result column="homephone" jdbcType="VARCHAR" property="homephone" />
  <result column="homeaddress" jdbcType="VARCHAR" property="homeaddress" />
  <result column="official" jdbcType="CHAR" property="official" />
  <result column="officialtype" jdbcType="VARCHAR" property="officialtype" />
  <result column="idtype" jdbcType="CHAR" property="idtype" />
  <result column="idnum" jdbcType="VARCHAR" property="idnum" />
  <result column="sso_user_id" jdbcType="VARCHAR" property="ssoUserId" />
  <result column="bill_Sys_Status" jdbcType="VARCHAR" property="billSysStatus" />
  <result column="orgname" jdbcType="VARCHAR" property="orgname" />
  <result column="devcode" jdbcType="VARCHAR" property="devcode" />
  <result column="regionScope" jdbcType="VARCHAR" property="regionscope" />
  <result column="operationScope" jdbcType="VARCHAR" property="operationscope" />
  <result column="customJson" jdbcType="VARCHAR" property="customjson" />
  <result column="bill_enter" jdbcType="VARCHAR" property="billEnter" />
  <result column="bill_user_type" jdbcType="VARCHAR" property="billUserType" />
  <result column="bill_org_id" jdbcType="INTEGER" property="billOrgId" />
  <result column="reset" jdbcType="CHAR" property="reset" />
  <result column="enteType" jdbcType="CHAR" property="entetype" />
  <result column="usestatus" jdbcType="CHAR" property="usestatus" />
  <result column="userId" jdbcType="VARCHAR" property="userId" />
  <result column="defaultSeal" jdbcType="BIGINT" property="defaultSeal" />
  <result column="isNotice" jdbcType="VARCHAR" property="isNotice" />
  <result column="roles" jdbcType="VARCHAR" property="roles" />
  <result column="dingtalk_user_code" jdbcType="VARCHAR" property="dingtalkUserCode" />
</resultMap>
<resultMap id="userAndMenus" type="com.datanew.model.User" extends="BaseResultMap">
  <association property="org" column="bill_org_id"  select="com.datanew.dao.PJorgMapper.selectByPrimaryKey"/>
  <association property="enter" column="bill_enter" select="com.datanew.dao.DwEnterpriseMapper.selectByEntecode"/>
  <collection property="posts" column="id" select="com.datanew.dao.XtUserpostMapper.getPostsByUserid"/>
</resultMap>

<resultMap id="userResultMap" type="com.datanew.dto.UserDTO" extends="BaseResultMap"/>

<sql id="Base_Column_List">
  <!--
  @mbggenerated
  -->
  ID, NAME, CODE, ADDRESS, PHONENO, MOBIPHONE, REGICODE, FAVREGION, AUTHROLE,
  LINKAGENCY, LINKBANK, CATEGORY, ENTENAME, bank_branch_ID, orgcoding, extendorgcoding, username,
  loginname, encryptiontype, loginpwd, email, mobile, mobile2, telephone, telephone2,
  virtualnum, userposition, usertitle, postcode, cakey, sex, birthday, country, province,
  city, officeaddress, officephone, officefax, homephone, homeaddress, official, officialtype,
  idtype, idnum, sso_user_id, bill_Sys_Status, orgname, devcode, regionScope, operationScope,
  customJson,bill_enter,bill_user_type,bill_org_id,`reset`,enteType,usestatus,userId,defaultSeal,isNotice,roles,dingtalk_user_code,changePassTime
</sql>

<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="userAndMenus">
  <!--
  @mbggenerated
  -->
  select
  <include refid="Base_Column_List" />
  from xt_user
  where ID = #{id,jdbcType=INTEGER}
</select>

<select id="getUserByCode" parameterType="String" resultMap="userAndMenus">
  select *
  from xt_user where code =#{code} and  enteType = '2'
</select>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值