mybaits一对多映射与分页组件冲突解决

main 9
hshansha 6 months ago
parent 449ed3fae6
commit 186a6b233d

@ -17,12 +17,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<collection property="pcEmps" ofType="KhEmployee">
<collection property="pcEmps" javaType="ArrayList"
ofType="KhEmployee"
select="getEmps" column="{id=id}"/>
<!--<collection property="pcEmps" ofType="KhEmployee" javaType="list">
<result property="id" column="emp_id" />
<result property="empName" column="emp_name" />
<result property="deptId" column="dept_id" />
<result property="deptName" column="dept_name" />
</collection >
</collection >-->
</resultMap>
<resultMap id="EmpsResult" type="KhEmployee">
<result property="id" column="emp_id" />
<result property="empName" column="emp_name" />
<result property="deptId" column="dept_id" />
<result property="deptName" column="dept_name" />
</resultMap>
<sql id="selectKhPingceVo">
@ -30,7 +39,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectKhPingceList" parameterType="KhPingce" resultMap="KhPingceResult">
select p.*, emp_id,emp_name,dept_id,dept_name from kh_pingce p left join kh_pc_emp pe on p.id=pe.pc_id
<include refid="selectKhPingceVo"></include>
/*select p.*, emp_id,emp_name,dept_id,dept_name from kh_pingce p left join kh_pc_emp pe on p.id=pe.pc_id*/
<where>
<if test="pcTitle != null and pcTitle != ''"> and pc_title = #{pcTitle}</if>
<if test="pcDescription != null and pcDescription != ''"> and pc_description = #{pcDescription}</if>
@ -41,9 +51,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
</select>
<select id="getEmps" resultMap="EmpsResult">
select emp_id,emp_name,dept_id,dept_name from kh_pc_emp pe
<where>
<if test="id != null "> pe.pc_id = #{id}</if>
</where>
</select>
<select id="selectKhPingceById" parameterType="Long" resultMap="KhPingceResult">
select p.*, emp_id,emp_name,dept_id,dept_name from kh_pingce p left join kh_pc_emp pe on p.id=pe.pc_id
where p.id = #{id}
<include refid="selectKhPingceVo"></include>
where id = #{id}
</select>
<insert id="insertKhPingce" parameterType="KhPingce" useGeneratedKeys="true" keyProperty="id">

@ -7,12 +7,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="KhTemplate" id="KhTemplateResult">
<result property="id" column="id" />
<result property="temName" column="tem_name" />
<!-- <result property="khitemId" column="khitem_id" />
<result property="itemName" column="item_name" />-->
<collection property="items" ofType="KhItems">
<result property="id" column="itemId" />
<result property="itemName" column="khitemName" />
</collection >
<collection property="items" ofType="KhItems " javaType="ArrayList" select="getItems" column="id"/>
</resultMap>
<resultMap id="KhItemsResult" type="KhItems">
<result property="id" column="itemId" />
<result property="itemName" column="khitemName" />
</resultMap>
<sql id="selectKhTemplateVo">
@ -20,17 +20,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectKhTemplateList" parameterType="KhTemplate" resultMap="KhTemplateResult">
select t.*,ti.khitem_id itemId ,ti.item_name khitemName from kh_template t left join kh_tem_item ti on t.id=ti.tem_id
/*select t.*,ti.khitem_id itemId ,ti.item_name khitemName from kh_template t left join kh_tem_item ti on t.id=ti.tem_id*/
<include refid="selectKhTemplateVo"/>
<where>
<if test="temName != null and temName != ''"> and tem_name like concat('%', #{temName}, '%')</if>
<!-- <if test="khitemId != null "> and khitem_id = #{khitemId}</if>
<if test="itemName != null and itemName != ''"> and item_name like concat('%', #{itemName}, '%')</if>-->
</where>
</select>
<select id="getItems" resultMap="KhItemsResult">
select ti.khitem_id itemId ,ti.item_name khitemName from kh_tem_item ti
<where>
<if test="id != null "> ti.tem_id = #{id}</if>
</where>
</select>
<select id="selectKhTemplateById" parameterType="Long" resultMap="KhTemplateResult">
select t.*,ti.khitem_id itemId ,ti.item_name khitemName from kh_template t left join kh_tem_item ti on t.id=ti.tem_id
where t.id = #{id}
<include refid="selectKhTemplateVo"/>
where id = #{id}
</select>
<insert id="insertKhTemplate" parameterType="KhTemplate" useGeneratedKeys="true" keyProperty="id">

Loading…
Cancel
Save