服务器报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 注解是一个好的做法,它可以确保参数的正确绑定和映射。

相关内容

热门资讯

透视能赢(WepoKe)外挂透... 1、透视能赢(WepoKe)外挂透明挂辅助app(wepoke真的有挂)素来存在有挂(详细透视技巧教...
aapoker发牌机制!aap... aapoker发牌机制!aapoker有外挂吗,(德州aapoker俱乐部)本来真的有挂(详细辅助技...
透视脚本(wepOke)透明挂... 这是一款非常优秀的wepoke的确有挂 ia辅助检测软件,能够让你了解到wepoke的确有挂中牌率当...
aa扑克辅助!德州aa扑克透明... aa扑克辅助!德州aa扑克透明挂,(aaPOKER)一直是真的有挂(详细辅助细节揭秘)1、首先打开a...
透视计算(wepOKE)透明挂... 透视计算(wepOKE)透明挂辅助代打(WePoKe外挂)切实真的是有挂(详细透视攻略教程);支持多...
aapoker外挂!aapok... aapoker外挂!aapoker外挂教程,(aApoker)总是是真的有挂(详细辅助细节揭秘)aa...
透视辅助(WepOke)外挂透... 《透视辅助(WepOke)外挂透明挂辅助软件(wepokeai辅助)切实是真的有挂(详细透视黑科技教...
aapoker辅助!aapok... aapoker辅助!aapoke辅助工具存在吗,(aa poker)好像有挂(详细辅助2025新版教...
透视数据(WEpoke)透视辅... 透视数据(WEpoke)透视辅助神器(wepokeai辅助)好像是有挂(详细透视分享教程);支持2-...
aapoker俱乐部!aa扑克... aapoker俱乐部!aa扑克有挂吗,(AApoker)都是真的有挂(详细辅助存在挂教程)1、玩家可...