SpringMVC 6.1.0的的查询字符串querystring似乎无法自动接收,但6.0.6可以.
controller代码如下
@Controller
@RequestMapping("/param")
public class ParamController {
@GetMapping("/simple")
@ResponseBody
String simpleData(String name,int age){
System.out.println("name = " + name + ", age = " + age);
return name+age;
}
}
相关依赖如下
java17
tomcat 10
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>6.0.6</spring.version>
<lombok>1.18.30</lombok>
<servlet.api>9.1.0</servlet.api>
</properties>
<dependencyManagement>
<dependencies>
<!--mvc框架-->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!--测试框架-->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version>${servlet.api}</version>
<scope>provided</scope>
</dependency>
</dependencies>
spring mvc 现在必须指定@RequestParm了么
Comment From: bclozel
Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.
Also, see https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#parameter-name-retention
Comment From: cs-xiyan
可是6.0.6及以前不需要显式添加@RequestParam就可以使用,是否意味着以后版本都必须加了。官方对此改动是否有具体说明呢
Comment From: bclozel
Please take the time to read the link to the documentation section I've provided above.
Comment From: cs-xiyan
我懂了,由于LocalVariableTableParameterNameDiscoverer已在 6.1 中删除。因此,Spring 框架和 Spring 组合框架中的代码不再尝试通过解析字节码来推断参数名称。所以说现在以后版本中,必须指定@RequestParam了。
Comment From: bclozel
That is not what the documentation says. You don't need to add @RequestParam
, but rather compile your code with the -parameters
flag. If you need more help, please ask questions on StackOverflow.
Comment From: cs-xiyan
可是那样不就意味着我的代码变成了java8,是否会与其他依赖相互冲突呢。或者使用了java17新特性,导致无法变异代码。所以我觉得倒不如强制加上@RequestParam