简体   繁体   English

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

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

can anyone help me how can I wrap multiple strings into a single string in postman and call spring boot rest API.任何人都可以帮助我如何在邮递员中将多个字符串包装成一个字符串并调用 spring boot rest API。

from postman I am calling my rest API via GET request从邮递员那里我通过 GET 请求调用我的 rest API

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

here inside searchRequest I would like to wrap "userId","userGroup" and "status" with values to call my spring boot rest API Get request.在searchRequest中,我想用值包装“userId”、“userGroup”和“status”以调用我的spring boot rest API Get请求。 and in my service class I am trying to covert this string to DTO but it is not converting, here is my code in the controller, service layer, util class在我的服务类中,我试图将此字符串转换为 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;

    }

i tried multiple ways but could not succeed, any suggestions would be really appreciated.我尝试了多种方法但无法成功,任何建议将不胜感激。

I would suggest to pass all the parameters as RequestParam and them bind them to object directly我建议将所有参数作为RequestParam传递,并将它们直接绑定到对象

Request :要求 :

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

POJO : POJO :

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

    private String userId;

    private String userGroup;

    private String status;

}

Controller :控制器 :

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

            //some code
        }

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

相关问题 Spring-boot rest api当前请求不是邮递员的多部分请求 - Spring-boot rest api current request is not multipart request with postman 如何解决通过 Z03D476861AFD3854510 测试 spring 引导 rest api 时遇到的错误? - How can I solve the error I get while testing the spring boot rest api via postman? 如何在rest控制器spring boot中为邮递员生成api-key - how to generate api-key for postman in rest controller spring boot Spring Boot:发布到REST API会将单个字符串存储为数组 - Spring Boot: Posting to a REST API is storing a single string as an array Spring Boot Rest Web Service 在获取请求中获取多个参数 - Spring Boot Rest Web Service fetching multiple parameters in Get Request ControllerAdvice 的异常处理程序在使用 Spring Boot 的 Rest API 获取请求中不起作用。 如何解决? - Exception Handler of ControllerAdvice Not working in Rest API Get Request using Spring Boot. How to resolve? 在 Spring Boot 中调用分页的 REST 请求 - Call paginated REST request in spring boot 如何使用邮递员将用户登录详细信息传递给Spring Boot Rest API - How to pass user login details to Spring Boot Rest API using postman 如何使用Spring Boot / Spring Security包装对OAuth2承载令牌请求的调用? - How to use Spring Boot/Spring Security to wrap a call to an OAuth2 bearer token request? 对 API 的 Spring Boot GET 请求 - Spring Boot GET request to API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM