zoukankan      html  css  js  c++  java
  • Jersey Client Post Bean参数

    代码:

        public static void main(String[] args) {
    
                Student st = new Student("Adriana", "Barrer", 12, 9);
                ClientConfig clientConfig = new DefaultClientConfig();
                clientConfig.getFeatures().put(
                        JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
                Client client = Client.create(clientConfig);
                WebResource webResource = client
                        .resource("http://localhost:8080/JerseyJSONExample/rest/jsonServices/send");
                ClientResponse response = webResource.accept("application/json")
                        .type("application/json").post(ClientResponse.class, st);
                if (response.getStatus() != 200) {
                    throw new RuntimeException("Failed : HTTP error code : "
                            + response.getStatus());
                }
                String output = response.getEntity(String.class);
                System.out.println("Server response .... 
    ");
                System.out.println(output);
        }

    资源中代码:

        @POST
        @Path("/send")
        @Consumes(MediaType.APPLICATION_JSON)
        public Response consumeJSON( Student student ) {
            System.out.println("student :"+student);
            System.out.println("student content:"+student.getFirstName());
            String output = student.toString();
    
            return Response.status(200).entity(output).build();
        }

    实体bean中必须要有默认的空构造器。

  • 相关阅读:
    《火影忍者:究级风暴》渲染技术究极解析!
    动态数组和内置数组转换范例
    固定视角
    旋转
    时间间隔操作
    编辑器的一些批处理脚本
    访问GUItexture
    血槽制作
    动画循环播放
    软件测试修炼之道之——重现问题(上)
  • 原文地址:https://www.cnblogs.com/juepei/p/4026981.html
Copyright © 2011-2022 走看看