private void setJoin ( T model ) { for ( JoinParam joinParam : joinParams ) { try { Object leftValue = AnimaUtils . invokeMethod ( model , getGetterName ( joinParam . getOnLeft ( ) ) , AnimaUtils . EMPTY_ARG ) ; String sql = "SELECT * FROM " + AnimaCache . getTableName ( joinParam . getJoinModel ( ) ) + " WHERE " + joinParam . getOnRight ( ) + " = ?" ; Field field = model . getClass ( ) . getDeclaredField ( joinParam . getFieldName ( ) ) ; if ( field . getType ( ) . equals ( List . class ) ) { if ( AnimaUtils . isNotEmpty ( joinParam . getOrderBy ( ) ) ) { sql += " ORDER BY " + joinParam . getOrderBy ( ) ; } List < ? extends Model > list = this . queryList ( joinParam . getJoinModel ( ) , sql , new Object [ ] { leftValue } ) ; AnimaUtils . invokeMethod ( model , getSetterName ( joinParam . getFieldName ( ) ) , new Object [ ] { list } ) ; } if ( field . getType ( ) . equals ( joinParam . getJoinModel ( ) ) ) { Object joinObject = this . queryOne ( joinParam . getJoinModel ( ) , sql , new Object [ ] { leftValue } ) ; AnimaUtils . invokeMethod ( model , getSetterName ( joinParam . getFieldName ( ) ) , new Object [ ] { joinObject } ) ; } } catch ( NoSuchFieldException e ) { log . error ( "Set join error" , e ) ; } } }
Set model join fields