首页 > 基础资料 博客日记
Name for argument of type [java.lang.String] not ... Ensure that the compiler uses the ‘-parameters’
2024-04-17 16:00:05基础资料围观294次
前排提示,本文为引流文,文章内容不全,更多信息前往: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
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:jacktools123@163.com进行投诉反馈,一经查实,立即删除!
标签:
上一篇:KMP算法 Java实现
下一篇:什么是观察者设计模式?
相关文章
最新发布
- java.lang.reflect.InaccessibleObjectException: Unable to make final void java.lang.Throwable.setCaus
- Java毕业设计:基于Java在线中药网上销售商城系统毕业设计源代码作品和开题报告
- html2canvas + jspdf 纯前端HTML导出PDF的实现与问题
- SpringBoot+Docker +Nginx 部署前后端项目
- 前几天顺手改的一个安卓启动器,已经获得40多颗星了
- 建行支付对接(H5)
- Java毕业设计:Java杭州城市文化展示系统毕业设计源代码作品和开题报告
- Java中的位图和布隆过滤器(如果想知道Java中有关位图和布隆过滤器的知识点,那么只看这一篇就足够了!)
- 少小白学前端——leaflet篇(Javascript 地图库)
- IDEA更改远程git仓库地址