package org.springframework.samples.imagedb.web;

import java.io.IOException;
import java.io.OutputStream;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.imagedb.ImageDatabase;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

/**
 * MultiActionController for the image list/upload UI.
 *
 * @author Juergen Hoeller
 * @since 07.01.2004
 */
@Controller
public class ImageController {

	@Autowired
	private ImageDatabase imageDatabase;

	@RequestMapping("/imageList")
	public ModelAndView showImageList() {
		return new ModelAndView("imageList", "images", this.imageDatabase.getImages());
	}

	@RequestMapping("/imageContent")
	public void streamImageContent(@RequestParam("name") String name, OutputStream outputStream) throws IOException {
		this.imageDatabase.streamImage(name, outputStream);
	}

	@RequestMapping("/imageUpload")
	public String processImageUpload(
			@RequestParam("name") String name, @RequestParam("description") String description,
			@RequestParam("image") MultipartFile image) throws IOException {

		this.imageDatabase.storeImage(name, image.getInputStream(), (int) image.getSize(), description);
		return "redirect:imageList";
	}

	@RequestMapping("/clearDatabase")
	public String clearDatabase() {
		this.imageDatabase.clearDatabase();
		return "redirect:imageList";
	}

}

@@ -272,16 +272,56 @@
 roller;%0A
+import org.springframework.ui.ModelMap;%0A
 import o
@@ -495,61 +495,8 @@
 ile;
-%0Aimport org.springframework.web.servlet.ModelAndView;
 %0A%0A/*
@@ -656,29 +656,121 @@
 %7B%0A%0A%09
-@Autowired%0A%09private I
+private ImageDatabase imageDatabase;%0A%0A%09@Autowired%0A%09public ImageController(ImageDatabase imageDatabase) %7B%0A%09%09this.i
 mage
@@ -769,32 +769,34 @@
 is.imageDatabase
+ =
  imageDatabase;%0A
@@ -790,24 +790,27 @@
 ageDatabase;
+%0A%09%7D
 %0A%0A%09@RequestM
@@ -838,28 +838,22 @@
 %09public 
-ModelAndView
+String
  showIma
@@ -863,51 +863,47 @@
 ist(
-) %7B%0A%09%09return new ModelAndView(%22imageList%22, 
+ModelMap model) %7B%0A%09%09model.addAttribute(
 %22ima
@@ -941,16 +941,38 @@
 ges());%0A
+%09%09return %22imageList%22;%0A
 %09%7D%0A%0A%09@Re

use ModelMap instead of ModelAndView