Because the springboot version is too high, in the Mongo query statement, the in query cannot be underlined in the field, such as test_id. So the Test_id is solved by its alias, and it is solved by lowering the version of springboot. Reduced to 2.4.0
Change result code:
// 实体类代码
@Data
@Document("test") // 列表数据来源
public class TestEntity extends BaseEntity {
@Field("test_id") // 字段改名 test_id,实际查询的是 test_id
private String testid;
}
The original code:
// 实体类代码
@Data
@Document("test") // 列表数据来源
public class TestEntity extends BaseEntity {
private String test_id;
}
Mongo database fields: There are three fields below
_id
test_id
content
Then the original code is actually used, and it will reportNo property test found for type TestEntity
List<String> str = new ArrayList<>();
str.add("123456");
Query query = new Query(Criteria.where("test_id").in(str));
It needs to be added and @Field
converted . I don't quite understand the need for this step of conversion. I guess it is _id
a conflict with the internal fields of Mongo, which should be a problem with the MongoTemplate interface. Added @Field
, then continue to use the following code, you will not continue to report No property xxx found for type 某个实体类名
similar problems.
List<String> str = new ArrayList<>();
str.add("123456");
Query query = new Query(Criteria.where("test_id").in(str));
Special attention: @Field
It is just an alias query, not the specified key name for data return. The real key name is still defined by the entity class testid
, and it is used testid
instead of @Field("test_id")
insidetest_id
The following is the query result and returned data:
TestEntity(testid="123456", content="测试内容")