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 缺少id #132

Open
starplatinum3 opened this issue Apr 14, 2022 · 2 comments
Open

这个语句生成的mybatis 缺少id #132

starplatinum3 opened this issue Apr 14, 2022 · 2 comments

Comments

@starplatinum3
Copy link
Contributor

这个语句生成的mybatis 缺少id
貌似是解析的时候都不会有id这个字段,所以所有的模板都不会有id字段

create table stu
(
    id      int auto_increment
        primary key,
    name    varchar(255) null,
    stu_num varchar(222) null,
    sex     varchar(255) null,
    id_num  varchar(33)  null,
    email   varchar(33)  null
);

生成的部分代码

<resultMap id="BaseResultMap" type="cn.edu.zucc.entity.Stu" >
    <result column="name" property="name" />
    <result column="stu_num" property="stuNum" />
    <result column="sex" property="sex" />
    <result column="id_num" property="idNum" />
    <result column="email" property="email" />
</resultMap>

<sql id="Base_Column_List">
            name,
            stu_num,
            sex,
            id_num,
            email
</sql>
@starplatinum3
Copy link
Contributor Author

//            为什么id 不要呢,这里看起来把id略过了,还是说前后端传值的时候不用传id的吗
            for (String columnLine : fieldLineList) {
                i++;
                columnLine = columnLine.replaceAll("\n", "").replaceAll("\t", "").trim();
                // `userid` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
                // 2018-9-18 zhengk 修改为contains,提升匹配率和匹配不按照规矩出牌的语句
                // 2018-11-8 zhengkai 修复tornadoorz反馈的KEY FK_permission_id (permission_id),KEY FK_role_id (role_id)情况
                // 2019-2-22 zhengkai 要在条件中使用复杂的表达式
                // 2019-4-29 zhengkai 优化对普通和特殊storage关键字的判断(感谢@AhHeadFloating的反馈 )
                // 2020-10-20 zhengkai 优化对fulltext/index关键字的处理(感谢@WEGFan的反馈)
                boolean specialFlag = (!columnLine.contains("key ") && !columnLine.contains("constraint") && !columnLine.contains("using") && !columnLine.contains("unique ")
                        && !(columnLine.contains("primary ") && columnLine.indexOf("storage") + 3 > columnLine.indexOf("("))
                        && !columnLine.contains("fulltext ") && !columnLine.contains("index ")
                        && !columnLine.contains("pctincrease")
                        && !columnLine.contains("buffer_pool") && !columnLine.contains("tablespace")
                        && !(columnLine.contains("primary ") && i > 3));

@starplatinum3
Copy link
Contributor Author

我知道了 这句话是 为了排除 PRIMARY KEY (id) 这种【1】
【1】 !(columnLine.contains("primary ")
但是如果是这样的建表语句,他的id就会被排除了【2】
【2】
create table stu
(
id int auto_increment
primary key,

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

No branches or pull requests

1 participant