public class Contact implements Serializable {
private
Long id;
private
String firstName;
private
String lastName;
private
Date birthDate;
// Getter/setter methods omitted
public String toString() {
return "Contact - Id: " + id + ", First name: " + firstName
+ ", Last name: " + lastName + ", Birthday: " + birthDate;
}
}
The class is a simple POJO, with nothing we need to specify here. The next step is to define the
contact's mapper interface (and the findAll() method), which was shown in Listing 11-7.
Listing 11-7. The ContactMapper Interface
package com.apress.prospring3.ch11.persistence;
import java.util.List;
import com.apress.prospring3.ch11.domain.Contact;
public interface ContactMapper {
public List<Contact> findAll();
}
There's nothing special for the interface either. We just need to define the database operations
supported by the mapper, which will be scanned by the MapperScannerConfigurer class and can be
autowired into Spring beans.
The next step is the most important part, the XML mapping file. Listing 11-8 shows the content for
mapping the findAll() operation (ContactMapper.xml).
Listing 11-8. The Mapping of the findAll Operation
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.apress.prospring3.ch11.persistence.ContactMapper">
<resultMap id="contactResultMap" type="Contact">
<id property="id" column="ID" />
<result property="firstName" column="FIRST_NAME" />
<result property="lastName" column="LAST_NAME" />
<result property="birthDate" column="BIRTH_DATE" />
</resultMap>
<select id="findAll" resultMap="contactResultMap">
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home