使用REST Client传递GET Request for Spring REST中的对象列表

时间:2017-06-13 09:46:22

标签: java json get spring-restcontroller advanced-rest-client

我想传递对象列表,即具有userId和viewDateTime字段的用户对象。我们如何生成get URL以从REST客户端访问服务?

USER POJO:

public class User implements Serializable {

    private static final long serialVersionUID = 6407485814769754843L;

    private String userId;

    @JsonProperty(access = Access.READ_ONLY)
    private Date viewDateTime;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public Date getViewDateTime() {
        return viewDateTime;
    }

    public void setViewDateTime(Date viewDateTime) {
        this.viewDateTime = viewDateTime;
    }
}

REST控制器:

@RequestMapping(value = APIConstant.GET_ALL, method = RequestMethod.GET)
    public NotificationResponse getAll(@RequestParam("notificationType") NotificationType notificationType,
            AppCodeDTO appCode, @RequestParam(value = "clientDetails", required = false) ClientDetails clientDetails,
            UserListWrapper userlist, @RequestParam(value = "createdByUserId", required = false) String createdByUserId,
            @RequestParam(value = "eventDateTime", required = false) Date eventDateTime,
            PagableSortable pagableSortable) throws QHPlatformException {
        return null;
    }

包装类:

public class UserListWrapper {

    @JsonSerialize(converter=UserConverter.class)
    private List<User> users;

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

}

我们可以使用UserWrapper类传递它,还是可以在控制器中将List作为请求参数传递。请告诉我如何构建GET请求的URL。

由于

0 个答案:

没有答案