为什么在使用mybatis生成器时没有生成enableSelectByPrimaryKey



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

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

一切都很好,但最后我发现用户映射器结果文件没有生成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)
);

您发布的DML显示该表没有主键。你有两个选择。

您可以通过将主键添加到createtable语句来定义表中的主键:

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

或者,如果你不想在数据库中定义主键,你可以使用;VirtualPrimaryKeyPlugin";在MyBatis Generator中。有关详细信息,请参见此处:https://mybatis.org/generator/reference/plugins.html

相关内容

  • 没有找到相关文章

最新更新