[英]Spring-boot rest api current request is not multipart request with postman
[英]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.