Exercise 17: Controller Methods - jkneal/spring-angular-train GitHub Wiki
Goals
Learn how to form different controller method signatures
Instructions
-
In
edu.train.shop.ShopController, create a new method named 'getNewsletter' that maps to '/shop/newsletter' and accepts Get Http methods -
Add the following code to the method body, then adapt the method signature as needed:
Resource resource = new ClassPathResource("public/newsletter.pdf");
try {
InputStream inputStream = resource.getInputStream();
OutputStream outputStream = httpServletResponse.getOutputStream();
IOUtils.copy(inputStream, outputStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
VERIFICATION
- Start the training application and go to the app home page
- Click on the link 'Exercise 17'. Verify a PDF with newsletter content is returned