数据库表
image.pngpms_user_tea表保存教师用户信息
image.png
pms_exp表保存实验室信息
查询信息:所有教师下的所有实验室
java类
package com.pms.pojo;
import java.util.List;
/**
* @author:wong
*/
public class TeaExp extends PmsUserTea{
private List<PmsExp> pmsExps;
public List<PmsExp> getPmsExps() {
return pmsExps;
}
public void setPmsExps(List<PmsExp> pmsExps) {
this.pmsExps = pmsExps;
}
}
编写PmsUserTeaMapper.xml文件
resultMap定义
<resultMap id="TeaExpListResultMap" type="com.pms.pojo.TeaExp">
<id column="teaId" property="id" jdbcType="BIGINT"/>
<result column="nickname" property="nickname" jdbcType="VARCHAR" />
<collection property="pmsExps" ofType="com.pms.pojo.PmsExp">
<id property="id" column="expId"/>
<result column="expName" property="expName"/>
</collection>
</resultMap>
sql语句定义
<select id="findTeaExpList" resultMap="TeaExpListResultMap">
SELECT DISTINCT
pms_user_tea.id AS teaId,
pms_user_tea.nickname,
pms_exp.exp_name AS expName,
pms_exp.id AS expId
FROM
pms_user_tea ,pms_exp
WHERE pms_user_tea.id=pms_exp.tutor_id
</select>
编写服务测试
测试结果:
image.png
网友评论