Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

CHAPTER 11: Using MyBatis in Spring > SQL Mapping in MyBatis

SQL Mapping in MyBatis

When implementing data access logic using MyBatis, the most important and time-consuming step is to define the mappings between the queries for various database operations and the corresponding domain objects. The mapping is closely related to what operations are required and their underlying queries. So, for the contact information service, let’s define the ContactService interface that we will implement first. Listing 11-5 shows the interface.

Listing 11-5. The ContactService Interface

package com.apress.prospring3.ch11.service;

import java.util.List;

import com.apress.prospring3.ch11.domain.Contact;

public interface ContactService {

    // Find all contacts - without details
    public List<Contact> findAll();

    // Find all contacts - with tels and hobbies
    public List<Contact> findAllWithDetail();

    // Find by ID - with tels and hobbies
    public Contact findById(Long id);

    // Create a new or save an existing contact
    public Contact save(Contact contact);

    // Delete a contact
    public void delete(Contact contact);

    // Find a contact by first name and last name
    public List<Contact> findByFirstNameAndLastName(String firstName,
        String lastName);

}

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint