为什么在使用mybatis生成器时不生成enableselectbyprimarykey

c90pui9n  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(370)

当我使用此命令生成mybatis xml文件时:

java -jar mybatis-generator-core-1.3.4.jar -configfile generatorConfig.xml -overwrite

一切正常,但最终我发现用户Map器结果文件没有生成 SelectByPrimaryKey 功能。这是我的生成文件配置的一部分:

<table tableName="users"
               enableCountByExample="true"
               enableUpdateByExample="true"
               enableDeleteByExample="true"
               enableSelectByExample="true"
               enableSelectByPrimaryKey="true"
               enableUpdateByPrimaryKey="true"
               selectByPrimaryKeyQueryId="true"
               selectByExampleQueryId="true">
            <generatedKey column="ID" sqlStatement="JDBC" identity="true" />
        </table>

我的数据库是postgresql 13。我应该如何修复它?这是我的用户表dml:

CREATE TABLE public.users (
    id int8 NOT NULL GENERATED ALWAYS AS IDENTITY,
    nickname varchar NULL,
    avatar_url varchar NULL,
    phone varchar NOT NULL,
    updated_time int8 NOT NULL,
    created_time int8 NOT NULL,
    salt varchar NULL,
    pwd varchar NULL,
    sex int4 NULL,
    level_type varchar NULL,
    phone_region varchar NULL,
    country_code int4 NULL,
    user_status int4 NULL DEFAULT 1,
    last_login_time int8 NULL,
    first_login_time int8 NULL,
    app_id int4 NOT NULL,
    register_time int8 NULL,
    apple_iap_product_id varchar NULL,
    CONSTRAINT unique_phone UNIQUE (phone)
);
qq24tv8q

qq24tv8q1#

您发布的dml显示该表没有主键。你有两个选择。
通过将以下内容添加到create table语句,可以在表中定义主键:

create table public.users (
  ...
  primary key (id)
);

或者,如果不想在数据库中定义主键,可以使用mybatis生成器中的“virtualprimarykeyplugin”。详情请参见此处:https://mybatis.org/generator/reference/plugins.html

相关问题