无参构造函数
角色实体类
@Data
@Alias("RoleDTO")
public class RoleDTO {
private Long id;
// 角色名称
private String roleName;
// 角色类型
private Integer roleType;
// 角色描述
private String roleDesc;
// 角色状态
private Integer status;
// 角色人数
private Long roleCount;
// 禁止删除标志
private Integer forbidDel;
// 角色人员
private List<Long> userIds;
}
注意:
当前实体类是无参构造函数
Mapper 文件
<resultMap id="RoleResultMap" type="RoleDTO">
<id property="id" column="id"/>
<result property="roleName" column="role_name"/>
<result property="roleType" column="role_type"/>
<result property="roleDesc" column="role_desc"/>
<result property="status" column="status"/>
<collection property="userIds" ofType="Long">
<constructor>
<arg column="user_id"/>
</constructor>
</collection>
</resultMap>
带参数构造函数
角色实体类
@Data
@Alias("RoleDTO")
public class RoleDTO {
private Long id;
// 角色名称
private String roleName;
// 角色类型
private Integer roleType;
// 角色描述
private String roleDesc;
// 角色状态
private Integer status;
// 角色人数
private Long roleCount;
// 禁止删除标志
private Integer forbidDel;
// 角色人员
private List<Long> userIds;
public RoleDTO(Long id, Integer status) {
this.id = id;
this.status = status;
}
}
注意:
当前实体类的构造函数是带有id和status入参
Mapper 文件
<resultMap id="RoleResultMap" type="RoleDTO">
<!-- 注意实体类中只有有参数的构造方法, 此处需要匹配实体类中的构造方法 -->
<constructor>
<idArg column="id" javaType="Long" />
<arg column="status" javaType="Integer" />
</constructor>
<result property="roleName" column="role_name"/>
<result property="roleType" column="role_type"/>
<result property="roleDesc" column="role_desc"/>
<collection property="userIds" ofType="Long">
<constructor>
<arg column="user_id"/>
</constructor>
</collection>
</resultMap>