关键字:mybaits关联查询,mybaits一对多查询,一个表单里面有多个附件,mapper.xml中一对多查询
主要描述信息: 一个学生对应多门功课,每门功课对应学分
<select id="getDetialByPrimaryKey" parameterType="java.math.BigDecimal" resultMap="BaseResultMap">
select
*
from 学生表名 j
<!-- 等下查询附件的东西-->
left join 功课表名 p on p.student_id= j.id
left join 学分表名 pi on pi.class_id = p.id
where p.id = '课程id'
and j.id= '学生id'
</select>
一般书写传入形式为#{学生id参数名,jdbcType=DECIMAL)}
jdbcType=DECIMAL 这个是学生id参数类型
j 学生表名别名
p 功课表名别名
pi 学分表名别名
j.id 学生id
p.student_id 功课表中对应的学生id
pi.class_id 学分表中对应的课程id
image.png
返回参数类型在mapper.xml里面的定义
collection是数组类型里面的元素对应的是实体类com.yrec.admin.server.model.PubFileInfo
BaseResultMap 对应的是实体类com.yrec.admin.server.model.JGSGZC
<resultMap id="BaseResultMap" type="com.yrec.admin.server.model.JGSGZC">
<id column="sid" jdbcType="DECIMAL" property="sid" />
<result column="chkno" jdbcType="VARCHAR" property="chkno" />
<result column="chkname" jdbcType="VARCHAR" property="chkname" />
<result column="chkdate" jdbcType="TIMESTAMP" property="chkdate" />
<result column="prono" jdbcType="VARCHAR" property="prono" />
<result column="cprono" jdbcType="VARCHAR" property="cprono" />
<result column="cproname" jdbcType="VARCHAR" property="cproname" />
<result column="chker" jdbcType="VARCHAR" property="chker" />
<result column="chkdept" jdbcType="VARCHAR" property="chkdept" />
<result column="chkcont" jdbcType="VARCHAR" property="chkcont" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="jlrid" jdbcType="DECIMAL" property="jlrid" />
<result column="jlr" jdbcType="VARCHAR" property="jlr" />
<result column="jlsj" jdbcType="TIMESTAMP" property="jlsj" />
<result column="jldw" jdbcType="VARCHAR" property="jldw" />
<result column="jldwid" jdbcType="DECIMAL" property="jldwid" />
<result column="dcstatus" jdbcType="VARCHAR" property="dcstatus" />
<collection property="files" ofType="com.yrec.admin.server.model.PubFileInfo">
<id column="ID_" jdbcType="DECIMAL" property="id" />
<result column="FILE_NAME" jdbcType="VARCHAR" property="fileName" />
<result column="FILE_NAME_OLD" jdbcType="VARCHAR" property="fileNameOld" />
<result column="FILEPATH" jdbcType="VARCHAR" property="filepath" />
<result column="OPTRNAME" jdbcType="VARCHAR" property="optrname" />
<result column="OPTRCODE" jdbcType="VARCHAR" property="optrcode" />
<result column="UPLOAD_TIME" jdbcType="TIMESTAMP" property="uploadTime" />
<result column="STATES" jdbcType="VARCHAR" property="states" />
<result column="DESC_" jdbcType="VARCHAR" property="desc" />
<result column="EXTENDS1" jdbcType="VARCHAR" property="extends1" />
<result column="EXTENDS2" jdbcType="VARCHAR" property="extends2" />
<result column="EXTENDS3" jdbcType="VARCHAR" property="extends3" />
<result column="EXTENDS4" jdbcType="VARCHAR" property="extends4" />
<result column="EXTENDS5" jdbcType="VARCHAR" property="extends5" />
<result column="DOCTYPE" jdbcType="VARCHAR" property="doctype" />
<result column="DOCID" jdbcType="DECIMAL" property="docid" />
<result column="FILEPATH_OLD" jdbcType="VARCHAR" property="filepathOld" />
<result column="ATTID_OLD" jdbcType="DECIMAL" property="attidOld" />
<result column="SENDID" jdbcType="DECIMAL" property="sendid" />
<result column="FILE_TABLENAME" jdbcType="VARCHAR" property="fileTablename" />
<result column="KEYFIELDVALUE" jdbcType="DECIMAL" property="keyfieldvalue" />
<result column="KEYFIELD" jdbcType="VARCHAR" property="keyfield" />
<result column="SORTNO" jdbcType="DECIMAL" property="sortno" />
</collection>
</resultMap>
对应的返回结果
image.png
有什么不明白的请老铁们留言 我看到了会第一时间回复
网友评论