前端js

var id = ["123","456"];
var params = {
    ids: id
};

$.ajax({
    type: "POST",
    dataType: "json",
    url: "/client/select",
    data: params,
    success: function (msg) {
        console.log(msg)
    }
});

后端controller

    @PostMapping("/editids")
    @ResponseBody
    public List<SysFileInfo> editByProjectlistId(@RequestParam(value="ids") List<String> ids)
    {
        List<SysFileInfo> sysFileInfo = sysFileInfoService.selectSysFileInfoByProjectlistIds(ids);
        return sysFileInfo;
    }

@RequestParam 中value值需要与前端参数名一致

后端mapper.xml

    <select id="selectSysFileInfoByProjectlistIds"  parameterType="list" resultMap="SysFileInfoResult">
        <include refid="selectSysFileInfoVo"/>
        where fkprojectlist_id in 
        <foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

foreach 中collection为前端返回的集合,item为遍历集合后的名称,index为索引

后端mapper

    public List<SysFileInfo> selectSysFileInfoByProjectlistIds(@Param("ids") List<String> ids);

如果出现Parameter 'xxxList' not found. Available parameters are [Collection,list]问题,在mapper中加上@Param

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐