| Custom Type Handlers in iBatis |
| Java - Tutorials |
| Thursday, 11 November 2010 12:05 |
|
There are times when you need to convert the data being returned in your sql query to match the data type of your variable.
An example of this is converting from a sql date to a Calendar object for use with beans generated from an xsd.
The iBatis framework allows for the creation of custom type handlers for this very purpose.
In order to achieve this, we extend TypeHandlerCallback and pay particular attention to the implementation of the following method In the code snippet below, we use the ResultGetter to return the sql date which we then set on the Calendar object. Pretty easy hey? This simple mapping tells iBatis to use our newly created class when dealing with the associated java type. Your result property in the resultMap must be mapped correctly in order for this to work. And there you have it. Custom type handlers made easy! |

