ruoyi 对表查询(一对一,一对多)
Mapper.XML<!--联合查询用到的map--><resultMap type="LmbBirdCollect" id="LmbBirdCollectResult2"><id property="collectId"column="collect_id"/><result property="pointId"column="point_id"/>
·
Mapper.XML
<!--联合查询用到的map-->
<resultMap type="LmbBirdCollect" id="LmbBirdCollectResult2">
<id property="collectId" column="collect_id" />
<result property="pointId" column="point_id" />
<result property="collectTime" column="collect_time" />
<result property="status" column="status" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<!--一对一,使用association,property是在LmbBirdCollect实例类中的字段名,column是在LmbBirdCollect中和LmbBirdPoint相关联的字段-->
<association property="birdPoint" column="point_id" javaType="LmbBirdPoint" >
<id property="pointId" column="point_id" />
<result property="itemId" column="item_id" />
<result property="pointName" column="point_name" />
<result property="longitude" column="longitude" />
<result property="latitude" column="latitude" />
<result property="altitude" column="altitude" />
<result property="remarks" column="remarks" />
<result property="status" column="status" />
</association>
<!--一对多,使用collection,property是LmbBirdCollect实例类中的字段名,column是在LmbBirdCollect实例类和LmbBirdCollects关联的字段,注意:这里要使用ofType-->
<collection property="birdCollects" column="collect_id" ofType="LmbBirdCollects">
<id property="collecstId" column="collects_id" />
<result property="collectId" column="collect_id" />
<result property="birdId" column="bird_id" />
<result property="quantity" column="quantity" />
</collection>
</resultMap>
<select id="selectLmbBirdCollectByCollectId" parameterType="Long" resultMap="LmbBirdCollectResult2">
SELECT c.collect_id, c.point_id, c.collect_time, c.status, c.del_flag, c.create_by,
c.create_time, c.update_by, c.update_time, c.remark ,p.point_name,s.bird_id,s.quantity
FROM lmb_bird_collect c
LEFT JOIN lmb_bird_point p ON c.point_id=p.point_id
LEFT JOIN lmb_bird_collects s ON c.collect_id=s.collect_id
where c.collect_id = #{collectId}
</select>
实体类:
public class LmbBirdCollect extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 自增id */
private Long collectId;
/** 所属区域 */
@Excel(name = "所属点")
private Long pointId;
/** 创建时间 */
@Excel(name = "调查时间", width = 30, dateFormat = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date collectTime;
/** 鸟种 */
@Excel(name = "状态")
private String status;
private LmbBirdPoint birdPoint;
private List<LmbBirdCollects> birdCollects;
public List<LmbBirdCollects> getBirdCollects() {
if(birdCollects == null){
List<LmbBirdCollects> birdCollects = new ArrayList<>();
}
return birdCollects;
}
public void setBirdCollects(List<LmbBirdCollects> birdCollects) {
this.birdCollects = birdCollects;
}
public LmbBirdPoint getBirdPoint() {
if(birdPoint == null){
birdPoint = new LmbBirdPoint();
}
return birdPoint;
}
public void setBirdPoint(LmbBirdPoint birdPoint) {
this.birdPoint = birdPoint;
}
/** 删除标志(0代表存在 2代表删除) */
private String delFlag;
public String getDelFlag() {
return delFlag;
}
public void setDelFlag(String delFlag) {
this.delFlag = delFlag;
}
public Long getCollectId() {
return collectId;
}
public void setCollectId(Long collectId) {
this.collectId = collectId;
}
public Long getPointId() {
return pointId;
}
public void setPointId(Long pointId) {
this.pointId = pointId;
}
public Date getCollectTime() {
return collectTime;
}
public void setCollectTime(Date collectTime) {
this.collectTime = collectTime;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
@Override
public String toString() {
return "LmbBirdCollect{" +
"collectId=" + collectId +
", pointId=" + pointId +
", collectTime=" + collectTime +
", status='" + status + '\'' +
", birdPoint=" + birdPoint +
", birdCollects=" + birdCollects +
", delFlag='" + delFlag + '\'' +
'}';
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)