简体   繁体   English

restFull Web服务方法

[英]restFull web service method

I want to pass like a parameter an Array to RESTful webservice with Jersey. 我想像泽西一样将参数作为数组传递给RESTful Web服务。 I have one mutiple select form where users can select multiple options. 我有一个多重选择表,用户可以在其中选择多个选项。 Then i pass the selected values using AJAX to the RESTful webservice. 然后,我使用AJAX将选定的值传递给RESTful Web服务。

That's the select: 选择的是:

<select id="u" multiple class="form-control">                       
 <option value="1">1</option>                   
 <option value="2">2</option>                   
 <option value="3">3</option>
</select>

The jquery js: jQuery JS:

$('#send').on('click', function() {
        $.ajax({
            url: "/pc/ws/ms/save-options",
            contentType: "application/x-www-form-urlencoded",
            cache: false,
            type: "POST",
            data: {
                ur: $('#u').val()
            }
        });
    });

I don't know how to indicate on the web service method receive is a array 我不知道如何在Web服务方法上指示接收到的是数组

If you are using Maven and Jersey we can maybe add this maven dependency which include Jackson lib : 如果您使用的是Maven和Jersey,则可以添加此maven依赖项,其中包括Jackson lib:

<properties>
    ...
    <dependency.jersey.version>1.18.1</dependency.jersey.version>
    ...
</properties>

+ +

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-json</artifactId>
    <version>${dependency.jersey.version}</version>
</dependency>

and a code similar to this one (not tested !) would maybe do the trick : 而与此类似的代码(未经测试!)也许可以解决问题:

@POST
@Path("/save-options")
@Consumes(MediaType.APPLICATION_JSON)
public Response getMyValues(Collection<Integer> values) {
    // Do whathever I want with my values
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM