Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MyBatis-plus generator 如何配置才能生成 XXXRepository extends CrudRepository<XXXMapper, XXX> #6555

Open
3 tasks done
chinacprogramer opened this issue Oct 26, 2024 · 1 comment

Comments

@chinacprogramer
Copy link

确认

  • 我的版本是最新版本, 我的版本号与 version 相同, 并且项目里无依赖冲突
  • 我已经在 issue 中搜索过, 确认问题没有被提出过
  • 我已经修改标题, 将标题中的 描述 替换为遇到的问题

功能改进

在在官方文档和源代码中没有找到使用 Mybatis-plus generator 自动生成 Repository 类的配置。如果要在程序中添加 Repository 类需要手动添加吗?

参考资料

No response

@nieqiurong
Copy link
Contributor

AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
// 替换service包为repository包
generator.packageInfo(packageConfig()
    .service("repository")
    .serviceImpl("repository.impl")
    .build());
// 替换service和serviceImpl为IXxxRepository和XxxRepository
generator.strategy(
    strategyConfig()
        .serviceBuilder().convertServiceFileName(entityName -> "I" + entityName + "Repository")
        .superServiceClass(IRepository.class).convertServiceImplFileName(entityName -> entityName + "Repository")
        .superServiceImplClass(CrudRepository.class)
    .build());
generator.global(globalConfig().build());
generator.execute();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants