时间:2021-07-01 10:21:17 帮助过:106人阅读
public class Test{ private Integer userID; // 主键ID private String username; // 姓名 private String idCard; // 身份证号 private Integer sex; //性别 private String mobilePhone; // 手机号 private List<Test> propertyList; //List属性 }
ibatis对应XML文件查询代码:
<resultMap id="List_result" class="com.ceshi.user.domain.User"> <result property="userID" column="userID"/> <result property="idCard" column="idCard"/> <result property="username" column="username"/> <result property="mobilePhone" column="mobilePhone"/> <result property="propertyList" column="{userID=userID}" select="getpropertyList"/> </resultMap> <select id="getpropertyList" parameterClass="HashMap" resultClass="com.ceshi.user.domain.User"> SELECT userID ,paperName, GROUP_CONCAT(courseRecomm SEPARATOR ‘,‘) courseRecomm FROM test WHERE userID = #userID# GROUP BY userID,paperName </select> <select id="getList" parameterClass="com.ceshi.user.domain.User" resultMap="List_result"> SELECT a.userID, a.idCard, a.username, CASE a.sex WHEN ‘1‘ THEN ‘女‘ ELSE ‘男‘ END AS sexName, a.mobilePhone, FROM user a <dynamic prepend="WHERE"> <isNotNull prepend="AND" property="userID"> a.userID=#userID# </isNotNull> <isNotNull prepend="AND " property="username"> a.username like‘%$username$%‘</isNotNull> <isNotNull prepend="AND" property="idCard"> a.idCard=#idCard# </isNotNull> </dynamic> ORDER BY a.userID DESC </select>
简单来张图说明一下;
查问卷表拼接用户结果是这样的:同一个人对应多张试卷,查询试卷表结果。
但是我只想查用户表,也返回用户对应的试卷,也就是这样:
记录一下,虽然简单。
ibatis查询SQL语句返回一个对象,此对象包含一个List属性
标签:result user shm select str tor 关系 like 技术分享