修复PageHelper分页问题,Mapper连接查询改为子查询

This commit is contained in:
tangpeng 2019-06-16 17:48:24 +08:00
parent d1a07af916
commit c147cfd71a
3 changed files with 122 additions and 107 deletions

View File

@ -1,6 +1,7 @@
package com.ruoyi.template.mapper; package com.ruoyi.template.mapper;
import com.ruoyi.template.domain.TmplSwitchPort; import com.ruoyi.template.domain.TmplSwitchPort;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -28,6 +29,8 @@ public interface TmplSwitchPortMapper {
*/ */
public TmplSwitchPort selectBySwitchIdAndPortType(Integer switchId, Integer switchPortType); public TmplSwitchPort selectBySwitchIdAndPortType(Integer switchId, Integer switchPortType);
public TmplSwitchPort selectBySwitchId(@Param("switchId") Integer switchId);
/** /**
* 查询交换机端口类型列表 * 查询交换机端口类型列表
* *

View File

@ -4,40 +4,26 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.template.mapper.TmplSwitchMapper"> <mapper namespace="com.ruoyi.template.mapper.TmplSwitchMapper">
<resultMap type="com.ruoyi.template.domain.TmplSwitch" id="TmplSwitchResult"> <resultMap type="com.ruoyi.template.domain.TmplSwitch"
id="TmplSwitchResult">
<result property="switchId" column="switch_id"/> <result property="switchId" column="switch_id"/>
<result property="switchBrand" column="switch_brand"/> <result property="switchBrand" column="switch_brand"/>
<result property="switchType" column="switch_type"/> <result property="switchType" column="switch_type"/>
<result property="powerNum" column="power_num"/> <result property="powerNum" column="power_num"/>
<collection property="switchPorts" ofType="com.ruoyi.template.domain.TmplSwitchPort" column="switch_id"> <collection property="switchPorts" column="switch_id"
<id column="pid" property="switchPortId"/><!-- 这里的column对应的是下面查询的别名而不是表字段名 --> select="com.ruoyi.template.mapper.TmplSwitchPortMapper.selectBySwitchId">
<result column="ptype" property="switchPortType"/><!-- property对应JavaBean中的属性名 -->
<result column="pnum" property="switchPortNum"/>
</collection> </collection>
</resultMap> </resultMap>
<!-- <sql id="selectTmplSwitchVo">-->
<!-- select switch_id, switch_brand, switch_type, power_num from tmpl_switch-->
<!-- </sql>-->
<sql id="selectTmplSwitchVo"> <sql id="selectTmplSwitchVo">
select select switch_id, switch_brand, switch_type, power_num from
s.switch_id, tmpl_switch
s.switch_brand, </sql>
s.switch_type,
s.power_num,
p.switch_port_id as pid,
p.switch_port_type as ptype,
p.switch_port_num as pnum
from
tmpl_switch s
left join
tmpl_switch_port p
on
s.switch_id = p.switch_id
</sql>
<select id="selectTmplSwitchList" parameterType="com.ruoyi.template.domain.TmplSwitch" resultMap="TmplSwitchResult"> <select id="selectTmplSwitchList"
parameterType="com.ruoyi.template.domain.TmplSwitch"
resultMap="TmplSwitchResult">
<include refid="selectTmplSwitchVo"/> <include refid="selectTmplSwitchVo"/>
<where> <where>
<if test="switchId != null ">and switch_id = #{switchId}</if> <if test="switchId != null ">and switch_id = #{switchId}</if>
@ -46,18 +32,16 @@
<if test="powerNum != null ">and power_num = #{powerNum}</if> <if test="powerNum != null ">and power_num = #{powerNum}</if>
</where> </where>
</select> </select>
<!-- <select id="selectTmplSwitchList_COUNT" resultType="Long">-->
<!-- select count(0) from tmpl_switch-->
<!-- </select>-->
<select id="selectTmplSwitchById" parameterType="Integer"
<select id="selectTmplSwitchById" parameterType="Integer" resultMap="TmplSwitchResult"> resultMap="TmplSwitchResult">
<include refid="selectTmplSwitchVo"/> <include refid="selectTmplSwitchVo"/>
where s.switch_id = #{switchId} where switch_id = #{switchId}
</select> </select>
<insert id="insertTmplSwitch" parameterType="com.ruoyi.template.domain.TmplSwitch" useGeneratedKeys="true" <insert id="insertTmplSwitch"
keyProperty="switchId"> parameterType="com.ruoyi.template.domain.TmplSwitch"
useGeneratedKeys="true" keyProperty="switchId">
insert into tmpl_switch insert into tmpl_switch
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="switchBrand != null and switchBrand != '' ">switch_brand,</if> <if test="switchBrand != null and switchBrand != '' ">switch_brand,</if>
@ -71,7 +55,8 @@
</trim> </trim>
</insert> </insert>
<update id="updateTmplSwitch" parameterType="com.ruoyi.template.domain.TmplSwitch"> <update id="updateTmplSwitch"
parameterType="com.ruoyi.template.domain.TmplSwitch">
update tmpl_switch update tmpl_switch
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="switchBrand != null and switchBrand != '' ">switch_brand = #{switchBrand},</if> <if test="switchBrand != null and switchBrand != '' ">switch_brand = #{switchBrand},</if>
@ -82,12 +67,14 @@
</update> </update>
<delete id="deleteTmplSwitchById" parameterType="Integer"> <delete id="deleteTmplSwitchById" parameterType="Integer">
delete from tmpl_switch where switch_id = #{switchId} delete from
</delete> tmpl_switch where switch_id = #{switchId}
</delete>
<delete id="deleteTmplSwitchByIds" parameterType="String"> <delete id="deleteTmplSwitchByIds" parameterType="String">
delete from tmpl_switch where switch_id in delete from tmpl_switch where switch_id in
<foreach item="switchId" collection="array" open="(" separator="," close=")"> <foreach item="switchId" collection="array" open="("
separator="," close=")">
#{switchId} #{switchId}
</foreach> </foreach>
</delete> </delete>

View File

@ -2,88 +2,113 @@
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.template.mapper.TmplSwitchPortMapper"> <mapper
namespace="com.ruoyi.template.mapper.TmplSwitchPortMapper">
<resultMap type="com.ruoyi.template.domain.TmplSwitchPort" id="TmplSwitchPortResult"> <resultMap type="com.ruoyi.template.domain.TmplSwitchPort"
<result property="switchPortId" column="switch_port_id"/> id="TmplSwitchPortResult">
<result property="switchId" column="switch_id"/> <result property="switchPortId" column="switch_port_id" />
<result property="switchPortType" column="switch_port_type"/> <result property="switchId" column="switch_id" />
<result property="switchPortNum" column="switch_port_num"/> <result property="switchPortType" column="switch_port_type" />
</resultMap> <result property="switchPortNum" column="switch_port_num" />
</resultMap>
<sql id="selectTmplSwitchPortVo"> <sql id="selectTmplSwitchPortVo">
select switch_port_id, switch_id, switch_port_type, switch_port_num from tmpl_switch_port select switch_port_id, switch_id, switch_port_type,
</sql> switch_port_num from
tmpl_switch_port
</sql>
<select id="selectTmplSwitchPortList" parameterType="com.ruoyi.template.domain.TmplSwitchPort" <select id="selectBySwitchId" parameterType="java.lang.Integer"
resultMap="TmplSwitchPortResult"> resultMap="TmplSwitchPortResult">
<include refid="selectTmplSwitchPortVo"/> <include refid="selectTmplSwitchPortVo" />
<where> where switch_id=#{switchId};
<if test="switchPortId != null ">and switch_port_id = #{switchPortId}</if> </select>
<if test="switchId != null ">and switch_id = #{switchId}</if>
<if test="switchPortType != null ">and switch_port_type = #{switchPortType}</if>
<if test="switchPortNum != null ">and switch_port_num = #{switchPortNum}</if>
</where>
</select>
<select id="selectTmplSwitchPortById" parameterType="Integer" resultMap="TmplSwitchPortResult"> <select id="selectTmplSwitchPortList"
<include refid="selectTmplSwitchPortVo"/> parameterType="com.ruoyi.template.domain.TmplSwitchPort"
where switch_port_id = #{switchPortId} resultMap="TmplSwitchPortResult">
</select> <include refid="selectTmplSwitchPortVo" />
<where>
<if test="switchPortId != null ">and switch_port_id = #{switchPortId}</if>
<if test="switchId != null ">and switch_id = #{switchId}</if>
<if test="switchPortType != null ">and switch_port_type = #{switchPortType}</if>
<if test="switchPortNum != null ">and switch_port_num = #{switchPortNum}</if>
</where>
</select>
<select id="selectBySwitchIdAndPortType" parameterType="Integer" resultMap="TmplSwitchPortResult"> <select id="selectTmplSwitchPortById" parameterType="Integer"
<include refid="selectTmplSwitchPortVo"/> resultMap="TmplSwitchPortResult">
where switch_id = #{switchPortId} <include refid="selectTmplSwitchPortVo" />
and switch_port_type = #{switchPortType} -- where switch_port_id = #{switchPortId}
</select> <where>
<if test="switchPortId != null ">and switch_port_id = #{switchPortId}</if>
<if test="switchId != null ">and switch_id = #{switchId}</if>
</where>
</select>
<select id="selectBySwitchIdAndPortType" parameterType="Integer"
resultMap="TmplSwitchPortResult">
<include refid="selectTmplSwitchPortVo" />
<if test="switchId != null ">and switch_id = #{switchId}</if>
<if test="switchPortType != null ">and switch_port_type = #{switchPortType}</if>
</select>
<insert id="insertTmplSwitchPort" parameterType="com.ruoyi.template.domain.TmplSwitchPort"> <insert id="insertTmplSwitchPort"
insert into tmpl_switch_port parameterType="com.ruoyi.template.domain.TmplSwitchPort">
<trim prefix="(" suffix=")" suffixOverrides=","> insert into tmpl_switch_port
<if test="switchPortId != null ">switch_port_id,</if> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="switchId != null ">switch_id,</if> <if test="switchPortId != null ">switch_port_id,</if>
<if test="switchPortType != null ">switch_port_type,</if> <if test="switchId != null ">switch_id,</if>
<if test="switchPortNum != null ">switch_port_num,</if> <if test="switchPortType != null ">switch_port_type,</if>
</trim> <if test="switchPortNum != null ">switch_port_num,</if>
<trim prefix="values (" suffix=")" suffixOverrides=","> </trim>
<if test="switchPortId != null ">#{switchPortId},</if> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="switchId != null ">#{switchId},</if> <if test="switchPortId != null ">#{switchPortId},</if>
<if test="switchPortType != null ">#{switchPortType},</if> <if test="switchId != null ">#{switchId},</if>
<if test="switchPortNum != null ">#{switchPortNum},</if> <if test="switchPortType != null ">#{switchPortType},</if>
</trim> <if test="switchPortNum != null ">#{switchPortNum},</if>
</insert> </trim>
</insert>
<insert id="batchTmplSwitchPort"> <insert id="batchTmplSwitchPort">
insert into tmpl_switch_port(switch_id, switch_port_type,switch_port_num) values insert into tmpl_switch_port(switch_id,
<foreach item="item" index="index" collection="list" separator=","> switch_port_type,switch_port_num) values
(#{item.switchId},#{item.switchPortType},#{item.switchPortNum}) <foreach item="item" index="index" collection="list"
</foreach> separator=",">
</insert> (#{item.switchId},#{item.switchPortType},#{item.switchPortNum})
</foreach>
</insert>
<update id="updateTmplSwitchPort" parameterType="com.ruoyi.template.domain.TmplSwitchPort"> <update id="updateTmplSwitchPort"
update tmpl_switch_port parameterType="com.ruoyi.template.domain.TmplSwitchPort">
<trim prefix="SET" suffixOverrides=","> update tmpl_switch_port
<if test="switchId != null ">switch_id = #{switchId},</if> <trim prefix="SET" suffixOverrides=",">
<if test="switchPortType != null ">switch_port_type = #{switchPortType},</if> <if test="switchId != null ">switch_id = #{switchId},</if>
<if test="switchPortNum != null ">switch_port_num = #{switchPortNum},</if> <if test="switchPortType != null ">switch_port_type = #{switchPortType},</if>
</trim> <if test="switchPortNum != null ">switch_port_num = #{switchPortNum},</if>
where switch_port_id = #{switchPortId} </trim>
</update> where switch_port_id = #{switchPortId}
</update>
<delete id="deleteTmplSwitchPortById" parameterType="Integer"> <delete id="deleteTmplSwitchPortById" parameterType="Integer">
delete from tmpl_switch_port where switch_port_id = #{switchPortId} delete from
</delete> tmpl_switch_port where switch_port_id = #{switchPortId}
</delete>
<delete id="deleteTmplSwitchPortBySwitchId" parameterType="Integer"> <delete id="deleteTmplSwitchPortBySwitchId"
delete from tmpl_switch_port where switch_id = #{switchId} parameterType="Integer">
</delete> delete from tmpl_switch_port where switch_id =
#{switchId}
</delete>
<delete id="deleteTmplSwitchPortByIds" parameterType="String"> <delete id="deleteTmplSwitchPortByIds" parameterType="String">
delete from tmpl_switch_port where switch_port_id in delete from tmpl_switch_port where switch_port_id in
<foreach item="switchPortId" collection="array" open="(" separator="," close=")"> <foreach item="switchPortId" collection="array" open="("
#{switchPortId} separator="," close=")">
</foreach> #{switchPortId}
</delete> </foreach>
</delete>
</mapper> </mapper>