Mybatis查询 resultMap 一对多查询 一对一初级版
Mybatis查询 resultMap 一对多查询 一对一
-
一对多查询
<resultMap type="User" id="UserResult"> <!--主键绑定--> <id property="userId" column="user_id" /> ........................................................... <!--非主键绑定--> <result property="remark" column="remark" /> <!--引用其他的类--> <association property="dept" column="dept_id" javaType="Dept" resultMap="deptResult" /> </resultMap> <resultMap id="deptResult" type="Dept"> <id property="deptId" column="dept_id" /> <result property="leader" column="leader" /> .................................................... <result property="status" column="dept_status" /> </resultMap><resultMap type="User" id="UserResult"> <!--主键绑定--> <id property="userId" column="user_id" /> ........................................................... <!--非主键绑定--> <result property="remark" column="remark" /> <collection property="ordersList" ofType="orders" column="id" select="selectByid"> </collection> </resultMap> <select id="" parameterType="" resultMap="UserResult" > select * from UserResult where id=#{id}; </select>

浙公网安备 33010602011771号