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

一些修正的建议 #8

Closed
EagleFlyInSky opened this issue Jul 5, 2017 · 2 comments
Closed

一些修正的建议 #8

EagleFlyInSky opened this issue Jul 5, 2017 · 2 comments

Comments

@EagleFlyInSky
Copy link

1,建议把分页里面的page方法修改为
this.offset = ( page - 1 ) * pageSize;
比较符合使用习惯 page就是页码

2,建议把BatchInsert方法和BatchInsertSelective切分成两个插件
我当前就只想使用BatchInsert方法,就只能修改你的源码了,不太方便

3, 使用作者项目是发现我的一些需求无法解决,就自己写了几个插件
贡献出来希望可以添加到作者的项目里
1>自动生成 mysql generatorKey 的插件 解决每个table设置generatorKey的问题
`

@Override
public boolean validate(List<String> list) {
    return true;
}

@Override
public void initialized(IntrospectedTable introspectedTable) {
    GeneratedKey gk = introspectedTable.getGeneratedKey();
    //如果需要生成参数
    if (gk == null) {
        List<IntrospectedColumn> keyColumns = introspectedTable.getPrimaryKeyColumns();
        IntrospectedColumn keyColumn = null;
        //只能有一个主键列;
        if (keyColumns.size() == 1) {
            //得到这个唯一的主键列
            keyColumn = keyColumns.get(0);
            //得到这个列映射成Java模型之后的属性对应的Java类型;
            FullyQualifiedJavaType javaType = keyColumn.getFullyQualifiedJavaType();
            //要求主键只能是递增的,所以我们把这个主键属性的类型分别和Integer,Long,Short做对比;
            if (javaType.equals(PrimitiveTypeWrapper.getIntegerInstance())
                    || javaType.equals(PrimitiveTypeWrapper.getLongInstance())
                    || javaType.equals(PrimitiveTypeWrapper.getShortInstance())) {
                //设置自增 insert 和 insertSelective 去除字段赋值
                keyColumn.setIdentity(true);
                //设置 Mysql generatedKey 用于生成 selectKey
                GeneratedKey generatedKey = new GeneratedKey(keyColumn.getActualColumnName(), "Mysql", true, "post");
                introspectedTable.getTableConfiguration().setGeneratedKey(generatedKey);
            }
        }
    }
    super.initialized(introspectedTable);
}

`

2> 需要修改mapper后缀为dao 所以写了下面这个插件
`
private String mapperSuffix;
private String sqlSuffix;

public boolean validate(List<String> warnings) {
    //获取配置
    mapperSuffix = properties.getProperty("mapperSuffix");
    sqlSuffix = properties.getProperty("sqlSuffix");
    //至少一个配置
    return stringHasValue(mapperSuffix) || stringHasValue(sqlSuffix);
}

@Override
public void initialized(IntrospectedTable introspectedTable) {
    String modelName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
    if (stringHasValue(mapperSuffix)) {
        String mapperType = introspectedTable.getMyBatis3JavaMapperType();
        mapperType = mapperType.replaceAll(modelName + "Mapper", modelName + mapperSuffix);
        introspectedTable.setMyBatis3JavaMapperType(mapperType);
    }
    if (stringHasValue(sqlSuffix)) {
        introspectedTable.setMyBatis3XmlMapperFileName(modelName + sqlSuffix);
    }
}`

最后感谢作者的无私奉献,希望项目越做越好

@itfsw
Copy link
Owner

itfsw commented Jul 5, 2017

首先感谢你的建议。

  1. 对于page分页的说法因为目前很多前端框架如easyui和jquery的分页插件都是从0开始计数的,所以保持和这些插件兼容暂时还是以0开始分页;
  2. 后期增加属性来确定是否生成BatchInsertSelective方法;
  3. mysql generatorKey的生成如果只用是否为唯一主键且为整数是不恰当的,因为一些外键也是可能是这种情况,也希望后续能找到一个精确获取自增主键的方法再来增加这个插件;
  4. 对于生成Model、Example、Mapper、Mapper.xml的命名,后期会考虑使用一个统一插件来做,也好精简目前插件TablePrefixPlugin、TableRenamePlugin;

再次感谢你的建议,后继续努力完善该插件库,方便大家减少一些代码开发量。

@sunlewuyou
Copy link

等待您的下一步完善,谢谢!

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

3 participants