Java 如何在postman中将多个字符串包装为单个字符串以调用spring boot rest API Get请求
有谁能帮助我如何在postman中将多个字符串包装成一个字符串并调用spring boot rest API 从postman我通过GET请求调用我的RESTAPIJava 如何在postman中将多个字符串包装为单个字符串以调用spring boot rest API Get请求,java,spring-boot,postman,Java,Spring Boot,Postman,有谁能帮助我如何在postman中将多个字符串包装成一个字符串并调用spring boot rest API 从postman我通过GET请求调用我的RESTAPI localhost:8084/restapi/v1?searchRequest= {"userId":"value1","userGroup":"value2","staus":"value2"} 在searchRequest中,我想用值包装“userId”、“userGroup”和“status”,以调用我的spring boo
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
@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
}
POJO:
localhost:8084/restapi/v1?userId=value1,userGroup=value2,staus=value3
@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
}
控制器:
localhost:8084/restapi/v1?userId=value1,userGroup=value2,staus=value3
@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
}
你能告诉我你的SearchRequest类还可以添加控制器代码和完整的服务,以便更好地理解代码吗?我认为您还应该更改api名称否,先生,我的期望是,如果请求参数增加,那么在url中追加看起来不太好