繁体   English   中英

如何在邮递员中将多个字符串包装成单个字符串以调用spring boot rest API Get请求

[英]How to wrap multiple strings into single string in postman to call spring boot rest API Get request

任何人都可以帮助我如何在邮递员中将多个字符串包装成一个字符串并调用 spring boot rest API。

从邮递员那里我通过 GET 请求调用我的 rest API

localhost:8084/restapi/v1?searchRequest= {"userId":"value1","userGroup":"value2","staus":"value2"}

在searchRequest中,我想用值包装“userId”、“userGroup”和“status”以调用我的spring boot rest API Get请求。 在我的服务类中,我试图将此字符串转换为 DTO 但它没有转换,这是我在控制器、服务层、util 类中的代码

    Controller:


    @Autowired
        private UserUtility userUtility;

        @GetMapping(path = "/restapi/v1", consumes = "text/plain")
            public UserInfoDetails searchUserDetails(@RequestParam String searchRequest) {

                UserInfoDetails userInfoDetails = new UserInfoDetails();
                try {
                    userUtility.searchUserDetails(searchRequest);
                } catch (Exception e) {
                    e.printStackTrace();

                }
                return userInfoDetails;
            }

    Util class

@Autowired

    private ModelMapper mapper;

    public UserInfoDetails searchUserDetails(String searchRequest) {

        UserInfoDetails userInfoDetails = new UserInfoDetails ();

        try {
        SearchRequest    SearchRequest =mapper.map(searchRequest, SearchRequest.class);
            //some business logic and assign the details to     userInfoDetails 

        } catch (Exception e) {
            e.printStackTrace();
        }

        return userInfoDetails ;

    }

    Search Request class

    @Getter
    @Setter
    @NoArgsConstructor
    @ToString
    public class SearchRequest {

        private String userId;

        private String userGroup;

        private String status;

    }

我尝试了多种方法但无法成功,任何建议将不胜感激。

我建议将所有参数作为RequestParam传递,并将它们直接绑定到对象

要求 :

localhost:8084/restapi/v1?userId=value1,userGroup=value2,staus=value3

POJO :

@Getter
@Setter
@NoArgsConstructor
@ToString
public class SearchRequest {

    private String userId;

    private String userGroup;

    private String status;

}

控制器 :

@GetMapping(path = "/restapi/v1", consumes = "text/plain")
        public UserInfoDetails searchUserDetails(SearchRequest searchRequest){

            //some code
        }

暂无
暂无

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

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