You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We plan to add an extension to MyBatis to handle the @DataPermission annotation on each Mapper's mappedStatement. Currently, mybatisMapperRegistry in MybatisConfiguration does not provide a set method, so it is not possible to directly customize the registry to store annotation information. At present, the only feasible approach is to modify this property via reflection, which is not very elegant. Could a setMybatisMapperRegistry method be provided in a future version to allow more flexible extensions?
public class DataPermissionConfigurationCustomizer implements ConfigurationCustomizer {
/**
* Customize the given a {@link MybatisConfiguration} object.
*
* @param configuration the configuration object to customize
*/
@Override
public void customize(MybatisConfiguration configuration) {
try {
Field field = MybatisConfiguration.class.getDeclaredField("mybatisMapperRegistry");
field.setAccessible(true);
MapperRegistry original = (MapperRegistry) field.get(configuration);
// 替换为我们自己的
DataPermissionMybatisMapperRegistry custom = new DataPermissionMybatisMapperRegistry(configuration);
field.set(configuration, custom);
System.out.println("✅ MybatisMapperRegistry 已替换为 DataPermissionMapperRegistry");
} catch (Exception e) {
throw new RuntimeException("替换 MapperRegistry 失败", e);
}
}
}
![Uploading image.png…]()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
We plan to add an extension to MyBatis to handle the @DataPermission annotation on each Mapper's mappedStatement. Currently, mybatisMapperRegistry in MybatisConfiguration does not provide a set method, so it is not possible to directly customize the registry to store annotation information. At present, the only feasible approach is to modify this property via reflection, which is not very elegant. Could a setMybatisMapperRegistry method be provided in a future version to allow more flexible extensions?
Beta Was this translation helpful? Give feedback.
All reactions