To answer the "custom types" question, you can implement a BinderFactory to bind to whatever you want.
@BindingAnnotation(UserBinder.UserBinderFactory.class) @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.PARAMETER}) public @interface UserBinder { public static class UserBinderFactory implements BinderFactory { @Override public Binder build(Annotation annotation) { return new Binder<UserBinder, User>() { @Override public void bind(SQLStatement<?> q, UserBinder bind, User arg) { q.bind("userId", arg.getUserId()); q.bind("uuid", arg.getUuid()); q.bind("openId", arg.getOpenId()); q.bind("givenName", arg.getGivenName());
This is most useful if you have complex types that you want to store in a certain way, for example. binary data or collections that you want to convert to CSV or only in separate mapping tables. Then you use your new fancy binder:
@SqlUpdate( "INSERT INTO user (openId,givenName,uuid," + // etc. ") VALUES (:openId,:givenName,:uuid" + // etc. ")" ) public abstract int createUser( @UserBinder User user );
You can also use the @BindBean annotation, which will automatically search for object fields by the name of the binding parameter (for example, it can match the request placeholder ":userId" with the getUserId() method).
Patrick m
source share