问题描述
我正在使用 spring boot 规范来查询数据库并返回结果。我查询的表包含很多列,我只想检索特定的列。这是我的代码 -
public static Specification<Partner> filter(SearchCriteria criteria) {
return (root,cq,cb) -> {
String key = criteria.getKey();
String value = criteria.getValue();
cq.distinct();
cq.multiselect(root.get("id").alias("Partner ID"),root.get("name").alias("Partner Name"),root.get("shortDescription").alias("Short Desc"),root.get("logoUrl").alias("logo Url"),root.get("accentColor").alias("Accent Color"));
return cb.equal(root.get(ID),value);
}
public Partner(Long id,String name,String shortDescription,String logoUrl,String accentColor) {
this.id = id;
this.name = name;
this.shortDescription = shortDescription;
this.logoUrl = logoUrl;
this.accentColor = accentColor;
}
但是,这不起作用,它会检索所有列。我在控制台上也没有看到任何错误。我在这里遗漏了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)