当前使用版本(必填,否则不予处理)
3.4.2
该问题是如何引起的?(确定最新版也有问题再提!!!)
有没有mybatis原生xml文件中的一对一、一对多聚合字段的功能 类似下面这样的字段隐射,在mybatis plus里面怎么做呢
<resultMap type="SysUser" id="SysUserResult">
<id property="userId" column="user_id" />
<result property="deptId" column="dept_id" />
<association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult" />
<collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
</resultMap>
<resultMap id="deptResult" type="SysDept">
<id property="deptId" column="dept_id" />
<result property="parentId" column="parent_id" />
</resultMap>
<resultMap id="RoleResult" type="SysRole">
<id property="id" column="role_id" />
<result property="roleName" column="role_name" />
</resultMap>
重现步骤(如果有就写完整)
报错信息
Comment From: yhl452493373
mybatis咋写,这个就咋写。。。
Comment From: VampireAchao
mybatis咋写,这个就咋写。。。
Comment From: adolphus0114
爱咋写咋写,生效算你赢
Comment From: qmdx
1,使用原生 xml 方式,例如:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.test.demo.mapper.ClassroomMapper">
<resultMap id="ClassroomResult" type="com.test.demo.domain.Classroom">
<id column="cid" property="cid" />
<result column="cname" property="cname" />
<!-- 一对多的关系 -->
<!-- property: 指的是集合属性的值,对应类中的属性名 ofType:指的是集合中元素的类型 -->
<collection property="students" ofType="com.test.demo.domain.Student">
<id column="id" property="id" />
<result column="sname" property="sname" />
<result column="age" property="age" />
</collection>
</resultMap>
<select id="listClassroom" resultMap="ClassroomResult">
select c.*,s.* from classroom c left join student s on c.cid = s.cid
</select>
</mapper>
2,使用第三方插件 https://github.com/yulichang/mybatis-plus-join