Java - spring mvc @RequestMapping creates several formats

I am working on a java spring mvc application. I have a method in my controller that is responsible for creating the image:

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

It works great. But now I have a problem. The resulting images can have 3 formats jpg, jpeg and png. So I need some attributes producesin @RequestMapping. Is there any way to do this? For example, something like this:produces = "image/jpg, image/jpeg, image/png"

+4
source share
4 answers

produces , void. , . . :.

response.setContentType("image/jpeg");
+2

mime , -

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

, , mimeType , Path, Parameter, Accept ( PPA).

+2

Spring, :

produces = {MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_PNG_VALUE, MediaType.IMAGE_GIF_VALUE}
+1

. , produces . :

producess = {"image/jpg", "image/jpeg", "image/png"}
0

Source: https://habr.com/ru/post/1607048/


All Articles