服务器报500错误 No primary or single unique constructor found for interface java.util.List
创始人
2025-01-18 19:32:03
0

 批量删除日志记录 前端请求

URL:http://localhost:8080/system/log?ids=3,4,5

Method:DELETE

//批量删除日志记录     deleteLogs() {       let url = '/system/log'       if (this.currentRow == null && this.multipleSelection.length == 0) {         this.$message.warning("请先选择记录")         return;       } else if (this.multipleSelection.length > 0) {         url += '?ids=' + this.multipleSelection;       } else if (this.currentRow && this.multipleSelection.length == 0) {         url += '?ids=' + this.currentRow.id;       }       this.$confirm('此操作将永久删除该记录,是否继续?', '提示', {type: "warning"}).then(() => {         this.deleteRequest(url).then(resp => {           if (resp) {             this.getLogs();           }         });       }).catch(() => {         this.$message.info('已取消当前操作~')       });     }

后端接口:

 /**      * 根据id删除日志记录      * @param ids      * @return      */     @DeleteMapping     public Result deleteLogsByIds(List ids){         boolean flag = operatorLogService.removeByIds(ids);         if (flag){             return Result.success("删除成功");         }         return Result.error("删除失败");     }

报错:java.lang.IllegalStateException: No primary or single unique constructor found for interface java.util.List

解决方法:添加@RequestParam注解

 @DeleteMapping     public Result deleteLogsByIds(@RequestParam List ids){         boolean flag = operatorLogService.removeByIds(ids);         if (flag){             return Result.success("删除成功");         }         return Result.error("删除失败");     }

原因分析: 由于 Spring Boot 默认情况下会尝试使用请求参数的值来创建方法参数,但对于接口类型(如 java.util.List)而言,它无法直接创建一个接口的实例。

通过使用 @RequestParam 注解,明确指定了请求参数的名称,并将请求参数的值绑定到方法参数上,从而避免了这个错误。@RequestParam 注解告诉 Spring Boot 去查找请求参数的值,并将值映射到方法参数上,而不会尝试创建一个接口的实例。

所以,如果你的方法参数是一个具体的类类型(如 List),那么 Spring Boot 可以通过请求参数的值来创建一个具体的类的实例。但是对于接口类型,它无法这样做,因此需要使用 @RequestParam 注解来明确指定参数的名称和类型,以避免错误。总之,为了避免这个错误,当你的方法参数类型是接口类型时,使用 @RequestParam 注解是一个好的做法,它可以确保参数的正确绑定和映射。

相关内容

热门资讯

推荐一款"aa po... 推荐一款"aa poker有外挂吗"aapoker辅助工具ai(都是真的是有挂)-哔哩哔哩1、金币登...
wepoke真的有挂!we辅助... 1、wepoke真的有挂!we辅助poker,(WepoKe)确实真的有挂,黑科技透明挂(有挂教程)...
wepokeai代打!wepo... wepokeai代打!wepoke辅助机器人(WePoKe黑科技)一贯真的有挂(有挂教程)-哔哩哔哩...
黑科技玄学(wepoke黑科技... 黑科技玄学(wepoke黑科技)wepoke ai代打辅助(wepOke)总是真的是有挂(有挂透视)...
wpK最新黑科技!wpk俱乐部... wpK最新黑科技!wpk俱乐部有ai吗(WPK ai辅助)切实是真的有挂(2025已更新)(哔哩哔哩...
wepoke辅助插件!wepo... wepoke辅助插件!wepoker真的有挂,(wEPoke)总是真的有挂,黑科技最新款(存在有挂)...
盘点一款"aapok... 盘点一款"aapoker发牌机制"aapoker透明挂辅助器(确实真的有挂)-哔哩哔哩1、首先打开a...
wepokeai代打!wepo... wepokeai代打!wepokeai代打(WePoKe黑科技)果然真的是有挂(真的有挂)-哔哩哔哩...
wpk到底是有外挂!wpk智能... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在这款游戏中打牌都...
黑科技规律(wepoke透明黑... 黑科技规律(wepoke透明黑科技)wepower外挂检测方法(we-poker)果然是真的有挂(有...