sending List/Map as POST parameter jersey

前端 未结 3 1927
情歌与酒
情歌与酒 2020-12-02 19:20

I want to send a HashMap object to a ReST resource as a POST variable. I used the Form class to send the object. The client code:

public static         


        
3条回答
  •  甜味超标
    2020-12-02 19:55

    send Map as POST request body

    @POST
    @Produces("application/json")
    @Consumes("application/json")
    @Path("/sendUser")
    public Response sendUser(Map usersMap) {
        String name = usersMap.get("Name");
        // first check for existing key
        String family = usersMap.get("Family");
        String phone = usersMap.get("Phone");
        String mobile = usersMap.get("Mobile");
        return Response.ok("Get user attributes successfully !").build();
    }
    

    get map response from POST

    @POST
    @Produces("application/json")
    @Consumes("application/json")
    @Path("/getUser")
    public Response getUser(String searchInputJsonString) {
        Map usersMap = new HashMap<>();
        usersMap.put("Name","Johm");
        usersMap.put("Family","W.R.Klein");
        usersMap.put("Phone","87540255");
        usersMap.put("Mobile", "112458033");
        return Response.ok(usersMap).build();
    }
    

提交回复
热议问题