[英]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.