小编web*_*rer的帖子

将JSON传递给WebService

我使用dropwizard框架在java中开发了一个web服务.我希望它消耗一个json.

我的服务代码是 -

- 资源等级

@Path(value = "/product")
  public class ProductResource{ 

   @POST
   @Path(value = "/getProduct")
   @Consumes(MediaType.APPLICATION_JSON)
   @Produces(MediaType.APPLICATION_JSON)
   public Product getProduct(InputBean bean) {
    // Just trying to print the parameters. 
    System.out.println(bean.getProductId());
    return new Product(1, "Product1-UpdatedValue", 1, 1, 1);
   }
} 
Run Code Online (Sandbox Code Playgroud)

- InputBean是一个简单的bean类.

public class InputBean {

    private int productId;
    private String productName;

    public String getProductName() {
        return productName;
    }
    public void setProductName(String productName) {
        this.productName= productName;
    }

    public int getProductId() {
        return productId;
    }
    public void setProductId(int productId) {
        this.productId= productId; …
Run Code Online (Sandbox Code Playgroud)

java json web-services dropwizard

7
推荐指数
1
解决办法
638
查看次数

读取yaml文件时出现UnrecognizedPropertyException

在使用dropwizard时,

我的dropwizard服务读取config.yml文件.

public void run() throws Exception {
    this.run(new String[] { "server", "src/main/resources/config.yml" });
}
Run Code Online (Sandbox Code Playgroud)

Config.yml文件:

database:
  # the name of your JDBC driver
  driverClass: com.mysql.jdbc.Driver

  # the username
  user: user2connect

  # the password
  password: password2connect

  # the JDBC URL
  url: jdbc:mysql://url.to.connect:port
Run Code Online (Sandbox Code Playgroud)

但是,一旦读取文件,我就会收到错误 -

Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "database" (class com.service.config.DropWizardConfiguration), not marked as ignorable (4 known properties: , "http", "httpConfiguration", "logging", "loggingConfiguration"])
 at [Source: N/A; line: -1, column: -1] (through reference chain: com.service.config.DropWizardConfiguration["database"])
Run Code Online (Sandbox Code Playgroud)

经过几个主题后,我意识到这可能是因为杰克逊无法忽视一些属性.

我尝试了几件事 - …

java yaml web-services dropwizard

4
推荐指数
1
解决办法
4456
查看次数

JAVA中如何从字符串中获取时区

我有一个输入“+04:00”

我可以使用什么 API 来获取时区?


到目前为止,1)我研究了joda - https://www.joda.org/joda-time/apidocs/org/joda/time/DateTimeZone.html

   static DateTimeZone forOffsetHoursMinutes(int hoursOffset, int minutesOffset) 
Run Code Online (Sandbox Code Playgroud)

不确定这是否理想。

2)我检查了时区类。

http://docs.oracle.com/javase/6/docs/api/java/util/TimeZone.html#getTimeZone%28java.lang.String%29

 getTimeZone

public static TimeZone getTimeZone(String ID)

    Gets the TimeZone for the given ID.

    Parameters:
        ID - the ID for a TimeZone, either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00". Note that the support of abbreviations is for JDK 1.1.x compatibility only and full names should be used. 
    Returns:
        the specified TimeZone, or the …
Run Code Online (Sandbox Code Playgroud)

java timezone jodatime

4
推荐指数
1
解决办法
1万
查看次数

如何以JSON格式从Sonatype Nexus REST API获取结果

我正在使用Sonatype Nexus REST核心API来获取存储库.

输出格式是XML.如何以JSON格式获取输出?

我可以在文档中看到返回类型可以application/json.但我完全处于空白处.

api rest json nexus

3
推荐指数
1
解决办法
4129
查看次数

在javascript代码中读取jstl变量.

我想在javascript函数中读取一个jstl变量.

JS代码提交表单.

$("#userSubmit").on('submit', function () {
    document.getElementById("userForm").submit();
});
Run Code Online (Sandbox Code Playgroud)

所以在服务器代码中 -

request.setAttribute("userId", 435);
Run Code Online (Sandbox Code Playgroud)

并在页面加载后 - >在javascript代码中 -

$("#textBoxInp").keyup(function() {
    // I want to access the userId here. 
    // in html code i can acccess it using JSTL syntax ${userId}
});
Run Code Online (Sandbox Code Playgroud)

javascript java jquery jstl

2
推荐指数
2
解决办法
2万
查看次数

在textBox1中键入文本时更新textBox2文本

我有2个文本框(如货币转换器)

我想在我键入textbox1时更新textbox2,我应该使用哪个jquery函数?

CREDIT: <input type="text" id="credit"/>

USD: <input type="text" id="usd"/>
Run Code Online (Sandbox Code Playgroud)

jQuery的:

    $("#credit").change(function () {
           $("#usd").val((parseInt($("#credit").val(), 10) * 2));
    });
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/9ysC3/

现在,usd val更新失去焦点.

在输入信用文本框时,我可以使用什么功能更新USD val?

javascript jquery

1
推荐指数
1
解决办法
73
查看次数

标签 统计

java ×4

dropwizard ×2

javascript ×2

jquery ×2

json ×2

web-services ×2

api ×1

jodatime ×1

jstl ×1

nexus ×1

rest ×1

timezone ×1

yaml ×1