jersey的psot请求

@Consumes 注释代表的是一个资源可以接受的 MIME 类型。

@Produces 注释代表的是一个资源可以返回的 MIME 类型。
这些注释均可在资源、资源方法、子资源方法、子资源定位器或子资源内找到

post请求接受方式:

第一种:

    @POST
    @Path("/create")
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)//接受类型
    @Produces(MediaType.APPLICATION_JSON) //返回形式
    @ApiOperation("新增")
    public ResultObject confirm(@ApiParam(value = "时间", required = true) @FormParam("settleMonth") String settleMonth,
            @ApiParam(value = "类型", required = true) @FormParam("dataType") String dataType,
            @ApiParam(value = "任务Id", required = true) @FormParam("taskId") String taskId,
            @ApiParam(value = "结果", required = true) @FormParam("auditResult") String auditResult,
            @ApiParam(value = "意见", required = true) @FormParam("auditProposal") String auditProposal)
 @Consumes(MediaType.APPLICATION_FORM_URLENCODED)和@FormParam相对应


第二种:

    @POST
    @Path("/create")
    @Produces(MediaType.APPLICATION_JSON) //返回形式
    @ApiOperation("新增")
    public ResultObject confirm(@ApiParam(value = "时间", required = true) @FormDataParam("settleMonth") String settleMonth,
            @ApiParam(value = "类型", required = true) @@FormDataParam("dataType") String dataType,
            @ApiParam(value = "任务Id", required = true) @FormDataParam("taskId") String taskId,
            @ApiParam(value = "结果", required = true) @FormDataParam("auditResult") String auditResult,
            @ApiParam(value = "意见", required = true) @FormDataParam("auditProposal") String auditProposal)

部分解释:

@Consumes与@Produces相反,用来指定可以接受client发送过来的MIME类型,同样可以用于class或者method,也可以指定多个MIME类型,一般用于@PUT,@POST

@Consumes(MediaType.TEXT_PLAIN)  b.接受clent参数为json类型@Consumes(MediaType.APPLICATION_JSON)


@PathParam :路劲参数

扫描二维码关注公众号,回复: 2785262 查看本文章
@GET
@Path("/user/{id}")
@Produces(MediaType.APPLICATION_JSON)
public ResultObject index(@ApiParam(value = "id值", required = true)
                              @PathParam("id") String id)

实现如下:www.localhost:8080/rest/user/11/


@QueryParam:路劲请求参数

@GET
@Path("/user")
@Produces(MediaType.APPLICATION_JSON)
public ResultObject index(@ApiParam(value = "id值", required = true)
                              @QueryParam("id") String id)

实现如下:www.localhost:8080/rest/user?id=11


如果需要为参数设置默认值,可以使用@DefaultValue

@ApiParam(value = "排序顺序") @DefaultValue("asc")  @QueryParam("indexOrder") String indexOrder,

    @GET
    @Path("/index")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation("列表查询")
    public ResultObject index(@ApiParam(value = "当前页(分页时必须)", required = true)
                              @QueryParam("currentPage") Integer currentPage,
                              @ApiParam(value = "每页条数(分页时必须)", required = true)
                              @QueryParam("numberPerPage") Integer numberPerPage,
                              @ApiParam(value = "排序顺序") @DefaultValue("asc")
                              @QueryParam("indexOrder") String indexOrder,
                              @ApiParam(value = "排序关键字") @DefaultValue("day_id")
                              @QueryParam("indexOrderKey") String indexOrderKey,
                              @ApiParam(value = "开始时间") @QueryParam("startDay") String startDay,
                              @ApiParam(value = "结束时间")
                              @QueryParam("endDay") String endDay){







猜你喜欢

转载自blog.csdn.net/u010931123/article/details/81035515