Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java - spring mvc @RequestMapping produces multiple formats

I'm working on a java spring mvc application. I have a method in my controller that responsible for producing image:

 @RequestMapping(value = "/view", method = RequestMethod.GET, produces = "image/jpg")
public void viewImage(HttpServletResponse response, HttpServletRequest request) throws Exception

This works fine. But I have a problem now. The produced images may have 3 formats jpg, jpeg and png. Therefore I need several produces attribute in the @RequestMapping. Is there any way to do this? For example, something like this: produces = "image/jpg, image/jpeg, image/png"

like image 656
hamed Avatar asked Dec 04 '22 02:12

hamed


1 Answers

You can have multiple mime types in produces, something like

produces={"image/jpg, image/jpeg, image/png"}

Now in order for the framework to know to which mimeType to resolve, you need to either add a Path or Parameter, or Accept header to the request (the so called PPA strategy). Read more at content negotiation

like image 90
Master Slave Avatar answered Dec 06 '22 19:12

Master Slave