- 使用mybatis一对多:
-
使用collection 标签: collection属性: property: 指的是集合属性的值. ofType:指的是集合中元素的类型. <collection property="products" ofType="com.xx.xxx"></collection> 例:在resultMap标签中 <collection property="teachers" ofType="com.xxx.xxxx.products"> <id property="tid" column="id"/> <result property="tname" column="tname"/> </collection> 注意:查询的时候如果关联表字段重复需要重命名. 例如:<id property="tid" column="id"/> <resultMap id="userMap" type="com.xxx.xxx.User"> <id property="id" column="id"/> <result property="username" column="username"/> <result property="birthday" column="birthday"/> <result property="sex" column="sex"/> <result property="address" column="address"/> <collection property="roles" ofType="com.example.domain.Role" resultMap="roleMap"/> </resultMap> <resultMap id="roleMap" type="com.xxx.xxx.Role"> <id property="roleId" column="rid"/> <result property="roleName" column="ROLE_NAME"/> <result property="roleDesc" column="ROLE_DESC"/> </resultMap> <select id="findAll" resultMap="userMap"> SELECT u.*,r.ID as rid,r.ROLE_DESC,r.ROLE_NAME FROM user u LEFT OUTER JOIN user_role ur on u.id = ur.UID LEFT OUTER JOIN role r on ur.RID = r.ID </select>
-
-
使用mybatis一对一
-
使用association标签 property: 指的是集合属性的值. javaType:指定关联的类型 <association property="People" javaType="com.xxx.xxx.user">
-
-
分页查询 问题解决: https://blog.csdn.net/wszcy199503/article/details/77867990:
mybatis.一对一,一对多
最新推荐文章于 2021-07-18 11:17:58 发布