Category Archives: Java

Return Image as ResponseBody

This will show how to return a JPG image as Response body from a Spring MVC annotated controller:

curl test:

Spring Data Mongo DB

Spring MVC Project with maven, mongodb, spring-data

This will contain only snippets of code. There are small dependencies that are not listed in these blocks of code.

I am running mongoDB in a remote Centos 6.2 Server.

Main Database is a PostgreSQL. Upper layers in MVC Service classes will try to fetch data from mongoDB. If is not available, will use SQL DB and update mongoDB. My application uses mongo for caching purposes and writes denormalized relationships in mongoDB.







A very simple entity:

A ultra simple Dao Repository:


Service class for Repository (contains JPA code for data transfer from JPA Repository to Mongo Repository, can be ignored):

Unit test for this implementation:


Generate a LinkedHashMap

Generate a LinkedHashMap:

Substring of a String object

Obtain last 32 characters from this 96 character string:

Obtain first 64 characters from same 96 character string: