对多个PATH使用Single Jersey REST类 [英] Using Single Jersey REST class for multiple PATH

查看:133
本文介绍了对多个PATH使用Single Jersey REST类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用JAX-RS开发REST服务.使用Jersey非常简单,但是使用Spring MVC和Jersey REST类遇到的一个区别是,Spring支持必须忽略Root Path元素,并在方法级别具有单独的路径映射.因此,如果有上载/下载功能,我可能不想让2个类一个上载,另一个有下载类,Jersey要求我现在这样做,因为这样的类级别可能只有1个根路径:

I have started developing REST services using JAX-RS. Using Jersey is pretty straightforward however one difference which I come across using Spring MVC and Jersey REST classes is, Spring supports having to ignore the Root Path element and have individual path mappings at Method Level. So if there is a Upload / Download Functionality, I may not want to have 2 classes one with upload and one with download which Jersey asks me to do now because there could be only 1 Root Path at class level like this:

@Path("/uploads")
public class FileDownloadController {
......
}

如果我忽略了根级别@Path,即在类级别,启动服务器时,Jersey无法识别我的类.这是我要实现的目标:

If I ignore the root level @Path i.e at the class level, Jersey while starting up the server doesn't recognize my class. Here is what I want to achieve:

public class FileProcessController {

   @Path("/uploads")
   public Response uploadFile(...) {
       ......
   }

   @Path("/downloads")
   public Response downloadFile(...) {
      ......
   }
}

任何线索都会受到赞赏.

Any clues will be appreciated.

谢谢

推荐答案

不确定我是否正确理解了这个问题,但是以下内容将在泽西根"中创建两个端点,分别为/uploads/downloads.您将能够在根目录中指定其他方法.所有这些都在同一个类中.

Not sure if I understand the question correctly, but the following will create two endpoints in the 'Jersey root' as /uploads and /downloads. You will be able to specify other methods in the root; all of this in the same class.

@Path("/")  
public class FileProcessController {

   @Path("uploads")
   public Response uploadFile(...) {
       ...
   }

   @Path("downloads")
   public Response downloadFile(...) {
      ...
   }

}

这篇关于对多个PATH使用Single Jersey REST类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆