问题
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 {
......
}
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.
Thanks
回答1:
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(...) {
...
}
}
来源:https://stackoverflow.com/questions/21980244/using-single-jersey-rest-class-for-multiple-path