This article shows how to work with MyBatis in Groovy application. We will fetch data from database and show them on UI.
Step 1
Create Item class that will represent a database entity. This class will be used by MyBatis as a data transfare object. MyBatis will automatically fetch values from database in to an instance of Item class.
packagecom.app.mappersclass Item { Long id String label}
Step 2
Create mapper interface for Item class. Then this mapper will be referenced from XML mapping file.
Here is an example of how to get the mapper and fetch values from database. Get the bean from the context Grails.get(ItemMapper) and call the method findById(1).
ItemMapper implementation is provided by mybatis-spring.