首页 > 基础资料 博客日记

Name for argument of type [java.lang.String] not ... Ensure that the compiler uses the ‘-parameters’

2024-04-17 16:00:05基础资料围观294

这篇文章介绍了Name for argument of type [java.lang.String] not ... Ensure that the compiler uses the ‘-parameters’,分享给大家做个参考,收藏Java资料网收获更多编程知识

前排提示,本文为引流文,文章内容不全,更多信息前往:oldmoon.top


简介

使用最新版的 Springboot 3.2.1 搭建开发环境进行开发,调用接口时出现奇怪的错。报错主要信息如下:

Name for argument of type [java.lang.String] not specified, and parameter name information not available via reflection. Ensure that the compiler uses the ‘-parameters’ flag.

官方说明中一直强调 @PathVariable 的使用,并没有提及 @RequestParam,阅读官方文档@RequestParam 会发现最后有一句话:

Note that use of @RequestParam is optional (for example, to set its attributes). By default, any argument that is a simple value type (as determined by BeanUtils#isSimpleProperty) and is not resolved by any other argument resolver, is treated as if it were annotated with @RequestParam.

翻译一下大概是:

注意,@RequestParam 的使用是可选的(例如,设置其属性)。 默认情况下,任何简单值类型(由 BeanUtils#isSimpleProperty 确定)且未由任何其他参数解析器解析的参数都将被视为使用 @RequestParam 注解。

根据原文及翻译,这自然让我认为,@RequestParam 依然是可以省略的。

然而奇怪的是,当 Springboot 3.2.1 使用Maven管理项目时,如果不使用 spring-boot-starter-parent 作为父工程,那么接口中必须显式声明 @RequestParam("name"),缺了其中的 name 也会报错。我清晰地记得我在旧版本的 Springboot 中经常省略 @RequestParam("name") 这种写法。

但如果不使用 spring-boot-starter-parent 作为父工程,好像 @RequestParam 变成了不可省略注解。大家搭建微服务和多模块时候,通常不会使用spring-boot-starter-parent作为父工程吧?还是只有我不用?。。。


更多信息: https://oldmoon.top/post/191


文章来源:https://blog.csdn.net/hu18315778112/article/details/135714006
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:jacktools123@163.com进行投诉反馈,一经查实,立即删除!

标签:

相关文章

本站推荐

标签云