RESTEasy数据自动装配
环境:
JDK1.6
resteasy-jaxrs-2.3.4.Final
1,通过路径变量获取参数值。Webservice里方法如下:
@GET //books/ayb/123/cBookNmae-BookTitlec @Path("books/a{param}b/{id}/c{name}-{title}c") @Produces(MediaType.APPLICATION_JSON) public String getBooksBadger99(@PathParam("id") String id, @PathParam("param") String param,@PathParam("name") String name,@PathParam("title") String title) { return id+ "--"+param+"--"+name+"--"+title; }
在浏览器中输入:
http://localhost:8080/resteasy-json/resteasy/library/books/ayb/123/cBookNmae-BookTitlec
返回结果:
123--y--BookNmae--BookTitle
------jerval
2,通过路径正则表达式获取。Webservice里方法如下:@GET //books/aaabb/test/dsd/stuff //books/aaabb/test/stuff //books/aaabb/stuff @Path("books/aaa{param:b+}/{many:.*}/stuff") @Produces(MediaType.APPLICATION_JSON) public String getBooksBadger90(@PathParam("param") String bs, @PathParam("many") String many) { return bs+ "--"+many; }在浏览器中输入:
http://localhost:8080/resteasy-json/resteasy/library/books/aaabb/test/dsd/stuff http://localhost:8080/resteasy-json/resteasy/library/books/aaabb/test/stuff http://localhost:8080/resteasy-json/resteasy/library/books/aaabb/stuff返回结果:
bb--test/dsd bb--test 报错要想第三个case也能工作,只能将URL变成:
http://localhost:8080/resteasy-json/resteasy/library/books/aaabb//stuff----jerval