项目需求是要实现同乡会的搜索返回功能,使用 Spring Data Elasticsearch 完成,在
但是 Controller 层调用对应的实体的查询所有方法时报 failed to map source[entity data]to xxx class 异常,去百度上查找得到的解决方案都是在实体类中提供空参构造器,但是我已经提供了
下面是代码,Controller 层,发生错误的方法是 findAll()
@GetMapping("test")
public void test(){
List<Village> list = villageService.list();
villageDao.saveAll(list);
Iterable<Village> all = villageDao.findAll();
for (Village village : all) {
System.out.println(village);
}
}
Village 实体类
@Getter
@Setter
@TableName("v_village")
@ApiModel(value = "Village 对象", description = "")
@Document(indexName = "village")
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class Village implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@TableId(value = "id", type = IdType.ASSIGN_ID)
@Field(index = false,type = FieldType.Keyword)
private String id;
@ApiModelProperty("同乡会头像")
@Field(index = false,type = FieldType.Text)
private String avatarUrl;
@ApiModelProperty("学校 Id ,对应 a_university")
@Field(index = false,type = FieldType.Keyword)
private Integer unId;
@ApiModelProperty("名称")
@Field(type = FieldType.Text)
private String name;
@ApiModelProperty("负责人微信")
@Field(index = false,type = FieldType.Text)
private String wechat;
@ApiModelProperty("负责人姓名")
@Field(type = FieldType.Text)
private String master;
@ApiModelProperty("公众号文章链接")
@Field(index = false,type = FieldType.Text)
private String articleUrl;
@ApiModelProperty("二维码")
@Field(index = false,type = FieldType.Text)
private String qrCode;
@ApiModelProperty("点赞数")
@Field(index = false,type = FieldType.Integer)
private Integer likeNum;
@ApiModelProperty("排序,小的在前")
@Field(index = false,type = FieldType.Integer)
private Integer sort;
@ApiModelProperty("省 id")
@Field(type = FieldType.Keyword)
private String provinceId;
@ApiModelProperty("城市 Id")
@Field(type = FieldType.Keyword)
private String cityId;
@ApiModelProperty("区 Id")
@Field(type = FieldType.Keyword)
private String districtId;
@Field(index = false,type = FieldType.Integer)
private Integer isDeleted;
@TableField(fill = FieldFill.INSERT)
@Field(index = false,type = FieldType.Date)
private LocalDateTime createTime;
@TableField(fill = FieldFill.INSERT_UPDATE)
@Field(index = false,type = FieldType.Date)
private LocalDateTime updateTime;
}
按照 ES 规范构造的 Repository 接口
public interface VillageDao extends ElasticsearchCrudRepository<Village,String> {
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.