@@ -112,14 +112,19 @@ protected void setResultType(MappedStatement ms, Class<?> entityClass) {
112
112
}
113
113
114
114
/**
115
- * 重新设置SqlSource
115
+ * 重新设置SqlSource,同时判断如果是Jdbc3KeyGenerator,就设置为MultipleJdbc3KeyGenerator
116
116
*
117
117
* @param ms
118
118
* @param sqlSource
119
119
*/
120
120
protected void setSqlSource (MappedStatement ms , SqlSource sqlSource ) {
121
121
MetaObject msObject = SystemMetaObject .forObject (ms );
122
122
msObject .setValue ("sqlSource" , sqlSource );
123
+ //如果是Jdbc3KeyGenerator,就设置为MultipleJdbc3KeyGenerator
124
+ KeyGenerator keyGenerator = ms .getKeyGenerator ();
125
+ if (keyGenerator instanceof Jdbc3KeyGenerator ){
126
+ msObject .setValue ("keyGenerator" , new MultipleJdbc3KeyGenerator ());
127
+ }
123
128
}
124
129
125
130
/**
@@ -150,8 +155,13 @@ public void setSqlSource(MappedStatement ms) throws Exception {
150
155
SqlNode sqlNode = (SqlNode ) method .invoke (this , ms );
151
156
DynamicSqlSource dynamicSqlSource = new DynamicSqlSource (ms .getConfiguration (), sqlNode );
152
157
setSqlSource (ms , dynamicSqlSource );
158
+ } else if (String .class .equals (method .getReturnType ())) {
159
+ String xmlSql = (String ) method .invoke (this , ms );
160
+ SqlSource sqlSource = createSqlSource (ms , xmlSql );
161
+ //替换原有的SqlSource
162
+ setSqlSource (ms , sqlSource );
153
163
} else {
154
- throw new RuntimeException ("自定义Mapper方法返回类型错误,可选的返回类型为void和SqlNode !" );
164
+ throw new RuntimeException ("自定义Mapper方法返回类型错误,可选的返回类型为void,SqlNode,String三种 !" );
155
165
}
156
166
} catch (IllegalAccessException e ) {
157
167
throw new RuntimeException (e );
0 commit comments