jersey中@QueryParam和@PathParam參數說明


參考sdujava2011的博客,網址:http://blog.csdn.NET/sdujava2011/article/details/40053623

 

 


@Path("/test")  
public class RestTest1 {  
  
    @GET  
    @Path("/getMessage") 
    @Produces({ MediaType.APPLICATION_JSON })  
    public HashMap getClientedMessage(@QueryParam("from") int from, @QueryParam("to") int to) {  
        HashMap<String, String> map = new HashMap<String, String>();  
        map.put("abc", "def");  
        map.put("abc1", ""+from);  
        map.put("abc2", ""+to);  
        return map;  
    }  

//請求方式為:    http://localhost:8080/resourceRest-1/api/test/getMessage?from=10&to=100

 

    @GET  
    @Path("{year}/{month}/{day}") 
    @Produces({ MediaType.APPLICATION_JSON })  
    public HashMap getClientedMessage2(@PathParam("year") int year,@PathParam("month") int month,   
            @PathParam("day") int day) { 
        HashMap<String, String> map = new HashMap<String, String>();  
        map.put("abc", "def");  
        map.put("abc1", ""+year);  
        map.put("abc2", ""+month);  
        map.put("abc3", ""+day);  
        return map;  
    }  

//請求方式為:http://localhost:8080/resourceRest-1/api/test/2011/11/12


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM