mybatis查询返回数据,和嵌套类之间的转换
public class DoneRegistRes {
private Registration registration;
private DangerousGoods dangerousGoods;
private IdCard idCard;
private RailwayTicket railwayTicket;
private RegistPerInfo registPerInfo;
}
public class Registration {
private int id;
private int creatorId;
private String lkqz;
private String lkqzPic;
private String entranceName;
private String classNum;
private String stationName;
private int status;
private long createTime;
private String registNum;
private String classGroupInfo;
}
public class DangerousGoods {
private int id;
private String picPath;
private String name;
private String kind;
private String shape;
private String method;
private int status;
private long createTime;
private int registrationId;
private String remark;
private int countNum;
}
public class IdCard {
private int id;
private String name;
private String idNumber;
private String address;
private String picPath;
private int status;
private long createTime;
private int registrationId;
private String remark;
}
public class RailwayTicket {
private int id;
private String trainNum;
private String ticketNum;
private String destination;
private String startPlace;
private String picPath;
private int status;
private long createTime;
private int registrationId;
private String remark;
}
public class RegistPerInfo {
private int id;
private String jcry;
private String jcgw;
private String czry;
private String czmj;
private int status;
private long createTime;
private int registrationId;
private String remark;
}
{
"code": 200,
"msg": "成功",
"data": {
"dangerousGoods": {
"id": 1,
"picPath": null,
"name": "打火机",
"kind": "类别1",
"shape": "长方形",
"method": "回收",
"status": 1,
"createTime": 159468940,
"registrationId": 1,
"remark": "无",
"countNum": 1
},
"idCard": {
"id": 1,
"name": "李四",
"idNumber": "1010236321",
"address": "合肥高新区",
"picPath": null,
"status": 1,
"createTime": 1594689460,
"registrationId": 1,
"remark": "无"
},
"registPerInfo": {
"id": 1,
"jcry": "阿sir3",
"jcgw": "机检",
"czry": "阿sir2",
"czmj": "阿sir1",
"status": 1,
"createTime": 1594691120,
"registrationId": 1,
"remark": "string"
},
"registration": {
"id": 1,
"creatorId": 18,
"lkqz": "张三签字",
"lkqzPic": null,
"entranceName": "北广场1号进站口",
"classNum": "一班一组",
"stationName": "合肥南",
"status": 1,
"createTime": 1594621977,
"registNum": null,
"classGroupInfo": null
},
"railwayTicket": {
"id": 1,
"trainNum": "G306",
"ticketNum": "票号1",
"destination": "北京南",
"startPlace": "合肥南",
"picPath": null,
"status": 1,
"createTime": 1594689537,
"registrationId": 1,
"remark": "无"
}
},
"success": true
}
- 参考mybatis中多对一的情况,使用association解决。mapper.xml代码如下
<resultMap id="DataAllMap" type="com.qxmz.dgr.vo.dataStatistics.DoneRegistRes">
<association property="registration" javaType="Registration">
<id column="registration_id" jdbcType="INTEGER" property="id"/>
<result column="creatorId" jdbcType="INTEGER" property="creatorId"/>
<result column="lkqz" jdbcType="VARCHAR" property="lkqz"/>
<result column="lkqzPic" jdbcType="VARCHAR" property="lkqzPic"/>
<result column="entranceName" jdbcType="VARCHAR" property="entranceName"/>
<result column="classNum" jdbcType="VARCHAR" property="classNum"/>
<result column="stationName" jdbcType="VARCHAR" property="stationName"/>
<result column="registration_status" jdbcType="INTEGER" property="status"/>
<result column="registration_createTime" jdbcType="BIGINT" property="createTime"/>
<result column="registNum" jdbcType="VARCHAR" property="registNum"/>
<result column="classGroupInfo" jdbcType="VARCHAR" property="classGroupInfo"/>
</association>
<association property="dangerousGoods" javaType="DangerousGoods">
<id column="dangerousGoods_id" jdbcType="INTEGER" property="id"/>
<result column="dangerousGoods_picPath" jdbcType="VARCHAR" property="picPath"/>
<result column="dangerousGoods_name" jdbcType="VARCHAR" property="name"/>
<result column="kind" jdbcType="VARCHAR" property="kind"/>
<result column="shape" jdbcType="VARCHAR" property="shape"/>
<result column="method" jdbcType="VARCHAR" property="method"/>
<result column="dangerousGoods_status" jdbcType="INTEGER" property="status"/>
<result column="dangerousGoods_createTime" jdbcType="BIGINT" property="createTime"/>
<result column="dangerousGoods_registrationId" jdbcType="INTEGER" property="registrationId"/>
<result column="dangerousGoods_remark" jdbcType="VARCHAR" property="remark"/>
<result column="countNum" jdbcType="INTEGER" property="countNum"/>
</association>
<association property="idCard" javaType="IdCard">
<id column="idCard_id" property="id"/>
<result column="idCard_name" property="name"/>
<result column="idNumber" property="idNumber"/>
<result column="address" property="address"/>
<result column="idCard_picPath" property="picPath"/>
<result column="idCard_status" property="status"/>
<result column="idCard_createTime" property="createTime"/>
<result column="idCard_registrationId" property="registrationId"/>
<result column="idCard_remark" property="remark"/>
</association>
<association property="railwayTicket" javaType="RailwayTicket">
<id column="railwayTicket_id" property="id"/>
<result column="trainNum" property="trainNum"/>
<result column="ticketNum" property="ticketNum"/>
<result column="destination" property="destination"/>
<result column="startPlace" property="startPlace"/>
<result column="railwayTicket_picPath" property="picPath"/>
<result column="railwayTicket_status" property="status"/>
<result column="railwayTicket_createTime" property="createTime"/>
<result column="railwayTicket_registrationId" property="registrationId"/>
<result column="railwayTicket_remark" property="remark"/>
</association>
<association property="registPerInfo" javaType="RegistPerInfo">
<id column="registPerInfo_id" property="id"/>
<result column="jcry" property="jcry"/>
<result column="jcgw" property="jcgw"/>
<result column="czry" property="czry"/>
<result column="czmj" property="czmj"/>
<result column="registPerInfo_status" property="status"/>
<result column="registPerInfo_createTime" property="createTime"/>
<result column="registPerInfo_registrationId" property="registrationId"/>
<result column="registPerInfo_remark" property="remark"/>
</association>
</resultMap>
<select id="getDoneOrToDoRegistrationDetailByGroupTest" parameterType="Map" resultMap="DataAllMap">
SELECT *,re.id registration_id, re.createTime registration_createTime, re.status registration_status ,
idc.id idCard_id,idc.name idCard_name,idc.`picPath` idCard_picPath,idc.`remark` idCard_remark,idc.`status` idCard_status,
rt.id railwayTicket_id,rt.`picPath` railwayTicket_picPath,rt.`remark` railwayTicket_remark,rt.`status` railwayTicket_status,
dg.id dangerousGoods_id,dg.`name` dangerousGoods_name,dg.`picPath` dangerousGoods_picPath,dg.`remark` dangerousGoods_remark,dg.`status` dangerousGoods_status,
rp.id registPerInfo_id,rp.`remark` registPerInfo_remark,rp.`status` registPerInfo_status
FROM registration re
LEFT JOIN idcard idc ON re.id=idc.registrationId
LEFT JOIN railway_ticket rt ON re.id=rt.registrationId
LEFT JOIN dangerous_goods dg ON re.id=dg.registrationId
LEFT JOIN regist_per_info rp ON re.id=rp.registrationId
<where>
<if test="status!=null and status!=0">
and re.status = #{status}
</if>
<if test="stationName!=null">
and re.stationName = #{stationName}
</if>
<if test="keyWord!=null and keyWord!=''">
and idc.name like concat('%',#{keyWord},'%') or rt.trainNum like concat('%',#{keyWord},'%')
</if>
<if test="classNameList!=null ">
and classNum IN
<foreach item="item" index="index" collection="classNameList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
ORDER BY registration_createTime DESC
</where>
</select>