LoginSignup
0
0

@RequestParamの省略記法が使えなくなった

Last updated at Posted at 2024-02-25
MainController.java
    ...
    @PostMapping(path="/add") // Map ONLY POST Requests
  public @ResponseBody String addNewUser (@RequestParam String name, @RequestParam String email) {
    // @ResponseBody means the returned String is the response, not a view name
    // @RequestParam means it is a parameter from the GET or POST request

    User n = new User();
    n.setName(name);
    n.setEmail(email);
    userRepository.save(n);
    return "Saved";
  }
  ...
  • 以下のエラーが発生
    Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.IllegalArgumentException: 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.] with root cause
  • RequestParamの変数名と対応する引数名が同じときはこの記法で大丈夫なはず、と思ったが、Spring Framework 6.1以降ではLocalVariableTableParameterNameDiscovererが使えなくなり、これに伴って省略記法も使えない(Spring Boot 3.2.3 はSpring Framework 6.1.4を使用)(参考)
  • https://github.com/spring-projects/spring-boot/issues/39095
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0