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 15 ■ <strong>Spring</strong> Data Within Your <strong>Spring</strong> Application<br />

public void setTypeId(String typeId) {<br />

this.typeId = typeId;<br />

}<br />

public String getName() {<br />

return name;<br />

}<br />

public void setName(String name) {<br />

this.name = name;<br />

}<br />

public String getDesc() {<br />

return desc;<br />

}<br />

public void setDesc(String desc) {<br />

this.desc = desc;<br />

}<br />

public String getExtension() {<br />

return extension;<br />

}<br />

public void setExtension(String extension) {<br />

this.extension = extension;<br />

}<br />

}<br />

public String toString(){<br />

StringBuilder builder = new StringBuilder("Type(");<br />

builder.append("id: ");<br />

builder.append(typeId);<br />

builder.append(", name: ");<br />

builder.append(name);<br />

builder.append(", description: ");<br />

builder.append(desc);<br />

builder.append(", extension: ");<br />

builder.append(extension);<br />

builder.append(")");<br />

return builder.toString();<br />

}<br />

As you can see in Listings 15-1 and 15-2, you are using the annotations @Document, @Id, and the @DBRef; the<br />

<strong>Spring</strong> Data module provides these annotations and it will know what to do to persist the document and its type.<br />

Next, take a look at the build.gradle in the book’s companion source code to get more detail of what library you are<br />

using. Using the @Document annotation, you are telling the <strong>Spring</strong> Data module that the collection used will be docs<br />

and types.<br />

206

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

Saved successfully!

Ooh no, something went wrong!