JAVA-2113: Split or move spring-resttemplate module (#9753)

* JAVA-2113: Move Proxies With RestTemplate to spring-resttemplate-2

* JAVA-2113: Move A Custom Media Type for a Spring REST API to spring-resttemplate-2

* JAVA-2113: Move RestTemplate Post Request with JSON to spring-resttemplate-2

* JAVA-2113: Move Download an Image or a File with Spring MVC to spring-boot-mvc-3

* JAVA-2113: Fix the test
This commit is contained in:
kwoyke
2020-07-28 06:01:54 +02:00
committed by GitHub
parent 16df3b088a
commit be7545e1dc
22 changed files with 44 additions and 8 deletions

View File

@@ -5,4 +5,5 @@ This module contains articles about Spring Web MVC in Spring Boot projects.
### Relevant Articles:
- [Circular View Path Error](https://www.baeldung.com/spring-circular-view-path-error)
- [Download an Image or a File with Spring MVC](https://www.baeldung.com/spring-controller-return-image-file)
- More articles: [[prev -->]](/spring-boot-modules/spring-boot-mvc-2)

View File

@@ -26,6 +26,15 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
</dependencies>
<properties>
<commons-io.version>2.7</commons-io.version>
</properties>
</project>

View File

@@ -0,0 +1,13 @@
package com.baeldung.produceimage;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
@EnableAutoConfiguration
@ComponentScan("com.baeldung.produceimage")
public class ImageApplication {
public static void main(final String[] args) {
SpringApplication.run(ImageApplication.class, args);
}
}

View File

@@ -0,0 +1,38 @@
package com.baeldung.produceimage.controller;
import org.apache.commons.io.IOUtils;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.IOException;
import java.io.InputStream;
@Controller
public class DataProducerController {
@GetMapping("/get-text")
public @ResponseBody String getText() {
return "Hello world";
}
@GetMapping("/get-image")
public @ResponseBody byte[] getImage() throws IOException {
final InputStream in = getClass().getResourceAsStream("/com/baeldung/produceimage/image.jpg");
return IOUtils.toByteArray(in);
}
@GetMapping(value = "/get-image-with-media-type", produces = MediaType.IMAGE_JPEG_VALUE)
public @ResponseBody byte[] getImageWithMediaType() throws IOException {
final InputStream in = getClass().getResourceAsStream("/com/baeldung/produceimage/image.jpg");
return IOUtils.toByteArray(in);
}
@GetMapping(value = "/get-file", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public @ResponseBody byte[] getFile() throws IOException {
final InputStream in = getClass().getResourceAsStream("/com/baeldung/produceimage/data.txt");
return IOUtils.toByteArray(in);
}
}