-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
About the Bug...
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of MyBatis.
-
I have confirmed this bug reproduces without 3rd party extensions (e.g. mybatis-plus).
Database Version
mysql
JDBC Driver Version
mysql
Issue Description
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);
}
}
}
About your report...
-
I did not use images 🖼️ for showing text information (code, error, etc.).
-
I checked the Preview and my report looks awesome! 👍