zoukankan      html  css  js  c++  java
  • jersey实现RESTful接口PUT方法JSON数据传递

    • 项目中使用的是org.json包
    • maven中的配置如下:
      •   <!-- https://mvnrepository.com/artifact/org.json/json -->
              <dependency>
                  <groupId>org.json</groupId>
                  <artifactId>json</artifactId>
                  <version>20180130</version>
              </dependency>
              ```
        
    • resource class
      •   @PUT
          @Path("/put")
          @Produces("text/plain;charset=UTF-8")
          @Consumes(MediaType.APPLICATION_JSON)
          public String putTest(String userStr){
              JSONObject jsonObject=new JSONObject(userStr);
              System.out.println(jsonObject.toString());
              User user=new User(jsonObject.getString("username"),jsonObject.getString("password"));
              System.out.println(user.toString());
              return "that's ok.";
          }
        
    • testing
      • output:
      •   Jersey app started with WADL available at http://localhost:8080/myapp/application.wadl
          四月 18, 2018 10:49:18 下午 org.glassfish.grizzly.http.server.NetworkListener start
          信息: Started listener bound to [localhost:8080]
          Hit enter to stop it...
          四月 18, 2018 10:49:18 下午 org.glassfish.grizzly.http.server.HttpServer start
          信息: [HttpServer] Started.
          {"password":"123456","username":"tt"}
          User{username='tt', password='123456'}
        
  • 相关阅读:
    Django model 字段类型及选项解析(二)
    MYSQL数据库设计规范与原则
    爬虫相关模块命令回顾
    Django model 字段类型及选项解析(一)
    Django自身安全机制-XSS和CSRF
    分页
    css样式大全
    HTML标签和属性大全
    IsPost 判断
    HTML中夹杂CODE
  • 原文地址:https://www.cnblogs.com/Black-Cobra/p/8878216.html
Copyright © 2011-2022 走看看