繁体   English   中英

Spring Boot:是否可以将@RequestParam 作为 json 使用?

[英]Spring Boot: Is it possible to consume @RequestParam's as json?

我在 Spring Boot 应用程序中有以下休息端点:

    @RequestMapping(method = RequestMethod.POST, value = "/sign-in")
    public Client signIn(@RequestParam String username, @RequestParam String password, HttpServletRequest request) {
        Client client = authService.signIn(username, password);
        return client;
    }

我想接受数据作为应用程序/json。

是否可以在不为此创建类的情况下执行此操作?:

public class LoginModel {
   private String username;
   private String password;
   ...
}

此外,在signIn方法中没有 Map 类型的参数

我需要接受带有此签名的 application/json:

public Client signIn(@RequestParam String username, @RequestParam String password)

是否可以?

不,我认为这不可能。

您需要创建中间Login对象。

@RequestParam要求你有一个请求参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM