如何在ormlite中将两个字段作为一个主键?

How to make two fields as one primary key in ormlite?

创建 table temp(id int,userId int,query text,createdOn text,primary key(id,userId));

如何使用 ormlite 创建 id 和 UserId 作为一个主键?

@DatabaseField(columnName = "_id",id = true,generatedId = true)
private long _id;
@DatabaseField(columnName = "userId")
private String userId;
@DatabaseField(columnName = "query")
public String query;
@DatabaseField(columnName = "createdOn")
public String createdOn;
@DatabaseField(columnName = "_id",id = true,generatedId = true)
private long _id;

_id 当你使用 generatedId = true 时它是主键;