首页 > 基础资料 博客日记
Name for argument of type [java.lang.String] not ... Ensure that the compiler uses the ‘-parameters’
2024-04-17 16:00:05基础资料围观831次
前排提示,本文为引流文,文章内容不全,更多信息前往: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
@RequestParamis 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实现
下一篇:什么是观察者设计模式?
相关文章
最新发布
- 莱特摩比的一面之缘(前端经验)
- 洛谷-P10786 [NOI2024] 百万富翁 题解
- PyTorch KernelAgent 源码解读 ---(3)--- orchestrator
- OpenClaw.NET 外部 CLI 预设系统:从零编写第三方 CLI 集成指南
- Agent Harness 的 Session Tree View:让每一个 Agent 做自己擅长的事情!
- 二、OpenCloudOS Server 9 系统 安装 Nginx
- AI 开发狂飙!.NET 11 Preview 4 原生集成向量搜索 + MCP 模板,EF Core 直接对标 RAG 应用
- Vibe Coding有多强?我只花了一天,就搓出了这个银行开户行查询网站!
- 100条cmd命令大全
- C# ESP32/STM32 轻量 Web 能力库:PicoServer.Nano

