概述
主要是返回数据类型对应关系需要注意一下。具体实现示例如下,
1、查询结果实体类(一对多中的"一")
package sol.erms.model.entity.process.use;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
/**
* <p>
* 借阅记录表/借阅主表导出表
* </p>
*
* @author groot
* @since 2020-03-18
*/
@Data
public class ErmsUseMainExport implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 借阅编号
*/
private String useNo;
/**
* 借阅人
*/
private String ermsLender;
/**
* 借阅目的
*/
private String ermsLendingpurpose;
//条目集合
private List<ERMSUseExport> archList;
}
2、查询结果子对象实体类(一对多中的"多")
package sol.erms.model.entity.process.use;
import lombok.Data;
import java.util.Date;
@Data
public class ERMSUseExport {
private String archName;
private String archNo;
private String ermsApplymode;
private Date startUseDate;
private String ermsLendhandler;
private String ermsBorrowReviewer;
private Date ermsReturntime;
private Date ermsReturner;
private Date ermsReturnhandler;
private Date ermsReturnReviewer;
}
3、mapper/dao方法:
List<ErmsUseMainExport> getMainListUseCollectionByCondition(Map<String, Object> map);
4、xml中的sql。定义返回数据类型,通过collection标签对应子集即可。
<resultMap type="sol.erms.model.entity.process.use.ErmsUseMainExport" id="useMainResult">
<result column="USE_NO" property="useNo" />
<result column="ERMS_LENDER" property="ermsLender" />
<result column="ERMS_LENDINGPURPOSE" property="ermsLendingpurpose" />
<collection property="archList" ofType="sol.erms.model.entity.process.use.ERMSUseExport" column="id">
<result column="ARCH_NAME" jdbcType="TIMESTAMP" property="archName" />
<result column="ARCH_NO" jdbcType="VARCHAR" property="archNo" />
<result column="ERMS_APPLYMODE" property="ermsApplymode" />
<result column="START_USE_DATE" property="startUseDate" />
<result column="ERMS_LENDHANDLER" property="ermsLendhandler" />
<result column="ERMS_BORROW_REVIEWER" property="ermsBorrowReviewer" />
<result column="ERMS_RETURNTIME" property="ermsReturntime" />
<result column="ERMS_RETURNER" property="ermsReturner" />
<result column="ERMS_RETURN_HANDLER" property="ermsReturnhandler" />
<result column="ERMS_RETURN_REVIEWER" property="ermsReturnReviewer" />
</collection>
</resultMap>
<!--条件查询借阅+档案(集合)数据-->
<select id="getMainListUseCollectionByCondition" resultMap="useMainResult">
SELECT
m.`USE_NO`,
m.`ERMS_LENDER`,
m.`ERMS_LENDINGPURPOSE`,
m.ERMS_APPLYMODE,
u.START_USE_DATE,
u.ERMS_LENDHANDLER,
u.ERMS_BORROW_REVIEWER,
u.ERMS_RETURNTIME,
u.ERMS_RETURNER,
u.ERMS_RETURN_HANDLER,
u.ERMS_RETURN_REVIEWER,
a.ARCH_NO,
a.ARCH_NAME
FROM
erms_use_main m
LEFT JOIN erms_use u ON m.ID = u.ERMS_USE_MAIN_ID
LEFT JOIN erms_archived_arch_ru a ON u.ERMS_ARCH_FORM_ID = a.ID
<where>
<if test="DEL_STATUS!=null and DEL_STATUS!=''">
m.DEL_STATUS = #{DEL_STATUS}
</if>
<if test="ids!=null and ids.size()>0">
m.ID IN
<foreach collection="ids" item="id" open="(" close=")" separator="," >
#{id}
</foreach>
</if>
</where>
</select>
最后
以上就是称心盼望为你收集整理的mybatis/mybatis-plus一对多查询的全部内容,希望文章能够帮你解决mybatis/mybatis-plus一对多查询所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复