1 需要返回的类,带有一个子类集合
@Data
public class SentryHandoverSystemResult {
@ApiModelProperty("制度名称")
private String id;
/**
* 制度名称
*/
@ApiModelProperty("制度名称")
private String systemName;
/**
* 制度描述
*/
@ApiModelProperty("制度描述")
private String systemDescription;
/**
* 正常交接最早可提前xx分钟
*/
@ApiModelProperty("正常交接最早可提前xx分钟")
private String normalHandoverEarliest;
/**
* 正常交接最晚可提推迟xx分钟
*/
@ApiModelProperty("正常交接最晚可提推迟xx分钟")
private String normalHandoverLatest;
/**
* 误岗最早可提前xx分钟
*/
@ApiModelProperty("误岗最早可提前xx分钟")
private String missHandoverEarliest;
/**
* 误岗最晚可推迟xx分钟
*/
@ApiModelProperty("误岗最晚可推迟xx分钟")
private String missHandoverLatest;
/**
* 脱岗最早可提前xx分钟
*/
@ApiModelProperty("脱岗最早可提前xx分钟")
private String leaveHandoverEarliest;
/**
* 脱岗最晚可推迟xx分钟
*/
@ApiModelProperty("脱岗最晚可推迟xx分钟")
private String leaveHandoverLatest;
/**
* 未交接最早可提前xx分钟以上
*/
@ApiModelProperty("未交接最早可提前xx分钟以上")
private String noNormalHandoverEarliest;
/**
* 未交接最晚可推迟xx分钟以上
*/
@ApiModelProperty("未交接最晚可推迟xx分钟以上")
private String noNormalHandoverLatest;
/**
* 创建人
*/
@ApiModelProperty("创建人名称")
private String creator;
/**
* 创建人名称
*/
@ApiModelProperty("创建人名称")
private String creatorName;
/**
* 创建人单位
*/
@ApiModelProperty("创建人单位")
private String founderUnit;
/**
* 创建时间
*/
@ApiModelProperty("创建时间")
private LocalDateTime createTime;
/**
* 修改人
*/
@ApiModelProperty("修改人")
private String modifier;
/**
* 修改人名称
*/
@ApiModelProperty("修改人名称")
private String modifierName;
/**
* 修改时间
*/
@ApiModelProperty("修改时间")
private LocalDateTime modifierTime;
/**
* 哨点集合
*/
@ApiModelProperty("哨点集合")
private List<SentryHandoverSystemPoint> sentryHandoverSystemPointList;
}
2 XML写法:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ikingtech.camp.sentry.handover.client.mappers.UniversalMapper">
<resultMap id="BaseResultMap" type="com.ikingtech.camp.sentry.handover.client.result.SentryHandoverSystemResult">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="system_name" jdbcType="VARCHAR" property="systemName" />
<result column="system_description" jdbcType="VARCHAR" property="systemDescription" />
<result column="normal_handover_earliest" jdbcType="VARCHAR" property="normalHandoverEarliest" />
<result column="normal_handover_latest" jdbcType="INTEGER" property="normalHandoverLatest" />
<result column="miss_handover_latest" jdbcType="BIT" property="missHandoverLatest" />
<result column="leave_handover_latest" jdbcType="VARCHAR" property="leaveHandoverLatest" />
<result column="leave_handover_earliest" jdbcType="VARCHAR" property="leaveHandoverEarliest" />
<result column="no_normal_handover_earliest" jdbcType="VARCHAR" property="noNormalHandoverEarliest" />
<result column="no_normal_handover_latest" jdbcType="VARCHAR" property="noNormalHandoverLatest" />
<result column="creator_name" jdbcType="VARCHAR" property="creatorName" />
<result column="creator" jdbcType="VARCHAR" property="creator" />
<result column="founder_unit" jdbcType="INTEGER" property="founderUnit" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="modifier" jdbcType="VARCHAR" property="modifier" />
<result column="modifier_name" jdbcType="INTEGER" property="modifierName" />
<result column="modifier_time" jdbcType="TIMESTAMP" property="modifierTime" />
<collection property="sentryHandoverSystemPointList" javaType="java.util.ArrayList"
ofType="com.ikingtech.camp.sentry.handover.client.model.SentryHandoverSystemPoint">
<id column="spId" jdbcType="VARCHAR" property="id" />
<result column="spSystemNameId" jdbcType="VARCHAR" property="systemNameId" />
<result column="spPointName" jdbcType="VARCHAR" property="pointName" />
<result column="spPointId" jdbcType="VARCHAR" property="pointId" />
</collection>
</resultMap>
<sql id="Find_Base_Column_List">
s.id as id,
s.system_name as system_name,
s.system_description as system_description,
s.normal_handover_earliest as normal_handover_earliest,
s.normal_handover_latest as normal_handover_latest,
s.miss_handover_earliest as miss_handover_earliest,
s.miss_handover_latest as miss_handover_latest,
s.leave_handover_latest as leave_handover_latest,
s.leave_handover_earliest as leave_handover_earliest,
s.no_normal_handover_earliest as no_normal_handover_earliest,
s.no_normal_handover_latest as no_normal_handover_latest,
s.creator_name as creator_name,
s.creator as creator,
s.founder_unit as founder_unit,
s.create_time as create_time,
s.modifier as modifier,
s.modifier_name as modifier_name,
s.modifier_time as modifier_time,
sp.id as spId,
sp.point_name as spPointName,
sp.system_name_id as spSystemNameId,
sp.point_id as spPointId
</sql>
<select id="findRules" resultMap="BaseResultMap">
SELECT
<include refid="Find_Base_Column_List"/>
FROM
sentry_handover_system s
JOIN sentry_handover_system_point sp ON s.id = sp.system_name_id
WHERE
1 = 1
<if test="param.systemName !=null and param.systemName!= ''">
AND s.system_name=#{param.systemName}
</if>
<if test="param.pointName !=null and param.pointName!= ''">
and sp.point_name=#{param.pointName}
</if>
ORDER BY s.create_time desc
</select>
</mapper>
3 接口定义:
@Mapper
public interface UniversalMapper {
List<SentryHandoverSystemResult> findRules(@Param("param") SentryHandoverPageParam param);
}
4 调用:
/**
* 查询
*
* @param param 查询参数
*/
@Override
public Result<List<SentryHandoverSystemResult>> find(SentryHandoverPageParam param) {
PageInfo<SentryHandoverSystemResult> pageInfo = PageHelper.startPage(param.getPage(), param.getRows()).doSelectPageInfo(() -> {
universalMapper.findRules(param);
}
);
return Result.successPage(pageInfo.getList(), pageInfo.getTotal(), pageInfo.getPages());
}