springboot前端向后端传递list
前端jsvar 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("/
·
前端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
更多推荐
已为社区贡献1条内容
所有评论(0)