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

dao层转为jpa代码,不对逻辑层进行更改,并新增可以自定义数据库前缀 #1572

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

MAOUXSAKI
Copy link

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

The description of the PR:

  1. 将所有的sql语句翻译为了jpa代码语句,并将所有Model实体类加上了jpa的注解,基本上只对dao层进行了修改,除了获取分页信息代码以外没有对上层逻辑代码进行修改,以做到最小改动,但同时可能会对性能有部分影响,大部分的update的操作都是将待修改的数据从数据库中先取出后再进行修改。

  2. 为了使用Jpa将所有xml中的namespace置为了空,并将mybatis.mapper-locations=classpath:/mybatis-mapper/*Mapper.xml配置项注释掉了

  3. 因为使用了jpa后,所有的分页数据及分页的信息(总页数,总行数...)都可以通过一个方法获取,所以代码中获取分页数据的dao层接口返回类型改为了 Page<> ,其它使用到这个接口的地方改为了

Page<> page = dao.pageList();
List<> list = page.getContent;
int list_count = (int) page.getTotalElements();
  1. 将所有model的主键生成策略改为了通过数据库表(xxl_primary_key_gen)生成,为了能兼容更多的数据库

  2. 可以自定义表名前缀,通过重载 SpringPhysicalNamingStrategy 类的 toPhysicalTableName 方法实现,实现类为TableNameStrategy。配置项为xxl.tablename.prefix ,默认值为xxl,对原有的初始化脚本默认情况下不造成影响。包括获取表锁的地方也做了可变前缀处理。

  3. 因为新增了jpa,所以可以通过spring.jpa.generate-ddl=true 配置项自动生成所有的数据库表,带上默认的数据库前缀xxl_.。同时为了可以做到自动生成xxl_job_lock这张表,加入了相应的Model实体类。

  4. 为了使自动生成的mysql表的编码正常所以新增了MysqlConfig,使得自动生成表的时候能自动设置为utf-8编码

Other information:
自测了下没什么问题,之后在项目会在项目中进行测试。如果有bug也会进行更新。

yunsongliu added 5 commits April 13, 2020 18:25
2.数据库前缀可自定义,默认为xxl,配置项为xxl.tablename.prefix
3.数据库自动生成配置增加
4.修改获取分页数据代码
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant