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 ■ Showing Your <strong>Spring</strong> Application on the Web<br />

}<br />

134<br />

public List getAll() {<br />

return new JdbcTemplate(this.dataSource).query(query, new DocumentRowMapper());<br />

}<br />

As you can see, Listing 10-1 has been reduced to its minimal size in lines compared with other chapters. This is<br />

awesome! Next is Listing 10-2, the Mapper, but this class doesn’t have any new changes.<br />

Listing 10-2. DocumentRowMapper.java<br />

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

import java.sql.ResultSet;<br />

import java.sql.SQLException;<br />

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

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

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

public class DocumentRowMapper implements RowMapper {<br />

}<br />

public Document mapRow(ResultSet rs, int rowNum) throws SQLException {<br />

Document document = new Document();<br />

document.setDocumentId(rs.getString("documentId"));<br />

document.setName(rs.getString("name"));<br />

document.setLocation(rs.getString("location"));<br />

document.setCreated(rs.getDate("created"));<br />

document.setModified(rs.getDate("modified"));<br />

document.setDescription("doc_desc");<br />

Type type = new Type();<br />

type.setTypeId(rs.getString("typeId"));<br />

type.setName(rs.getString("type_name"));<br />

type.setDesc(rs.getString("type_desc"));<br />

type.setExtension(rs.getString("extension"));<br />

document.setType(type);<br />

return document;<br />

}<br />

Before you continue, you need to prepare your project, My Documents, with the necessary structure, creating<br />

folders and files essential for your web application. In the Java world, there is a standard way to develop web<br />

applications and you will be following it. Every web application must have the structure shown:<br />

└── src<br />

└── main<br />

└── java<br />

└── resources<br />

└── webapp<br />

└── WEB-INF

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

Saved successfully!

Ooh no, something went wrong!