alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Spring Framework example source code file (ImageController.java)

This example Spring Framework source code file (ImageController.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Spring Framework tags/keywords

autowired, controller, imagecontroller, imagedatabase, io, ioexception, ioexception, multipartfile, outputstream, requestmapping, requestmapping, requestparam, requestparam, string, string

The Spring Framework ImageController.java source code

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.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

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

	private final ImageDatabase imageDatabase;

	@Autowired
	public ImageController(ImageDatabase imageDatabase) {
		this.imageDatabase = imageDatabase;
	}

	@RequestMapping("/imageList")
	public String showImageList(Model model) {
		model.addAttribute("images", this.imageDatabase.getImages());
		return "imageList";
	}

	@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";
	}

}

Other Spring Framework examples (source code examples)

Here is a short list of links related to this Spring Framework ImageController.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.