虚拟字段的使用

类上包含某个其他对象作为字段

 @Data
@ToString
@EqualsAndHashCode(callSuper = false)
public class SysRoleOrg extends BaseEntity {

	@Field(name = "角色ID", colCode = "ROLE_ID")
	private String roleId;
	
	@Field(name = "单位ID", colCode = "ORG_ID")
	private String orgId;

	//单位对象
	private SysOrg sysOrg;
}

利用序列化,在前段页面该对象的属性

Json 反序列化会让它在前端包含一个sysOrg对象的属性

mybatis 连表注入到该对象上去

<resultMap id="SysRoleOrg" type="com.kimde.framework.app.system.service.user.domain.SysRoleOrg">
		<id property="id" column="ID" jdbcType="VARCHAR" />
		<result property="orgId" column="ORG_ID" jdbcType="VARCHAR" />
		<result property="roleId" column="ROLE_ID" jdbcType="VARCHAR" />
		<!-- 虚拟字段 -->
	</resultMap>

	<resultMap id="SysRoleOrgExt" extends="SysRoleOrg" type="com.kimde.framework.app.system.service.user.domain.SysRoleOrg">
		<association property="sysOrg" javaType="com.kimde.framework.app.system.service.user.domain.SysOrg">
			<result property="id" column="sysOrg_ID" />
			<result property="orgName" column="sysOrg_ORG_NAME" jdbcType="VARCHAR" />
			<result property="orgAllname" column="sysOrg_ORG_ALLNAME" jdbcType="VARCHAR" />
		</association>
	</resultMap>


	<select id="getAllWithParent" resultMap="SysRoleOrgExt">
		select * from(
			SELECT
			t1.*,
			t2.ID as sysOrg_ID, t2.ORG_NAME as sysOrg_ORG_NAME, t2.ORG_ALLNAME as sysOrg_ORG_ALLNAME
			FROM SYS_ROLE_ORG t1
			left join SYS_ORG t2 on t2.ID = t1.ORG_ID
		) t
		<include refid="dynamicWhere" />
		<if test="@ObjUtil@isNotEmpty(orderStrs)">
			order by ${orderStrs}
		</if>
		<if test="@ObjUtil@isEmpty(orderStrs)">
			order by CREATE_DATE desc
		</if>
	</select>


posted @ 2020-10-30 21:28  由来一声笑  阅读(478)  评论(0)    收藏  举报