除暖

spring boot +swagger+mssql +lombok+mybatis的List<Dto> 参数

电脑版发表于:2021/11/3 16:51

一、参数为list实体model时(注意list参数一定要用对应的类型接收传回的参数,不然会报错)

接口效果

注意list参数默认是必填,想不填必须在@RequestParam等接收参数里改

二、list参数在mapper.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">
<!--这个是接口路径集dao层-->
<mapper namespace="com.example.My10_18.mapper.IForms_UserInfoMapper">
    <!--    添加-->
    <insert id="addF_User">
        insert Forms_UserInfo values
        <foreach collection="listInput" item="item" separator=",">
            (#{item.forms_id},#{item.userinfo_id})
        </foreach>
    </insert>
    <!--删除-->
    <delete id="delF_User">
        delete Forms_UserInfo
        <where>
            <if test="forms_ids!=null and forms_ids.size()>0">
                and
                <foreach collection="forms_ids" item="item" separator="or">forms_id=#{item}</foreach>
            </if>
            <if test="userinfo_ids!=null and userinfo_ids.size()>0">
                and <foreach collection="userinfo_ids" item="item" separator="or">userinfo_id=#{item}</foreach>
            </if>
        </where>
    </delete>

    <!--    修改-->
    <update id="updateF_UserByForms_id">
        <!--    update Forms_UserInfo set userinfo_id=1 where userinfo_id=2-->
        update Forms_UserInfo set userinfo_id=#{NForms_ids} where userinfo_id=#{OForms_ids}
    </update>
    <select id="queryFormsByAll" resultType="Forms_UserInfo">
        <!--         select* from Forms_UserInfo where  forms_id=1 and userinfo_id in(1,2)-->
        select* from Forms_UserInfo
        <where>
            <if test="forms_ids!=null and forms_ids.size()>0">
                and
                <foreach collection="forms_ids" item="item" separator="or">forms_id=#{item}</foreach>
            </if>
            <if test="userinfo_ids!=null and userinfo_ids.size()>0">and userinfo_id in
                <foreach collection="userinfo_ids" item="item" open="(" separator="," close=")">#{item}</foreach>
            </if>
        </where>
    </select>
<!--分页查询-->
    <select id="queryFormsByPages" resultType="Forms_UserInfo">
        <!--         select* from Forms_UserInfo where  forms_id=1 and userinfo_id in(1,2)-->
        select top ${row}* from Forms_UserInfo
        <where>
            <if test="forms_ids!=null and forms_ids.size()>0">
                and
                <foreach collection="forms_ids" item="item" separator="or">forms_id=#{item}</foreach>
            </if>
            <if test="userinfo_ids!=null and userinfo_ids.size()>0">and userinfo_id in
                <foreach collection="userinfo_ids" item="item" open="(" separator="," close=")">#{item}</foreach>
            </if>
            and Id not in(select top(2*(#{page}-1))Id from Forms_UserInfo order by Id)
        </where>
    </select>

</mapper>


关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢