25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 10<br />

Showing Your <strong>Spring</strong> Application<br />

on the Web<br />

In this chapter, you are going to show your <strong>Spring</strong> application called My Documents on the Web. You are going to<br />

use <strong>Spring</strong> annotations so the code is clean and easy to read. Also, you are going to continue to use the embedded<br />

database and the RowMapper from Chapter 9 so you can see something real in action.<br />

To put your <strong>Spring</strong> application on the Web, you need to know about the MVC design pattern. The MVC design<br />

pattern is the most used pattern for web applications. Let’s start coding, and as we go along I will talk more about this<br />

famous pattern.<br />

Persistence Layer<br />

First, let’s start with the Persistence layer. Listing 10-1 shows your modified DocumentDAO implementation (this class is<br />

from Chapter 9).<br />

Listing 10-1. DocumentRepository.java.<br />

package com.apress.isf.spring.data;<br />

import java.util.List;<br />

import javax.sql.DataSource;<br />

import org.springframework.beans.factory.annotation.Autowired;<br />

import org.springframework.jdbc.core.JdbcTemplate;<br />

import org.springframework.stereotype.Repository;<br />

import com.apress.isf.java.model.Document;<br />

@Repository("documentDAO")<br />

public class DocumentRepository implements DocumentDAO {<br />

@Autowired<br />

private DataSource dataSource;<br />

@Autowired<br />

private String query;<br />

133

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!