类1
package com.taiji.model.alarm.entity;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Data
public class AlarmRule implements Serializable {
private static final long serialVersionUID = 581079209770691676L;
@JsonProperty("uuid")
private String Id;
@JsonProperty("alarm_level")
private String alarmLevel;
@JsonProperty("check_frequency")
private String checkFrequency;
@JsonProperty("created_at")
private Object createdAt;
@JsonProperty("created_by")
private String createdBy;
@JsonProperty("current_taskid")
private String currentTaskid;
private String deviceid;
@JsonProperty("is_active")
private Boolean isActive;
private String name;
@JsonProperty("query_interval")
private String queryInterval;
private Integer state;
private String typeid;
@JsonProperty("updated_at")
private Date updatedAt;
private List<AlarmCondition> alarmconditions ;
}
类2
package com.taiji.model.alarm.entity;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
public class AlarmCondition implements Serializable {
private static final long serialVersionUID = 381720044793804052L;
@JsonProperty("uuid")
private String Id;
private String attributeid;
@JsonProperty("created_at")
private Date createdAt;
@JsonProperty("created_by")
private String createdBy;
private String function;
@JsonProperty("is_active")
private Boolean isActive;
private String ruleid;
private String sign;
private Integer state;
@JsonProperty("updated_at")
private Date updatedAt;
@JsonProperty("yu_value")
private String yuValue;
}
XML mapper 首先声明一个resultMap
<resultMap id="ResultMapWhitCondition" type="com.taiji.model.alarm.entity.AlarmRule">
<!--@Table alarm_rule-->
<result property="id" column="id" jdbcType="VARCHAR"/>
<result property="alarmLevel" column="alarm_level" jdbcType="VARCHAR"/>
<result property="checkFrequency" column="check_frequency" jdbcType="VARCHAR"/>
<result property="createdAt" column="created_at" jdbcType="OTHER"/>
<result property="createdBy" column="created_by" jdbcType="VARCHAR"/>
<result property="currentTaskid" column="current_taskid" jdbcType="VARCHAR"/>
<result property="deviceid" column="deviceid" jdbcType="VARCHAR"/>
<result property="isActive" column="is_active" jdbcType="BOOLEAN"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="queryInterval" column="query_interval" jdbcType="VARCHAR"/>
<result property="state" column="state" jdbcType="INTEGER"/>
<result property="typeid" column="typeid" jdbcType="VARCHAR"/>
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
<collection property="alarmconditions"
ofType="com.taiji.model.alarm.entity.AlarmCondition">
<result property="id" column="id" jdbcType="VARCHAR"/>
<result property="attributeid" column="attributeid" jdbcType="VARCHAR"/>
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
<result property="createdBy" column="created_by" jdbcType="VARCHAR"/>
<result property="function" column="function" jdbcType="VARCHAR"/>
<result property="isActive" column="is_active" jdbcType="BOOLEAN"/>
<result property="ruleid" column="ruleid" jdbcType="VARCHAR"/>
<result property="sign" column="sign" jdbcType="VARCHAR"/>
<result property="state" column="state" jdbcType="INTEGER"/>
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
<result property="yuValue" column="yu_value" jdbcType="VARCHAR"/>
</collection>
</resultMap>
编写查询语句
<select id="selectPageWhitCondition" resultMap="ResultMapWhitCondition">
select
*
from alarm_rule a,alarm_condition b
where 1=1
<if test="domain.deviceid != null and domain.deviceid != ''">
and deviceid = #{domain.deviceid}
</if>
<if test="domain.typeid != null and domain.typeid != ''">
and typeid = #{domain.typeid}
</if>
and a.id = b.ruleid
</select>
查询代码
@Override
public CommonPageDTO<AlarmRule> queryAlarmRuleList(CommonPageDTO<AlarmRule> commonPageDTO) {
Page page = CommonMybatisPageUtil.getInstance().pageDTOtoPage(commonPageDTO,"id");
AlarmRule domain = commonPageDTO.getFilters();
IPage<AlarmRule> alarmRuleVoIPage = alarmRuleDao.selectPageWhitCondition(page,domain);
CommonPageDTO resultPage = CommonMybatisPageUtil.getInstance().iPageToCommonPageDTO(alarmRuleVoIPage, AlarmRule.class, commonPageDTO);
return resultPage;
}
返回值